如何配置 keepalived - 无法设置 VIP

如何配置 keepalived - 无法设置 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 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...

答案1

我已经在我的计算机上测试了您的配置,并且它有效。Keepalived 将 VIP 分配给指定的接口,日志显示了以下行

Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE

我能够重现您的情况的唯一方法是提供一个空的配置文件(不存在的文件的测试失败,因为启动脚本会检查它)。

您需要验证启动脚本中指定的配置文件/etc/init.d/keepalived

相关内容