我正在使用 2 个 vagrant Centos7 实例为虚拟 IP 故障转移安装 keepalived,但遇到了问题(我在生产中遇到了同样的问题)。
基本上,我有 2 个运行 keepalived 的实例。以下是这 2 台服务器的配置 keepalived.conf:
Server1的配置:
global_defs {
notification_email {
ABC@gmail.com
}
notification_email_from server1.dev.vagrant.net
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_enp0s8 {
state MASTER
interface enp0s8
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.65.110
192.168.65.111
}
}
Server2的配置:
global_defs {
notification_email {
ABC@gmail.com
}
notification_email_from server2.dev.vagrant.net
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_enp0s8 {
state BACKUP
interface enp0s8
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.65.110
192.168.65.111
}
}
基本上,如果我停止 keepalived 使用: sudo service keepalived stop on server1; 然后虚拟IP地址成功传输到server2。当我使用“sudo service keepalived start”在 server1 上启动 keepalived 时,IP 地址将被传回。当我在 server1 上执行“sudo reboot”时,一切都正常工作。
但是,如果我关闭然后重新启动 server1 使用:sudo shutdown -h now(或 vagrant halt server1)然后 vagrant up server1,那么虚拟 IP 将不会分配给任一服务器。(ip 地址显示 enp0s8)。
下面是 /var/log/messages 的日志。在我看来,由于某种原因,虚拟 IP 已被添加,但随后被删除。
Jun 21 08:19:50 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) Entering MASTER STATE
Jun 21 08:19:50 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) setting protocol VIPs.
Jun 21 08:19:50 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.110 added
Jun 21 08:19:50 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.111 added
Jun 21 08:19:50 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) Sending gratuitous ARPs on enp0s8 for 192.168.65.110
Jun 21 08:19:50 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) Sending gratuitous ARPs on enp0s8 for 192.168.65.111
Jun 21 08:19:52 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.104 removed
Jun 21 08:19:52 oasis4 Keepalived_vrrp[724]: Netlink reflector reports IP 192.168.65.104 removed
Jun 21 08:19:52 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.110 removed
Jun 21 08:19:52 oasis4 Keepalived_vrrp[724]: Netlink reflector reports IP 192.168.65.110 removed
Jun 21 08:19:52 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.111 removed
Jun 21 08:19:52 oasis4 Keepalived_vrrp[724]: Netlink reflector reports IP 192.168.65.111 removed
Jun 21 08:19:52 oasis4 kernel: e1000: enp0s8 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
Jun 21 08:19:52 oasis4 kernel: IPv6: ADDRCONF(NETDEV_UP): enp0s8: link is not ready
Jun 21 08:19:52 oasis4 kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp0s8: link becomes ready
Jun 21 08:19:54 oasis4 Keepalived_healthcheckers[723]: Netlink reflector reports IP 192.168.65.104 added
Jun 21 08:19:54 oasis4 Keepalived_vrrp[724]: Netlink reflector reports IP 192.168.65.104 added
Jun 21 08:19:55 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) Sending gratuitous ARPs on enp0s8 for 192.168.65.110
Jun 21 08:19:55 oasis4 Keepalived_vrrp[724]: VRRP_Instance(VI_enp0s8) Sending gratuitous ARPs on enp0s8 for 192.168.65.111
Jun 21 08:19:55 oasis4 systemd: Starting Session 2 of user vagrant.
Jun 21 08:19:55 oasis4 systemd: Started Session 2 of user vagrant.
Jun 21 08:19:55 oasis4 systemd-logind: New session 2 of user vagrant.
Jun 21 08:19:56 oasis4 systemd-logind: Removed session 1.
Jun 21 08:20:00 oasis4 systemd: Starting Session 3 of user vagrant.
Jun 21 08:20:00 oasis4 systemd: Started Session 3 of user vagrant.
Jun 21 08:20:00 oasis4 systemd-logind: New session 3 of user vagrant.
Jun 21 08:20:01 oasis4 systemd: Starting user-0.slice.
Jun 21 08:20:01 oasis4 systemd: Created slice user-0.slice.
Jun 21 08:20:01 oasis4 systemd: Starting Session 4 of user root.
如果我登录到 server1,然后手动重新启动 keepalived,那么事情就会开始正常工作。
如果我的配置有什么问题,有人可以告诉我吗?
此外,有几次我无法使用 sudo service keepalived stop 正确停止服务;发生这种情况时,虚拟 IP 不会分配给任一服务器。
谢谢。