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 
}