13. 启动heartbeat并做切换测试
先停止nginx并复制启动文件到resource目录(需要在2台node上执行)
/etc/init.d/nginx stop
先调整SElinux配置为Permissive,防止heartbeat无法启动
[root@test1 log]# getenforce
Enforcing
[root@test1 log]# setenforce 0
[root@test1 log]# getenforce
Permissive
启动heartbeat服务
/etc/init.d/heartbeat start
查看日志
tail -f /var/log/ha-log
主机:
Nov 07 17:25:26 test1 heartbeat: [4610]: info: Status update for node test2: status active
harc(default)[5261]: 2012/11/07_17:25:26 info: Running /etc/ha.d//rc.d/status status
备机:
Nov 07 17:24:45 test2 heartbeat: [3453]: info: Link test1:eth1 up.
Nov 07 17:24:45 test2 heartbeat: [3453]: info: Status update for node test1: status active
harc(default)[4123]: 2012/11/07_17:24:45 info: Running /etc/ha.d//rc.d/status status
抓包查看UDP通信是否正常
[root@test2 ~]# tcpdump -nni eth1 host 192.168.159.100
17:25:41.412651 IP 192.168.159.110.22152 > 192.168.159.100.694: UDP, length 175
17:25:41.412781 IP 192.168.159.110.22152 > 192.168.159.100.694: UDP, length 172
虚拟IP在主机上已经启用,nginx服务也被heartbeat正常启动
inet 192.168.159.250/24 brd 192.168.159.255 scope global secondary eth0:0
14. 进行主备机的HA切换测试
在主机上停止heartbeat服务
/etc/init.d/heartbeat stop
查看日志
tail -f /var/log/ha-log
主机:
ResourceManager(default)[5304]: 2012/11/07_17:31:01 info: Releasing resource group: test1 IPaddr::192.168.159.250/24/eth0 drbddisk::r0 Filesystem::/dev/drbd1::/drbd::ext3 nginx
ResourceManager(default)[5304]: 2012/11/07_17:31:01 info: Running /etc/ha.d/resource.d/nginx stop
ResourceManager(default)[5304]: 2012/11/07_17:31:01 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd1 /drbd ext3 stop
Filesystem(Filesystem_/dev/drbd1)[5369]: 2012/11/07_17:31:01 INFO: Running stop for /dev/drbd1 on /drbd
Filesystem(Filesystem_/dev/drbd1)[5369]: 2012/11/07_17:31:01 INFO: Trying to unmount /drbd
Filesystem(Filesystem_/dev/drbd1)[5369]: 2012/11/07_17:31:01 INFO: unmounted /drbd successfully
备机:
Nov 07 17:30:50 test2 heartbeat: [3453]: info: mach_down takeover complete.
Nov 07 17:30:59 test2 heartbeat: [3453]: WARN: node test1: is dead
Nov 07 17:30:59 test2 heartbeat: [3453]: info: Dead node test1 gave up resources.
Nov 07 17:30:59 test2 heartbeat: [3453]: info: Link test1:eth1 dead.
从日志上观察备机切换正常
在备机上查看IP, drbd挂载,nginx服务
[root@test2 ~]# ip add list
inet 192.168.159.250/24 brd 192.168.159.255 scope global secondary eth1:0
[root@test2 ~]# df -h
/dev/drbd1 2.0G 76M 1.8G 4% /drbd
[root@test2 ~]# netstat -tunlp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4635/nginx
以上说明切换正常,heartbeat+drbd可以在备机正常使用
15. 主机heartbeat恢复,手动进行主备切换
在主机上再次开启heartbeat服务,主备不会切换
/etc/init.d/heartbeat start
在备机上停止heartbeat服务,主备会再次切换,服务和数据依然可以正常使用,数据也通过drbd保持一致
/etc/init.d/heartbeat stop