Manage Heartbeat using CRM
Heartbeat is an open-source Linux-based, widely used high-availability cluster system. It mainly includes two high-availability cluster components: Heartbeat service and resource manager. Its resource management method can be managed by using the haresource file method, or by using the CIB method. CIB-based cluster resources use xml format to save their resource configuration information. Resources Based on haresouce file management can be converted to CIB-based management. Its biggest advantage is that CIB management makes cluster management more convenient and easy to monitor. This document describes how to manage heartbeat using crm.
1. Description of related configuration files
### Node Information
# More/etc/hosts
127.0.0.1 localhost. localdomain localhost
# Public ip
192.168.21.10 orasrv1.xlk.com orasrv1
192.168.21.13 orasrv2.xlk.com orasrv2
# Private ip
192.168.144.128 orasrv1-priv.xlk.com orasrv1-priv
192.168.144.129 orasrv2-priv.xlk.com orasrv2-priv
### Configuration file information
# Cat/etc/ha. d/ha. cf ### ha. cf file
Logfile/var/log/ha-log
Keepalive 2
Deadtime 15
Warntime 30
Initdead 60
Udpport 694
Bcast eth0
Auto_failback off
Node orasrv1.xlk.com
Node orasrv2.xlk.com
Ping 192.168.21.254
Respawn hacluster/usr/lib64/heartbeat/ipfail
Crm respawn ### this item is used to define how to enable crm, or pacemaker (after heartbeat V3)
# CRM and Resources are not compatible. If CRM is defined in ha. cf, the HA service will not read the/etc/ha. d/haresources configuration file.
# The following message is displayed in the log file: This file is not used because crm is enabled.
# Cat/etc/ha. d/authkeys ### authkeys File
Auth 1
1 md5 74a6a503b5bec9373b22bb630608df41
# More/etc/ha. d/haresources ### resource file
Orasrv1.xlk.com IPaddr: 192.168.21.1 httpd
### Use ha_propagate to synchronize the configuration file. Note that the configuration file does not contain the haresource file.
### Ha_propagate uses the scp command based on equivalent ssh, and connects to the node and enables heartbeat auto-start using chkconfig
[Root @ orasrv1 heartbeat] #/usr/lib64/heartbeat/ha_propagate
Ii. Start the heartbeat Service
# Service heartbeat start ### Node 1
# Ssh orasrv2 'service heartbeat start' ### Node 2
# Netstat-nltp | grep 5560 ### view the mgmtd Port
Tcp 0 0 0.0.0.0: 5560 0.0.0.0: * LISTEN 4128/mgmtd
# Ssh orasrv2 'netstat-nltp | grep 100'
Tcp 0 0 0.0.0.0: 5560 0.0.0.0: * LISTEN 3434/mgmtd
### View heartbeat-related processes
# Ps-AHfww | grep heartbeat | grep-v grep
Root 5564 1 0 Nov11? 00:00:40 heartbeat: master control process.
Nobody 5567 5564 0 Nov11? 00:00:04 heartbeat: FIFO reader
Nobody 5568 5564 0 Nov11? 00:00:09 heartbeat: write: bcast eth0
Nobody 5569 5564 0 Nov11? 00:00:03 heartbeat: read: bcast eth0
Nobody 5570 5564 0 Nov11? 00:00:07 heartbeat: write: ping 192.168.21.254
Nobody 5571 5564 0 Nov11? 00:00:02 heartbeat: read: ping 192.168.21.254
496 5575 5564 0 Nov11? 00:00:04/usr/lib64/heartbeat/ccm
496 5576 5564 0 Nov11? 00:00:07/usr/lib64/heartbeat/cib
Nobody 5577 5564 0 Nov11? 00:00:03/usr/lib64/heartbeat/lrmd-r
Nobody 5578 5564 0 Nov11? 00:00:04/usr/lib64/heartbeat/stonithd
496 5579 5564 0 Nov11? 00:00:02/usr/lib64/heartbeat/attrd
496 5580 5564 0 Nov11? 00:00:03/usr/lib64/heartbeat/crmd
496 8978 5580 0? 00:00:00/usr/lib64/heartbeat/tengine
496 8979 5580 0? 00:00:00/usr/lib64/heartbeat/pengine
Root 5581 5564 0 Nov11? 00:00:03/usr/lib64/heartbeat/mgmtd-v
### The following figure shows the automatically generated cib. xml file, which does not contain specific resource information.
# Cd/var/lib/heartbeat/crm
# Ls-hltr
Total 16 K
-Rw ------- 2 hacluster haclient 484 Nov 11 cib. xml. last
-Rw ------- 2 hacluster haclient 484 Nov 11 cib. xml
-Rw-r -- 2 hacluster haclient 32 Nov 11 16:54 cib. xml. sig. last
-Rw-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, the vip is on the second node.
Eth0: 0 Link encap: Ethernet HWaddr 00: 0C: 29: F1: 2E: E4
Inet addr: 192.168.21.1 Bcast: 192.168.21.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
3. Use crm commands to manage Clusters
Crm-related command line tools, usually located at/usr/sbin
All commands can be obtained through <command> -- help
Crm_verify -- check the cluster configuration file
Crm_uuid -- view the node uuid
Crm_standby -- standby attribute of the Operation node to determine whether the resource can run on this node
Crm_resource -- Resource Management Tool
Crm_mon -- cluster Health Status Monitoring
Crm_master -- choose settings for managing Master/Slave resources to improve on a given Node
Crm_failcount -- manages the counters that record the fault count of each resource.
Crm_diff -- identify the changes to the cluster configuration and apply the supplemental program to the configuration file
Crm_attribute -- allows you to query, modify, and delete node attributes and cluster options.
Crmadmin -- Control Cluster Resource Manager
Crm_sh -- tool set in the crm Command Prompt
Cibadmin-provides direct access to cluster configurations
# Crm_verify-x/var/lib/heartbeat/crm/cib. xml ### verify the configuration file
# Crm_uuid ### view node uuid
512505ec-63f0-4a51-be40-58ba0e2f613d
# Ssh orasrv2 crm_uuid
6ae0f853-b98c-470b-9ce9-4cd0077179ee
# Crm_resource -- list ### view resources. Currently, no resources exist.
NO resources configured
# Crm_mon-1 ### cluster status monitoring. The current two nodes are online.
================
Last updated: Wed Nov 11 17:14:18 2015
Current DC: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee)
2 Nodes configured.
0 Resources configured.
================
Node: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee): online
Node: orasrv1.xlk.com (512505ec-63f0-4a51-be40-58ba0e2f613d): online
Convert the haresources file resource to CIB xml
### Use haresources2cib. py to convert the content of the haresource file to the CIB xml file
#/Usr/lib64/heartbeat/haresources2cib. py
Cib. 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
#/Usr/lib64/heartbeat/haresources2cib. py
# Ls/var/lib/heartbeat/crm/
Cib. xml old
### Restart 2 nodes
# Service heartbeat restart ### Node 1
# Ssh orasrv2 'service heartbeat restart' ### Node 2
# Crm_resource -- list ### view all resources with a group of resources
Resource 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 a specified resource
Resource Group: group_1
IPaddr_192_168_21_1 (ocf: heartbeat: IPaddr)
Httpd_2 (lsb: httpd)
[Root @ orasrv1 ~] # Crm_resource-QW-r IPaddr_192_168_21_1 ### query the node where the resource is located
Orasrv1.xlk.com
# Crmadmin -- version
HA Version 2.1.4, CRM Version 2.0 (CIB feature set 2.0) node: aa909246edb2017137b986c5773344b98c6969999
[Root @ orasrv1 ~] # Crmadmin -- nodes ### query node Member names
Normal node: orasrv2.xlk.com (6ae0f853-b98c-470b-9ce9-4cd0077179ee)
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 Popen3
Crm # help
Usage: crm (nodes | config | resources)
Crm # nodes
Crm nodes # help
Usage: nodes (status | list)
Crm nodes # list
<Node id = "6ae0f853-b98c-470b-9ce9-4cd0077179ee" uname = "orasrv2.xlk.com" type = "normal"/>
<Node id = "512505ec-63f0-4a51-be40-58ba0e2f613d" uname = "orasrv1.xlk.com" type = "normal"/>
Crm nodes # config -- unable to switch to the config path
Crm nodes # help
Usage: nodes (status | list)
Crm nodes # resources -- cannot switch to the config path
Crm nodes # help
Usage: nodes (status | list)
### Verify the httpd service. As shown in the following query, the current service is located at 2nd points.
# Curl http: // 192.168.21.1/
Orasrv1.xlk.com
### For details about more commands, refer:
Http://www.novell.com/zh-cn/documentation/sle_ha/book_sleha/data/cha_ha_management.html
Iv. 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 nodes by specifying nodes
### If node 2 is the master node, you can run the command on node 1 to switch it to the slave node.
# Crm_standby-v true-U orasrv2.xlk.com
V. Summary
1. In Versions later than heartbeat v2, resources managed by haresources can be converted to CIB-based management.
2. For CRM (CIB) management, you need to configure ha. cf and add crm respawn.
3. the CRM and haresources methods are not compatible, that is, either of them
4. You can use crm commands to manage cluster configurations, monitoring, and switching.
5. Use the CRM management method or manage it based on the graphical interface.
Hot Standby for Web Services Based on Heartbeat V1
Heartbeat enables high-availability clusters of Web Services
Heartbeat + LVS + Ldirectord high-availability Load Balancing Solution
DRBD + Heartbeat + NFS High Availability Configuration notes
Heartbeat high availability for MySQL using NFS based on CRM
Heartbeat high-availability httpd simple configuration based on Resources
CentOS 6 High Availability service Heartbeat v3 installation and configuration
This article permanently updates the link address: