HA is a highly available cluster (high available cluster), also known as dual-machine hot standby, to ensure uninterrupted service of critical business. Such as: Two Machines A and B, normal a service, B standby idle; a downtime or service outage, automatic switch to B machine continue to provide services. There are heartbeat and keepalived for high-availability open source software, and keepalived also features load balancing. Heartbeat as a common cluster open source software, familiar with its configuration method, it is very necessary.
Description: The following is an introduction to the Yum installation and configuration of heartbeat, the need to extend the Epel source, if not, to execute the command:
# yum Install-y epel-release
1. Test environment:
Two CentOS 6.0 64-bit virtual machines (master:eth1:192.168.220.11;slave:eth1:192.168.220.22), master host set up a virtual IP as the heartbeat line (the virtual machine has only one network card, The actual application should have more than one network card, or use a serial port to connect, otherwise there will be unsafe factors)
2. Pre-Preparation:
"1" Modified hostname: (The purpose of modifying hostname is to facilitate memory, hostname can be customized)
Master Host:
# vim/etc/sysconfig/networknetworking=yeshostname=master# hostname Master;bash
Slave Host:
# vim/etc/sysconfig/networknetworking=yeshostname=slave# hostname Slave;bah
"2" Modify the/etc/hosts file (two hosts for the same configuration)
# vim/etc/hosts192.168.220.11 master192.168.220.22 Slave
"3" shuts down the firewall
# iptables-f# Getenforce //If get to disabled, do not need to do configuration; if get is enforcing, make the following changes: # vim/etc/selinux/configselinux= Enforcing-selinux=disabled
"4" Virtual IP settings
# cd/etc/sysconfig/network-scripts# CP ifcfg-eth1 ifcfg-eth1:0# vim ifcfg-eth1:0 //Simple configuration, many parameters do not need to set, as follows: device= eth1:0 //modified to eth1:0type=ethernetonboot=yesnm_controlled=yesbootproto=staticipaddr=192.168.220.33 // Modified to 33netmask=255.255.255.0#/etc/init.d/network restart# ifconfig //configured correctly, can list eth1:0 virtual network card information
3. Installation and configuration of heartbeat:
"1" Yum install: # yum install-y heartbeat* libnet nginx//Dependent Libnet,nginx is our trial service and can be installed with Yum.
Configuration of the "2" Master host:
# cd/usr/share/doc/heartbeat-3.0.4/ //Note version of the issue, can not 3.0.4# CP authkeys HA.CF haresources/etc/ha.d/// Copy 3 core config files # CD/ETC/HA.D
(1) Modify Authkeys
# vim Authkeys //The last 4 lines are configured as follows: # auth 1 #1 CRC //least rigorous #2 SHA1 hi! The most rigorous #3 MD5 hello! Middle Value
Change the value after the first row of Auth to 3, and open the last line of comments, which is the type of intermediate rigor.
# chmod Authkeys //Modify permission is 600, otherwise heartbeat cannot start
(2) Modify Haresources
# vim Haresources //The default is all comments, so you can append one line: Master 192.168.220.33/24/eth1:0 nginx //Note Here IP is the IP of the virtual network card, that is, the configuration IP of the heartbeat line , 24 specified network segment, Nginx is the name of the service we want to test
(3) Modify HA.CF
# > HA.CF //Empty config # vim!$ //Edit, add the following configuration: debugfile/var/log/ha-debug //Troubleshooting log path logfile/var/log/ Ha-log //Run log logfacility local0 keepalive 2 deadtime warntime initdead Udpport 694 ucast eth1 192.168.220.22 //slave network card IP auto_failback on node master node Slave ping 192.168.220.2 //Arbitration address, usually a router address, or a secure, service-stable IP respawn hacluster/usr/lib64/heartbeat/ipfail //NOTE: 32bit Linux system, the path is LIB, not lib64, as follows: ########## Error:client child command [/usr/lib/heartbeat/ipfail] was not executable ##############
(4) Copy the configuration file to the slave host:
# SCP Authkeys ha.cf haresources slave:/etc/ha.d/
Configuration of "3" Slave host: only need to modify HA.CF:
Ucast eth1 192.168.220.22 to ucast eth1 192.168.220.11 //Convert IP to master IP address
"4" Start Heartbeat (first master, rear slave)
(1) Master host
#/etc/init.d/heartbeat startstarting high-availability services:info: Running Okcritical:resource 192.168.220.33/24/eth1:0 is active, and should not be! Critical:non-idle resources can affect data integrity!info:if you don't know what this means and then get Help!info:read t He docs and/or source To/usr/share/heartbeat/resourcemanager for more details. Critical:resource 192.168.220.33/24/eth1:0 is active, and should not be! Critical:non-idle resources can affect data integrity!info:if you don't know what this means and then get Help!info:read t He docs and/or the source To/usr/share/heartbeat/resourcemanager for more details. Critical:non-idle resources would affect resource takeback! Critical:non-idle resources may affect data integrity! Done.
heartbeat will automatically pull the Nginx, but the first boot will be slow. After some time (10S), check if Nginx is pulled up:
# PS aux |grep nginx
(2) Modify the Nginx index.html to check the operation status of the machine conveniently:
# >/usr/share/doc/nginx/html/index.html //Empty # echo "Mastermmmmmmmmmmmm" >!$
If Nginx has been started, enter the following URL in the browser: 192.168.220.33, should be able to get the receipt result (virtual network card IP): mastermmmmmmmmmmmm
(3) Slave host:
Under normal circumstances, Nginx is not pulled up, because the host has not been down, so the result of PS aux |grep nginx is empty.
Modify Nginx's index.html:
# >/usr/share/doc/nginx/html/index.html# echo "slavessssssssssssss" >!$
The principle of the heart jumper detection is ping, then we shut down the master ping Service, heartbeat detected a ping failure, the Nginx service will be transferred to slave to execute:
Iptables-a input-p icmp-j DROP//ping command from the ICMP protocol, turn off protocol, ping fails.
at this point, you can use the Tail-f/var/log/ha-log command to view the process of the heartbeat:
Master's Ha-log log content:
Jan 22:47:32 Master heartbeat: [2574]: Warn:node 192.168.220.2:is dead//ping 192.168.220.2 router failure Jan 22:47:32 MA Ster ipfail: [2601]: Info:status update:node 192.168.220.2 now have Status Deadjan one 22:47:32 master heartbeat: [2574]: Info:link 192.168.220.2:192.168.220.2 dead. Router hangs Harc (default) [2929]:2016/01/11_22:47:32 info:running/etc/ha.d//rc.d/status Statusjan 22:47:33 Master Ipfail: [2601]: Info:NS:We is dead. :< Jan 22:47:33 Master ipfail: [2601]: Info:link status Update:link 192.168.220.2/192.168.220.2 now have status DEA Djan 22:47:34 Master ipfail: [2601]: Info:we is dead. :<//Oh, it turns out we hung up. Jan 22:47:34 Master ipfail: [2601]: info:asking Other side for Ping node count. Jan 22:47:37 Master ipfail: [2601]: info:giving up because we were told, we have a less ping nodes. Jan 22:47:37 Master ipfail: [2601]: info:delayed giveup in 4 seconds. Jan 22:47:41 Master Ipfail: [2601]: Info:giveup () called (timeout worked) Jan 22:47:42 MaSter heartbeat: [2574]: Info:master wants to go standby [All]jan one 22:47:42 master heartbeat: [2574]: Info:standby:sla ve can takes our all resources//from the can take over service Jan one 22:47:42 master heartbeat: [2956]: info:give Up all HA resources (standby) . Give up our work ResourceManager (default) [2969]:2016/01/11_22:47:42 info:releasing resource Group:master 192.168.220.33/24 /eth1:0 Nginxresourcemanager (default) [2969]:2016/01/11_22:47:42 Info:running/etc/init.d/nginx Stop// Stop Nginx service ResourceManager (default) [2969]:2016/01/11_22:47:42 info:running/etc/ha.d/resource.d/ipaddr 192.168.220.33/24/eth1:0 stopipaddr (ipaddr_192.168.220.33) [3057]:2016/01/11_22:47:42 info:ip status = OK, IP_CIP=/ USR/LIB/OCF/RESOURCE.D//HEARTBEAT/IPADDR (ipaddr_192.168.220.33) [3031]:2016/01/11_22:47:42 Info:successjan 11 22:47:42 Master heartbeat: [2956]: Info:all HA resource release completed (standby). Jan 22:47:42 Master heartbeat: [2574]: info:local standby process completed [all]. Jan 22:47:43 Master HeartbeaT: [2574]: Warn:1 lost Packet (s) for [slave] [459:461]jan one 22:47:43 master heartbeat: [2574]: info:remote resource tra Nsition completed. Remote resource delivery complete Jan 22:47:43 master heartbeat: [2574]: Info:no pkts missing from slave! No missing data. Jan 22:47:43 Master heartbeat: [2574]: Info:other node completed standby takeover of all resources. The slave node completely takes over our work
Jan 11:48:17 slave ipfail: [115215]: info:telling Other node, we have more visible ping nodes. Tell master we can ping 11:48:22 slave heartbeat: [115188]: Info:master wants to go standby [all]//master want us to take over the Jan. 11:48:22 slave heartbeat: [115188]: info:standby:acquire [all] resource from master//Accept resources from master Jan 12 11:48:22 Slave heartbeat: [115841]: Info:acquire all HA resources (standby). ResourceManager (default) [115854]:2016/01/12_11:48:22 info:acquiring resource Group:master 192.168.220.33/24/eth1:0 NGINX/USR/LIB/OCF/RESOURCE.D//HEARTBEAT/IPADDR (ipaddr_192.168.220.33) [115882]:2016/01/12_11:48:22 Info:resource is Stoppedresourcemanager (default) [115854]:2016/01/12_11:48:22 info:running/etc/ha.d/resource.d/ipaddr 192.168.220.33/24/eth1:0 Start//start heartbeat line Nic IPAddr (ipaddr_192.168.220.33) [116015]:2016/01/12_11:48:22 info:adding inet Address 192.168.220.33/24 with broadcast address 192.168.220.255 to device eth1 (with label eth1:0)//virtual network card points to our Nic IPAddr ( Ipaddr_192.168.220.33) [116015]:2016/01/12_11:48:22 info:bringing device eth1 upipaddr (ipaddr_192.168.220.33) [116015] : 2016/01/12_11:48:22 INFO:/usr/libexec/heartbeat/send_arp-i 200-r 5-p/var/run/resource-agents/send_ arp-192.168.220.33 eth1 192.168.220.33 Auto not_used not_used/usr/lib/ocf/resource.d//heartbeat/ipaddr (ipaddr_ 192.168.220.33) [115989]:2016/01/12_11:48:22 info:success//NIC configuration complete ResourceManager (default) [115854]:2016/01/12_ 11:48:22 Info:running/etc/init.d/nginx Start//Start nginx service Jan 11:48:23 slave heartbeat: [115841]: Info:all HA Resou RCE acquisition completed (standby). All HA resources have been taken over. Jan 11:48:23 slave heartbeat: [115188]: Info:standby resource acquisition done [all]. The resources have been taken over. Jan 11:48:24 slave heartbeat: [115188]: Info:remote resource transition completed. Remote resource transfer finished, finished work!!!
According to these contents, we can know the operation of heartbeat, so when the browser input the network card address of the heartbeat line: 192.168.220.33, the following results are returned:
Slavessssssssssssss
At this time, Master's Nginx was closed, and slave's Nginx formally took over, the completion of the service provided uninterrupted.
If you did not use a firewall, but to execute the command, the heartbeat service is closed, the result is the same, slave will take over the Nginx service. So what happens if you remove the ipatables rule, or turn the heartbeat service back on?
# ipatales-d input-p icmp-j drop# service Heartbeat start
As a result, slave automatically shuts down the Nginx,master Nginx and restarts, taking over the Web service, and can experiment with it himself. Refresh your browser to see the results clearly.
Cluster (heartbeat) Building