node1 :192.168.0.155
10.1.1.2 (心跳)
node2 :192.168.0.156
10.1.1.3 (心跳)
虚拟IP: 192.168.0.222
1.安装hearbeat软件
yum install epel* -y
yum install heartbeat* -y
2:确保每个节点hosts文件都有条目
192.168.0.155 node1
10.1.1.2 node1
192.168.0.156 node2
10.1.1.3 node2
3:配置authkeys,确保每个节点一致 确保此文件权限为600
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf haresources authkeys /etc/ha.d/
vi authkeys
auth 11 crc
#2 sha1 HI!
#3 md5 Hello!
chmod 600 authkeys
4:配置各个节点的ha.cf
node1配置如下:
autojoin none
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
bcast eth1
ucast eth1 10.1.1.3
auto_failback on
node node1
node node2
ping 192.168.0.1
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
node2配置如下:
autojoin none
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
bcast eth1
ucast eth1 10.1.1.2
auto_failback on
node node1
node node2
ping 192.168.0.1
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
5:配置haresource,确保每个节点一致
node1 IPaddr::192.168.0.222/24/eth0 httpd
lnmp必须要是/etc/init.d/里的服务
6:启动Heartbeat
service heartbeat start
7.测试。
1) 拔掉任意一台的业务网卡网线
2) 拔掉任意一台的心跳网卡网线
3) 关闭任意一台机器电源
tcpdump -i all -n -p udp port 694 可以看广播信息,如果用的bcast的话。
如果有多个节点,只需配置一个节点 然后通过 ha_propagate 脚本将配置文件扩散到其他节点。那样的话用mcast比较方便。