0

我正在使用2个vagrant Centos7实例安装keepalived进行虚拟IP故障转移,但有问题(我在生产中遇到同样的问题)。当主控主机重新启动时,Keepalived虚拟IP将不会被传回

基本上,我有两个运行keepalived的实例。下面是这些2个服务器的配置keepalived.conf:

服务器1的配置:

global_defs { 
    notification_email { 
     [email protected] 
    } 
    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 { 
     [email protected] 
    } 
    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的服务KEEPALIVED停在Server1 ;那么虚拟ipaddresses被成功传送到server2。当我开始使用“sudo service keepalived start”重新启动服务器1时,IP地址被转回。当我在server1上执行“sudo reboot”时,所有内容也都正常工作。但是,如果我使用以下命令关闭然后重新启动server1:sudo shutdown -h now(或vagrant halt server1)然后流浪server1,则虚拟IP将不会被分配给任一服务器。 (ip addr show 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服务keepalived stop停止服务;发生这种情况时,虚拟IP不会分配给任何服务器。

感谢。

回答

1

根据日志,在网络接口enp0s8启动并准备就绪之前,keepalived已经启动。如果你想Keepalived跟踪接口,你应该在vrrp_instance中添加这样的内容

track_interface { 
    enp0s8 
}