Heartbeat is a highly available cluster system based on Linux open source and widely used. It mainly includes two highly available cluster components, heartbeat service and resource takeover. The resource management method can use the haresource file-based method for management, or the CIB-based method for management. Based on the CIB method, its cluster resources use the xml format to save its resource configuration information. The resources based on haresouce file management can be converted to CIB-based management. Its biggest advantage is that management through CIB makes the management of the cluster more convenient and easier to monitor. This article mainly describes the command line management of heartbeat in crm mode.
Related reference for heartbeat:
Overview of HeartBeat cluster components
Installing and configuring heartbeat under Linux
Linux configures httpd high-availability services based on heartbeat
1. Related configuration file description
###Node information# more /etc/hosts127.0.0.1 localhost.localdomain localhost#public ip192.168.21.10 orasrv1.xlk.com orasrv1192.168 .21.13 orasrv2.xlk. com orasrv2#private ip192.168.144.128 orasrv1-priv.xlk.com orasrv1-priv192.168.144.129 orasrv2-priv.xlk< span class="hljs-preprocessor">.com orasrv2-priv###Configuration file information# cat /etc/ha.d/ha.cf ###ha.cf filelogfile /var/log/ha-logkeepalive 2deadtime 15warntime 30 initdead 60 udpport 694bcast eth0auto_failback offnode orasrv1.xlk.comnode orasrv2.xlk.comping 192.168.21.254respawn hacluster /usr/lib64/heartbeat /ipfailcrm respawn ###This item is used to define the way to start crm, or pacemaker (after heartbeat V3)#CRM It is not compatible with Resources. If CRM is defined in ha.cf, HA service will not read the /etc/ha.d/haresources configuration file#in the log file You will see this prompt: This file is not used because crm is enabled# cat /etc/ha.d/authkeys ###authkeys file auth 11 md5 74a6a503b5bec9373b22bb630608df41# more /etc/ha.d/haresources ###Resource filesorasrv1.xlk.com IPaddr::192.168.21.1 httpd# ##Use ha_propagate to synchronize the configuration file. Note that the haresource file is not included.###ha_propagate uses the scp command method based on the equivalent ssh, and connects to the node using chkconfig Enable heartbeat self-starting[root@orasrv1 heartbeat]# /usr/lib64/heartbeat/ha_propagate
Two, start the heartbeat service
# service heartbeat start ###Node1# ssh orasrv2'service heartbeat start' ###Node2# netstat -nltp|grep 5560 ###View mgmtd porttcp 0 0 0.0.0.0:5560 0.0.0.0:* LISTEN 4128 /mgmtd # ssh orasrv2'netstat -nltp|grep 5560'tcp 0 0 0.0.0. 0:5560 0.0.0 span>.0:* LISTEN 3434 /mgmtd ###View heartbeat related processes# ps -AHfww | grep heartbeat |grep -v greproot 5564 1 0 Nov11? 00:00:40 heartbeat: master control processnobody 5567 5564 0 Nov11? 00:00:04 heartbeat: FIFO reader nobody 5568 5564 0 Nov11? 00:00:09< /span> heartbeat: write: bcast eth0 nobody 5569 5564 0 Nov11? 00:00:03 heartbeat: read: bcast eth0 nobody 5570 5564 0 Nov11? < span class="hljs-number">00:00:07 heartbeat: write: ping 192.168.21.254nobody < span class="hljs-number">5571 5564 0 Nov11? 00:00:02 heartbeat: read: ping 192.168.21.254496 5575 5564 0 Nov11? 00:00:04 /usr/lib64/heartbeat/ccm496 span> 5576 5564 0 Nov11? < span class="hljs-number">00:00:07 /usr/lib64 /heartbeat/cibnobody 5577 5564 0 Nov11 ? 00:00:03 /usr /lib64/heartbeat/lrmd -rnobody 5578 5564 0< /span> Nov11? 00:00:04 span> /usr/lib64/heartbeat/stonithd496 5579 5564 0 Nov11? 00:00:02 /usr/lib64/heartbeat /attrd496 5580 5564 0 Nov11? 00:00:03 /usr/lib64/heartbeat/crmd496 8978 < span class="hljs-number">5580 0 08:55? 00:00:00 /usr/lib64/heartbeat/tengine496 8979 5580 0 08:55? 00:00:00 /usr/lib64/heartbeat/pengineroot 5581 5564 0 Nov11? 00:00:03 /usr/lib64/heartbeat/mgmtd -v###below You can view the automatically generated cib.xml file, which does not contain specific resource information# cd /var/lib/heartbeat/crm# ls -hltrtotal 16K-rw------- 2 hacluster haclient 484 Nov 11 16:54 cib.xml.last-rw------- 2 hacluster haclient 484 Nov 11 16:54 cib.xml-rw-r--r-- 2 hacluster haclient 32 Nov 11 16: 54 cib.xml.sig.last-rw-r--r-- 2 hacluster haclient 32 Nov 11 16:54 cib.xml.sig# ifconfig |grep eth0:0# ssh orasrv2 ' ifconfig |grep eth0:0 -A2' ###At this time vip is on the second nodeeth0:0 Link encap:Ethernet HWaddr 00:0C:29:F1:2E:E4 inet addr:192.168.21< span class="hljs-number">.1 Bcast:192.168.21.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Three, use crm-related commands to manage the cluster
crm-related command-line tools, usually located in /usr/sbin All commands can be obtained through the --help method crm_verify --verify Cluster configuration file crm_uuid - view the uuid of the node crm_standby - operate the node's standby attributes to determine whether the resource can run on this node crm_resource - resource management tool crm_mon - cluster health monitoring crm_master-manages the optional settings of master/slave resources to increase on a given node crm_failcount-manages a counter that records the count of failures for each resource. crm_diff --Identifies the changes made to the cluster configuration and applies the patches to the configuration file crm_attribute --Allows querying, modifying, and deleting node attributes and cluster options. crmadmin - control the cluster resource manager crm_sh - crm command prompt tool set cibadmin - provide direct access to the cluster configuration # crm_verify -x /var/lib/heartbeat/ crm/cib.xml ###Verify configuration file# crm_uuid ###View node uuid512505< /span>ec-63f0-4a51-be40-58ba0e2f613d# ssh orasrv2 crm_uuid6ae0f853-b98c-470b-9ce9-4cd0077179ee# crm_resource --list ###View resources, there are currently no resourcesNO resources configured# crm_mon -1 ###Cluster status monitoring, currently 2 nodes Online============Last updated: Wed Nov 11 17 span>:14:18 2015Current DC: orasrv2.xlk.com (< span class="hljs-number">6ae0f853-b98c-470b-9 ce9-4cd0077179ee)2 Nodes configured.0 span> Resources configured.============Node: orasrv2.xlk .com (6ae0f853-b98c-470b-9ce9-4cd0077179ee): onlineNode : orasrv1.xlk.com (512505 ec-63f0-4a51-be40-58ba0e2f613d): onlineharesources file resources are transferred to CIB xml###Use haresources2cib.py to convert the contents of haresource files to CIB xml files span># /usr/lib64/heartbeat/haresources2cib.pycib.xml or cib.xml.sig exist in /var/lib/heartbeat/crm/please remove them before generating new cib.xml # mkdir /var/lib/heartbeat/crm/old# mv /var/lib/heartbeat/crm/cib* /var/lib/heartbeat/crm/old< /span># /usr/lib64/heartbeat/haresources2cib.py# ls /var/lib/heartbeat/crm/< /span>cib.xml old###Restart 2 nodes# service heartbeat restart ###Node1# ssh orasrv2'service heartbeat restart' ###Node2# crm_resource --list ###View all resources, there is a group of resourcesResource Group: group_1 IPaddr_192_168_21_1 (ocf::heartbeat:IPaddr) httpd_2 (lsb:httpd)[root@orasrv1 ~]# crm_resource -Q -r IPaddr_192_168_21_1 ###Query the specified resourceResource Group: group_1 IPaddr_192_168_21_1 (ocf::heartbeat:IPaddr) httpd_2 (lsb:httpd) [root@orasrv1 ~]< span class="hljs-preprocessor"># crm_resource -QW -r IPaddr_192_168_21_1 ###Query the node where the resource is locatedorasrv1.xlk.com# crmadmin --versionHA Version 2.1.4, CRM Version 2.0 (CIB feature set < span class ="hljs-number">2.0) node: aa909246edb386137b986c5773344b98c6969999[root@orasrv1 ~]# crmadmin --nodes ###Query node member namenormal node : orasrv2.xlk.com (6 ae0f853-b98c-470b-9ce9-4< /span>cd0077179ee)normal node: orasrv1.xlk.com (512505ec-63f0-4a51-be40-58ba0e2f613d)# crm_sh/usr/sbin/crm_sh:31 : DeprecationWarning: The popen2 module is deprecated. Use the subprocess module. from popen2 import Popen3crm # helpUsage:< /span> crm (nodes|config|resources)crm # nodescrm nodes # helpUsage: nodes (status|list)crm nodes # list "6ae0f853-b98c-470b-9ce9-4cd0077179ee" uname="orasrv2.xlk.com" type= "normal"/> "512505ec-63f0-4a51-be40-58ba0e2f613d" uname= "orasrv1.xlk.com" type="normal"/>crm nodes # config --cannot switch Go to the config pathcrm nodes # helpUsage: nodes (status|list)crm nodes # resources --also cannot be switched to the config pathcrm nodes # helpUsage: nodes (st atus|list)###Verify the httpd service. From the query below, you can see that the current service is at the second node# curl http://192.168.21.1/orasrv1.xlk.com###For a detailed description of more commands, please refer to:http://www.novell.com/zh-cn/documentation/sle_ha/book_sleha /data/cha_ha_management.html
four, switch test
[root@orasrv1 crm]# crm_standby -v true[root@orasrv1 crm]# curl http://192.168.21.1 /orasrv2.xlk.com###You can also switch by specifying nodes###Assumption Node 2 is the master, you can execute the command on node 1 to switch it to standby# crm_standby -v true -U orasrv2.xlk.com
Five. Summary
1. In the version after heartbeat v2, resources managed by haresources can be converted into management based on CIB 2. To use CRM (CIB) management, you need to configure ha.cf and add crm respawn 3. CRM and haresources methods are not compatible, that is, choose one of the two. 4. You can use crm related commands to configure the cluster, monitor, switch, etc. 5. Using CRM management method, it can also be managed based on a graphical interface, this article is omitted