内部OA系统:Nginx+Keepalived实现站点高可用(1)(3)
3. 测试
根据上面的配置,初始化状态:172.29.88.224 (itoatest1,MASTER,101),172.29.88.222itoatest2,BACKUP,100),nginx和keepalived都启动,虚拟IP 172.29.88.222 在 itoatest1 上:
# 使用ip命令配置的地址,ifconfig查看不了
[root@itoatest1 nginx-1.6]# ip a|grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 172.29.88.224/24 brd 172.29.88.255 scope global eth0
inet 172.29.88.222/32 scope global eth0
浏览器访问 172.29.88.222 或域名,OK。
直接关闭 itoatest1 上的nginx:/usr/local/nginx-1.6/sbin/nginx -s stop
:
[root@localhost keepalived]# ip a|grep eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 172.29.88.224/24 brd 172.29.88.255 scope global eth0
vip消失,漂移到 itoatest2:
同时可以看到两台服务器上 /var/log/messages
:
## itoatest1
Jun 5 16:44:01 itoatest1 Keepalived_vrrp[44875]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.29.88.222
Jun 5 16:44:06 itoatest1 Keepalived_vrrp[44875]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.29.88.222
Jun 5 16:44:46 itoatest1 Keepalived_vrrp[44875]: VRRP_Script(chk_nginx) failed
Jun 5 16:44:48 itoatest1 Keepalived_vrrp[44875]: VRRP_Instance(VI_1) Received higher prio advert
Jun 5 16:44:48 itoatest1 Keepalived_vrrp[44875]: VRRP_Instance(VI_1) Entering BACKUP STATE
Jun 5 16:44:48 itoatest1 Keepalived_vrrp[44875]: VRRP_Instance(VI_1) removing protocol VIPs.
Jun 5 16:44:48 itoatest1 Keepalived_healthcheckers[44874]: Netlink reflector reports IP 172.29.88.222 removed
## itoatest2
Jun 5 16:44:00 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 5 16:44:00 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Received higher prio advert
Jun 5 16:44:00 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Entering BACKUP STATE
Jun 5 16:44:48 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) forcing a new MASTER election
Jun 5 16:44:48 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) forcing a new MASTER election
Jun 5 16:44:49 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 5 16:44:50 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Entering MASTER STATE
Jun 5 16:44:50 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) setting protocol VIPs.
Jun 5 16:44:50 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.29.88.222
Jun 5 16:44:50 itoatest2 Keepalived_healthcheckers[35554]: Netlink reflector reports IP 172.29.88.222 added
Jun 5 16:44:55 itoatest2 Keepalived_vrrp[35555]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.29.88.222
你也可以通过在两台服务器上抓包来查看 优先级priority 的变化:
## itoatest1 上
## 直接输出,或后加 -w itoatest-kl.cap存入文件用wireshark查看
# tcpdump -vvv -n -i eth0 dst 224.0.0.18 and src 172.29.88.224
参考
- 使用Keepalived实现Nginx高可用性
- High Availability Support Based on keepalived
- nginx+keepalived实现双机热备的高可用
- LVS原理详解及部署之五:LVS+keepalived实现负载均衡&高可用
- Keepalived双主模型中vrrp_script中权重改变故障排查
- 虚拟路由器冗余协议原理篇】VRRP详解
- Keepalived原理与实战精讲
来源:http://seanlook.com/2015/05/18/nginx-keepalived-ha/
评论暂时关闭