环境说明:
主机名 | 角色 | IP地址 |
heartbeat+haproxy | eth0: eth1: | |
heartbeat+haproxy | eth0: eth1: | |
web server 1 | eth0: | |
web server 2 | eth0: |
一、环境准备
在mylinux1和mylinux2上安装heartbeat,可以手动安装,当然也可以使用前面发布的一篇heartbeat脚本的博文,里面有heartbeat快速安装脚本。
然后在mylinux2上安装haproxy,并将mylinux1上的haproxy配置文件和启停脚本都拷贝到mylinux2上。
要保证mylinux1和mylinux2的heartbeat+haproxy环境一致。
[root@mylinux1 ~]# scp /etc//haproxy mylinux2:/etc// root@mylinux2's password: Permission denied, please try again. root@mylinux2's password: haproxy 100% 1567 /s 00:00 [root@mylinux1 ~]# scp /usr/local/haproxy/conf/ mylinux2:/usr/local/haproxy/conf/ root@mylinux2's password: 100% 1194 /s 00:00 [root@mylinux2 haproxy]# ll /etc//haproxy -rwxr-xr-x 1 root root 1567 Oct 1 02:11 /etc//haproxy [root@mylinux2 haproxy]# ll /usr/local/haproxy/conf/ -rw-r--r-- 1 root root 1194 Oct 1 02:13 /usr/local/haproxy/conf/
二、修改heartbeat的资源文件
[root@mylinux1 ~]# tail -1 /etc//haresources IPaddr::/24/eth0 haproxy [root@mylinux2 haproxy]# tail -1 /etc//haresources IPaddr::/24/eth0 haproxy
这里还是贴出两个heartbeat节点的配置,如下:
[root@mylinux1 ~]# egrep -v "#|^$" /etc// debugfile /var/log/ha-debug logfile/var/log/ha-log logfacilitylocal1 keepalive 2 deadtime 30 warntime 10 initdead 120 udpport694 mcast eth1 694 1 0 auto_failback on respawn hacluster /usr/lib64/heartbeat/ipfail [root@mylinux2 haproxy]# egrep -v "#|^$" /etc// debugfile /var/log/ha-debug logfile/var/log/ha-log logfacilitylocal1 keepalive 2 deadtime 30 warntime 10 initdead 120 udpport694 mcast eth1 694 1 0 auto_failback on node node respawn hacluster /usr/lib64/heartbeat/ipfail
三、启动heartbeat服务
1、首先在mylinux1和mylinux2上先关闭haproxy服务
[root@mylinux1 ~]# service haproxy stop Stop haproxy successful. [root@mylinux2 haproxy]# service haproxy stop Haproxy is not running. Stop haproxy failed!
2、依次启动mylinux1和mylinux2上的heartbeat服务
[root@mylinux1 ~]# /etc//heartbeat start Starting High-Availability services: INFO: Resource is stopped Done. [root@mylinux2 haproxy]# /etc//heartbeat start Starting High-Availability services: INFO: Resource is stopped Done.
四、测试haproxy的高可用
1、首先,检查mylinux1的状态
[root@mylinux1 ~]# ip a|grep inet /24 brd scope global secondary eth0 [root@mylinux1 ~]# service haproxy status Haproxy (pid 3600) is running...
2、其次,检查mylinux2的状态
[root@mylinux2 haproxy]# ip a |grep [root@mylinux2 haproxy]# service haproxy status Haproxy is stopped.
3、查看监控界面
五、测试故障切换
1、停止mylinux1上的heartbeat服务
[root@mylinux1 ~]# /etc//heartbeat stop Stopping High-Availability services: Done.
2、检查mylinux1和mylinux2的状态
[root@mylinux1 ~]# ip a |grep [root@mylinux1 ~]# service haproxy status Haproxy is stopped. [root@mylinux2 haproxy]# ip a |grep inet /24 brd scope global secondary eth0 [root@mylinux2 haproxy]# service haproxy status Haproxy (pid 3997) is running...
3、查看监控页面
4、查看mylinux2上的heartbeat日志
[root@mylinux2 ~]# >/var/log/ha-log
[root@mylinux2 ~]# tail -f /var/log/ha-log
Oct 01 02:44:31 heartbeat: [3534]: info: Received shutdown notice from ''.
Oct 01 02:44:31 heartbeat: [3534]: info: Resources being acquired from .
Oct 01 02:44:31 heartbeat: [3655]: info: acquire local HA resources (standby).
Oct 01 02:44:31 heartbeat: [3656]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys ] to acquire.
Oct 01 02:44:31 heartbeat: [3655]: info: local HA resource acquisition completed (standby).
Oct 01 02:44:31 heartbeat: [3534]: info: Standby resource acquisition done [all].
harc(default)[3681]:2016/10/01_02:44:31 info: Running /etcstatus status
mach_down(default)[3698]:2016/10/01_02:44:31 info: Taking over resource group IPaddr::/24/eth0
ResourceManager(default)[3725]:2016/10/01_02:44:31 info: Acquiring resource group: IPaddr::/24/eth0 haproxy
/usr/lib/ocf///heartbeat/IPaddr(IPaddr_)[3753]: 2016/10/01_02:44:31 INFO: Resource is stopped
ResourceManager(default)[3725]:2016/10/01_02:44:31 info: Running /etc///IPaddr /24/eth0 start
IPaddr(IPaddr_)[3878]:2016/10/01_02:44:32 INFO: Adding inet address /24 with broadcast address to device eth0
IPaddr(IPaddr_)[3878]:2016/10/01_02:44:32 INFO: Bringing device eth0 up
IPaddr(IPaddr_)[3878]:2016/10/01_02:44:32 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp- eth0 auto not_used not_used
/usr/lib/ocf///heartbeat/IPaddr(IPaddr_)[3852]: 2016/10/01_02:44:32 INFO: Success
ResourceManager(default)[3725]:2016/10/01_02:44:32 info: Running /etc//haproxy start
mach_down(default)[3698]:2016/10/01_02:44:32 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down(default)[3698]:2016/10/01_02:44:32 info: mach_down takeover complete for node .
Oct 01 02:44:32 heartbeat: [3534]: info: mach_down takeover complete.
Oct 01 02:45:02 heartbeat: [3534]: WARN: node : is dead
Oct 01 02:45:02 heartbeat: [3534]: info: Dead node gave up resources.
Oct 01 02:45:02 heartbeat: [3534]: info: Link :eth1 dead.
Oct 01 02:45:02 ipfail: [3543]: info: Status update: Node now has status dead
Oct 01 02:45:03 ipfail: [3543]: info: NS: We are dead. :<
Oct 01 02:45:03 ipfail: [3543]: info: Link Status update: Link /eth1 now has status dead
Oct 01 02:45:04 ipfail: [3543]: info: We are dead. :<
Oct 01 02:45:04 ipfail: [3543]: info: Asking other side for ping node count.