# 注意此时备机还未开始安装 [root@hk01 ~]# less /var/log/messages
.... May 12 23:46:51 localhost systemd: Starting LVS and VRRP High Availability Monitor... May 12 23:46:51 localhost Keepalived[18849]: Starting Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2 May 12 23:46:51 localhost Keepalived[18849]: Opening file '/etc/keepalived/keepalived.conf'. May 12 23:46:51 localhost Keepalived[18850]: Starting Healthcheck child process, pid=18851 May 12 23:46:51 localhost systemd: Started LVS and VRRP High Availability Monitor. May 12 23:46:51 localhost Keepalived[18850]: Starting VRRP child process, pid=18852 May 12 23:46:51 localhost Keepalived_healthcheckers[18851]: Opening file '/etc/keepalived/keepalived.conf'. May 12 23:46:51 localhost Keepalived_vrrp[18852]: Registering Kernel netlink reflector May 12 23:46:51 localhost Keepalived_vrrp[18852]: Registering Kernel netlink command channel May 12 23:46:51 localhost Keepalived_vrrp[18852]: Registering gratuitous ARP shared channel May 12 23:46:51 localhost Keepalived_vrrp[18852]: Opening file '/etc/keepalived/keepalived.conf'. May 12 23:46:51 localhost Keepalived_vrrp[18852]: WARNING - default user 'keepalived_script' for script execution does not exist - please create. May 12 23:46:51 localhost Keepalived_vrrp[18852]: SECURITY VIOLATION - scripts are being executed but script_security not enabled. May 12 23:46:51 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) removing protocol VIPs. May 12 23:46:51 localhost Keepalived_vrrp[18852]: Using LinkWatch kernel netlink reflector... May 12 23:46:51 localhost Keepalived_vrrp[18852]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)] May 12 23:46:51 localhost Keepalived_vrrp[18852]: VRRP_Script(check_web) succeeded May 12 23:46:52 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) Transition to MASTER STATE May 12 23:46:52 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) Changing effective priority from 100 to 102 May 12 23:46:53 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) Entering MASTER STATE May 12 23:46:53 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) setting protocol VIPs. May 12 23:46:53 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:53 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.174.201 May 12 23:46:53 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:53 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:53 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:53 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 12 23:46:58 localhost Keepalived_vrrp[18852]: Sending gratuitous ARP on eth0 for 192.168.174.201 ....
[root@hk02 ~]# ip a s eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:59:d4:55 brd ff:ff:ff:ff:ff:ff inet 192.168.174.138/24 brd 192.168.174.255 scope global noprefixroute dynamic eth0 valid_lft 5522648sec preferred_lft 5522648sec inet 192.168.174.201/24 scope global secondary eth0:1 valid_lft forever preferred_lft forever inet6 fe80::c5f2:37c:a210:ea88/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever inet6 fe80::8074:c1a5:fa67:cfaa/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever inet6 fe80::772e:38a7:d2af:640a/64 scope link noprefixroute valid_lft forever preferred_lft forever
# 查看日志 [root@hk02 ~]# less /var/log/messages .... May 13 00:02:19 localhost Keepalived_vrrp[23211]: VRRP_Instance(VI_1) Transition to MASTER STATE May 13 00:02:20 localhost Keepalived_vrrp[23211]: VRRP_Instance(VI_1) Entering MASTER STATE May 13 00:02:20 localhost Keepalived_vrrp[23211]: VRRP_Instance(VI_1) setting protocol VIPs. May 13 00:02:20 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:20 localhost Keepalived_vrrp[23211]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.174.201 May 13 00:02:20 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:20 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:20 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:20 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 May 13 00:02:25 localhost Keepalived_vrrp[23211]: Sending gratuitous ARP on eth0 for 192.168.174.201 ....
3.恢复master nginx和keepalive服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 恢复了master 的nginx,vip会自动切换回到master节点上 [root@hk01 ~]# systemctl start nginx [root@hk01 ~]# systemctl start keepalived [root@hk01 ~]# ip a s eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:24:49:ed brd ff:ff:ff:ff:ff:ff inet 192.168.174.137/24 brd 192.168.174.255 scope global noprefixroute dynamic eth0 valid_lft 5521457sec preferred_lft 5521457sec inet 192.168.174.201/24 scope global secondary eth0:1 valid_lft forever preferred_lft forever inet6 fe80::8074:c1a5:fa67:cfaa/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever inet6 fe80::c5f2:37c:a210:ea88/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@hk01 ~]# curl 192.168.174.201 node-hk01