如何configurationkeepalived – 无法设置VIP

我正在尝试在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文件如下所示:

 ! 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... 

我已经在我的机器上testing了你的configuration,它工作。 Keepalived将VIP分配给指定的界面,日志显示该行

 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE 

我能够重现你的情况的唯一方法是提供一个空的configuration文件(在不存在的文件上的testing失败,因为启动脚本检查)。

您需要validation在启动脚本/etc/init.d/keepalived指定的命名configuration文件。