keepalived没有绑定VIP

keepalived没有绑定VIP

我正在尝试让 keepalived 在 2 个 debian jessie VM 之间运行。

我已经定义主机将 VIP 地址绑定到 172.128.28.6,如下所示:

global_defs {
        lvs_id tom_lvs
}

vrrp_instace tom_lvs {
        state MASTER
        interface eth1
    virtual_router_id 1
    priority 100
        authentication {
                auth_type PASS
                auth_pass 1234
        }

    advert_int 1
    virtual_ipaddress {
        172.28.128.6
    }

        virtual_server 172.28.128.6 3000 {
                delay_loop 10
                lb_algo wlc
                lb_kind DR
                protocol TCP
                persistence_timeout 1800
                sorry_server 172.28.128.3 3000
                real_server 172.28.128.4 3000 {
                        weight 1
                        HTTP_GET {
                                url {
                                        path /index.html
                                }
                        }
                }
        }
}

然而,当我运行时,ip addr我没有看到连接到 eth3 的第二个 IP:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:f6:86:bf brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fef6:86bf/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:05:a5:a1 brd ff:ff:ff:ff:ff:ff
    inet 172.28.128.4/24 brd 172.28.128.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe05:a5a1/64 scope link 
       valid_lft forever preferred_lft forever

我显然在这里遗漏了一些东西,但我已经花了两天时间却仍然没有找到它。

如果完全相关的话,这些机器正在使用 vagrant 和 virtual-box 运行,两者都定义为从 dhcp 获取地址,它们的 IP 是 /24 子网上的 172.128.28.4 和 172.128.28.3。

下面是输出grep Keepalived /var/log/messages

Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Registering Kernel netlink reflector
Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Registering Kernel netlink command channel
Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Registering gratuitous ARP shared channel
Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Opening file '/etc/keepalived/keepalived.conf'.
Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Configuration is using : 58175 Bytes
Feb 13 11:39:51 jessie Keepalived_vrrp[1890]: Using LinkWatch kernel netlink reflector...
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Registering Kernel netlink reflector
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Registering Kernel netlink command channel
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Opening file '/etc/keepalived/keepalived.conf'.
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Configuration is using : 12031 Bytes
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Using LinkWatch kernel netlink reflector...
Feb 13 11:39:51 jessie Keepalived_healthcheckers[1889]: Activating healthchecker for service [172.28.128.4]:3000

答案1

如果您复制/粘贴了配置文件,我注意到您的配置中有一个拼写错误。除此之外,一切似乎都很好。

您需要修复 VRRP 实例定义以使其读取:

vrrp_instance tom_lvs {

您漏掉了关键字n中的第二个字母vrrp_instance。修复配置并重新启动 keepalived 后,您应该会看到类似以下内容的日志行:

Keepalived_vrrp[15607]: VRRP_Instance(tom_lvs) Transition to MASTER STATE
Keepalived_vrrp[15607]: VRRP_Instance(tom_lvs) Entering MASTER STATE

相关内容