High-Availability

如何配置keepalived - 無法設置VIP

  • August 16, 2015

我正在嘗試在帶有故障轉移的 ubuntu 14.04 上設置編譯的 keepalived 1.2.19。不知何故,虛擬IP永遠不會出現:

ip addr show eth0 


2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
       link/ether 08:00:27:60:7f:89 brd ff:ff:ff:ff:ff:ff
       inet 192.168.56.120/24 brd 192.168.56.255 scope global eth0
          valid_lft forever preferred_lft forever
       inet 192.168.56.121/24 brd 192.168.56.255 scope global secondary eth0:0
          valid_lft forever preferred_lft forever
       inet6 fe80::a00:27ff:fe60:7f89/64 scope link 
          valid_lft forever preferred_lft forever

配置文件如下所示:

! Configuration File for keepalived
vrrp_script chk_haproxy {               # Requires keepalived-1.1.13
       script "killall -0 haproxy"     # cheaper than pidof
       interval 2                      # check every 2 seconds
       weight 2                        # add 2 points of prio if OK
}
vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 101
   priority 101        # 101 on master; 100 on backup
   virtual_ipaddress {
       192.168.56.150
   }
   track_script {
       chk_haproxy
   }
}

這看起來非常基本的設置。我究竟做錯了什麼?

重啟keepalived後的系統日誌:

Keepalived[4821]: Stopping Keepalived v1.2.19 (08/15,2015)
Keepalived[4988]: Starting Keepalived v1.2.19 (08/15,2015)
Keepalived[4989]: Starting Healthcheck child process, pid=4990
Keepalived_healthcheckers[4990]: Initializing ipvs 2.6
Keepalived[4989]: Starting VRRP child process, pid=4991
Keepalived_healthcheckers[4990]: Registering Kernel netlink reflector
Keepalived_healthcheckers[4990]: Registering Kernel netlink command channel
Keepalived_healthcheckers[4990]: Configuration is using : 6006 Bytes
Keepalived_vrrp[4991]: Registering Kernel netlink reflector
Keepalived_vrrp[4991]: Registering Kernel netlink command channel
Keepalived_vrrp[4991]: Registering gratuitous ARP shared channel
Keepalived_vrrp[4991]: Configuration is using : 57026 Bytes
Keepalived_vrrp[4991]: Using LinkWatch kernel netlink reflector...
Keepalived_healthcheckers[4990]: Using LinkWatch kernel netlink reflector...

我已經在我的機器上測試了你的配置並且它工作正常。Keepalived 將 VIP 分配給指定的介面,並且日誌顯示該行

Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE

我能夠重現您的案例的唯一方法是提供一個空配置文件(對不存在文件的測試失敗,因為啟動腳本會檢查它)。

您需要驗證啟動腳本中指定的配置文件/etc/init.d/keepalived

引用自:https://serverfault.com/questions/714484