Implement HA based on HeartBeat V2 CRM by LAMP

The definition of Heartbeat
The Heartbeat project is an integral part of the Linux-HA project, and it is also the most successful example of the current open source HA project. The full name of Linux-HA is High-Availability Linux, this open source project The goal is: through the joint efforts of community developers, to provide a cluster solution that enhances Linux reliability, availability and serviceability (RAS), which implements a highly available cluster system. Heartbeat service and cluster communication are two key components of a high-availability cluster. In the Heartbeat project, the heartbeat module implements these two functions.

2. Heartbeat versions and components
Note: Heartbeat has three versions: Heartbeat v1.x, Heartbeat v2.x, Heartbeat v3.x. The composition structure of Heartbeat v1.x and Heartbeat v2.x is very simple. All modules are concentrated in heartbeat. After the v3 version, the entire heartbeat project was split and divided into different projects for development.
1. Components of Heartbeat v1.x and v2.x
heartbeat: inter-node communication detection module

ha-logd: cluster event log service

CCM (Consensus Cluster Membership): Cluster Member Consistency Management Module

LRM (Local Resource Manager): Local Resource Management Module

Stonith Daemon: Disconnect or restart the problematic node from the cluster environment

CRM (Cluster resource management): Cluster resource management module

Cluster policy engine: Cluster policy engine

Cluster transition engine: Cluster transition engine (also called policy Execution engine)

The difference between Heartbeat v1.x and Heartbeat v2.x: A new cluster resource manager crm is added to Heartbeat v2.x, and the cluster resource manager in Heartbeat v1.x is haresource, Heartbeat v2.x retains haresource for compatibility with v1.x, but at the same time a more powerful crm resource manager has been added. There are crm management methods, one is based on command line crmsh, the other is based on graphical interface hb_gui.
2. Components of Heartbeat v3.x
Heartbeat: Separate the original message communication layer into the heartbeat project. The new heartbeat is only responsible for maintaining the information of each node in the cluster and their previous communication.

Cluster Glue: It is equivalent to an intermediate layer, which is used to associate heartbeat and pacemaker. It mainly contains two parts, namely LRM and STONITH.

Resource Agent: A collection of scripts used to control the start and stop of services and monitor the status of services. These scripts will be called by LRM to realize the start, stop, and monitoring of various resources.

Pacemaker: That is, Cluster Resource Manager (CRM for short), which is used to manage the entire HA control center. The client uses pacemaker to configure, manage, and monitor the entire cluster.

homework : Achieve HA based on heartbeat v2 crm through LAMP combination.

1, address planning

node1.test.com 192.168.77.101 node2.test.com 192.168.77.30 vip 192.168.77.200


2. Host name resolution

[root@node1~]# uname-n node1.test.com [root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 localhost localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.77.101 node1.test.com 192.168.77.101 node1.test.com 192.168.77.101 node1.test.com node1 192.168.77.130 @node2~]#uname-n node2.test.com [root@node2~]#cat/etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain6local.localhost.6localhost localhost::1localhost6 localhost.localdomain6 node1.test.com node1 192.168.77.130 node2.test.com node2

3. Configure mutual trust between the two parties

[root@node1~]# ssh-keygen-trsa-f~/.ssh/id_rsa-P''[root@node1~]#ssh-copy-id- i.ssh/id_rsa.pub [email protected] [root@node2~]# ssh-keygen -t rsa -f~/.ssh/id_rsa -P'' [root@node2~]#ssh-copy- id -i.ssh/id_rsa.pub [email protected]

4. Configure time synchronization

#yum-y install ntpdate # ntpdate time.windows.com

5, install lamp

[root@node1~]#yuminstall http mysql- server php php-mysql

6. Install heartbeat related software packages

[root@node1~]#yuminstall net-snmp- libs libnet PyXML[root@node1~]# rpm-ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12 .el6.x86_64.rpm

7. Heartbeat configuration

copy ha.cf, authkeys,haresources under /etc/ha.d
[root@node1 ~]#cp/usr/share/doc/heartbeat-3.0.4/ {h a.cf,authkeys,haresources} /etc/ha.d/

Edit authkeys file

[root@node1 ~]# openssl rand -hex 8 >> authkeys #The generated key is appended to the authkeys file [root@node1~]# vi authkeys #Modify to the following configuration, use sha1 to encrypt auth 2#1crc#2sha1HI!#3md5Hello! 2 sha1 d0071be771be703c

Edit ha.cf main configuration file

[root@node1~]#grep-v'^#'ha .cf |sed'/^$/d' logfacility local0 mcast eth1 225.0.0.1 694 1 0 #Modify the propagation mode of heartbeat information|Multicast auto_failback on node1.test.com node 2#Configure the number of nodes in the cluster .com #Configure the number of nodes in the cluster

Edit haresources configuration file

[root@node1~]#grep-v"# "Haresourcesnode1.test.com 192.168.77.200/24/eth1 httpd

Copy configuration file guide node2

[root@node1~] #Scp/etc/ha.d/{ha.cf,haresources,authkeys} [email protected]:/etc/ha.d/

5. The node provides httpd service

Edit html

[root@node1 ~]#echo”

node1.test.com

“/var/www/html/index.html

Start httpd

[root@node1 ~]# service httpd start

Browse node1

< img onload="if(this.width>650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” title=”QQ screenshot 20151024221718 .jpg” alt=”wKioL1YrktuzoSaLAAC_Nl02afM037.jpg” d=”4702538″ s=”402_bee” t=”jpg”>

< /p>

node2 disable IPTABELS

[root@node2 ~]#getenforceDisabled[root@node2~]#service iptables stopiptables: set the chain to Policy ACCEPT: nat mangle filter [OK] iptables: clear firewall rules: [OK] iptables: Uninstalling module: 2> pnode [p] >wKioL1Yrk8fDzG9iAACvyIUwVDs862.jpg

Start the heartbeat service

[root@ node1~]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped Done.

View VIP

[root@node1~]# ip addreth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:c7:14:97 brd ff:ff:ff :ff:ff:ff inet 192.168.77.101/24 brd 192.168.0.255 scope global eth1 inet 192.168.77.200/24 ​​scope global eth1
Check whether the httpd service is Taken over by heartbeat [root@node1~]#netstat -tnlpu|grep httpd2 0 tcp 0::80 

p

onload="if(this.width>650) this.width=650;" src="/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png" title="node1.jpg" alt="wKiom1YrmxeDgU3MAACFFhcvWCY065.jpg" d="4702540" s="0e9_713" t="jpg">

Stop node1, test after httpd

wKioL1Yrm4HSuS9LAACbbhshcd8637.jpg

Leave a Comment

Your email address will not be published.