Heartbeat (Linux-HA) working principle: The core of heartbeat consists of two parts, the heartbeat monitoring part and the resource takeover part. The heartbeat monitoring can be carried out through the network link and the serial port, and Supports redundant links. They send messages to each other to tell each other their current status. If the message sent by the other party is not received within the specified time, then the other party is considered to be invalid. At this time, the resource takeover module needs to be activated. Take over the resources or services running on the host of the other party.
Test environment:
OS:CentOS6.6_64
master-ip:10.0.0.16
slave-ip: 10.0.0.17< /p>
vip-ip:10.0.0.100
1. Master installation configuration
[root@master ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@master ~]# yum install heartbeat libnet -y
1. Basic configuration:
[root@master ~]# cat /etc/ hosts
10.0.0.16 master
10.0.0.17 slave
[root@master ~]# ifconfig eth1:0 10.0.0.100 netmask 255.255.255.0 up< /p>
[root@master ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
2. Modify the above three configuration files as follows:
[root@master ~]# egrep -v “#|^$” /etc/ha .d/authkeys
auth 3
3 md5 Hello!
[root@master ~]# chmod 600 /etc/ha.d/authkeys
p>
[root@master ~]# egrep -v “#|^$” /etc/ha.d/haresources
master 10.0.0.100 /24/eth1:0 nginx
[root@master ~]# egrep -v “#|^$” /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10 p>
initdead 60
udpport 694
ucast eth1 10.0.0.17
auto_failback on
node master
node slave
ping 10.0.0.2 ###arbitration ip
respawn hacluster /usr/lib64/heartbeat/ipfail
[root@master ~]# yum install nginx
[root@master ~]# echo “www.master.com” >/usr/share/nginx/html/index.html
Second, Slave installation configuration
[root@slave ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo /epel-6.repo
[root@slave ~]# yum install heartbeat libnet -y
1. Basic configuration
[root@slave ~]# cat /etc/hosts
10.0.0.16 master
10.0.0.17 slave
2, copy configuration file And modification
[root@master ha.d]# scp ha.cf haresources authkeys slave:/etc/ha.d/
Only need to modify ha.cf File, the other two configurations are the same
[root@slave ~]#egrep -v “#|^$” /etc/ha.d/ha.cf
debugfile / var/log/ha-debu g
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth1 10.0. 0.16
auto_failback on
node master
node slave
ping 10.0.0.2
respawn hacluster /usr/lib64/heartbeat/ipfail
3. Install nginx service
[root@slave ~]# yum install nginx
[root@slave ~]# echo “www.slave.com”>/usr/share/nginx/html/index.html
3. Start Heartbeat
You must start the heartbeat on the master first
[ root@master ~]# /etc/init.d/heartbeat start
nginx does not need to be started manually, heartbeat will start it
[root@slave ~]# /etc/init.d/heartbeat start
four, test function:< /span>
Direct access to 10.0.0.100 on the client will display “www.master.com”
Disable the master. Or simply shut down and visit 10.0.0.100 again, it will display “www.slave.com”, indicating that the nginx service has been successfully taken over! ! !