keepalived和两个活动服务器

时间:2015-07-19 17:29:51

标签: linux load-balancing

我正在尝试使用 keepalived 配置两个活动负载均衡器服务器。

它与标准配置略有不同,我们有两台服务器和一台虚拟IP。

我想要的只是当 loadbalancer_1 关闭时, loadbalancer_2 会占用他的IP地址,反之亦然。

loadbalancer_1 IP地址:xx.237.193.132 / 27 loadbalancer_2 IP地址:xx.237.193.134 / 27

当我第一次启动 loadbalancer_1 时,它还需要 loadbalancer_2 IP地址,因为在此特定时刻 keepalived 不是尚未开始 loadbalancer_2 。 但是,当我开始 loadbalancer_2 时,仍有 loadbalancer_1 上的IP地址。所以, loadbalancer_1 。是两个IP地址的主人。

当我首先启动 loadbalancer_2 时会发生同样的情况,因此先前启动的服务器将成为两个IP地址的主服务器。

登录 loadbalancer_1

Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering gratuitous ARP shared channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Configuration is using : 71869 Bytes
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering BACKUP STATE
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Configuration is using : 12587 Bytes
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:01 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Transition to MASTER STATE
Jul 19 19:18:02 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Entering MASTER STATE
Jul 19 19:18:04 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:05 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE

登录 loadbalancer_2

Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering gratuitous ARP shared channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 022 Keepalived_vrrp[468]: Configuration is using : 71869 Bytes
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:08 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_1) Entering BACKUP STATE
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Configuration is using : 12587 Bytes
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:09 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:10 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE
Jul 19 19:18:11 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Received lower prio advert, forcing new election

配置 loadbalancer_1

global_defs {
    router_id loadbalancer_1
    lvs_id loadbalancer_1
}
vrrp_instance web_loadbalancer_1 {
    state MASTER
    interface eth0
    virtual_router_id 10
    priority 110
    advert_int 1
    virtual_ipaddress {
        xx.237.193.132/27 dev eth0
    }
    authentication {
        auth_type PASS
        auth_pass 45f3fgv1
    }
}
vrrp_instance web_loadbalancer_2 {
    state BACKUP
    interface eth0
    virtual_router_id 20
    priority 200
    smtp_alert
    advert_int 1
    virtual_ipaddress {
        xx.237.193.134/27 dev eth0
    }
    authentication {
        auth_type PASS
        auth_pass 45f3fgv2
    }
}

配置 loadbalancer_2

global_defs {
    router_id loadbalancer_2
    lvs_id loadbalancer_2
}
vrrp_instance web_loadbalancer_1 {
    state BACKUP
    interface eth0
    virtual_router_id 10
    priority 100
    advert_int 1
    virtual_ipaddress {
        xx.237.193.132/27 dev eth0
    }
    authentication {
        auth_type PASS
        auth_pass 45f3fgv1
    }
}
vrrp_instance web_loadbalancer_2 {
    state MASTER
    interface eth0
    virtual_router_id 20
    priority 210
    advert_int 1
    virtual_ipaddress {
        xx.237.193.134/27 dev eth0
    }
    authentication {
        auth_type PASS
        auth_pass 45f3fgv2
    }
}

2 个答案:

答案 0 :(得分:0)

我建议在两个MASTER部分添加 preempt_delay 10

查看server2的最后一个日志条目

  

Jul 19 19:18:11 002 Keepalived_vrrp [468]:VRRP_Instance(web_loadbalancer_2)收到较低的prio广告,迫使新选举

似乎它只是意识到它可以接管作为VRRP主机。如果没有发生这种情况,可能稍后会在日志中查看。

第一台服务器启动是正常的,因为没有其他服务器而假设为master,然后当第二台服务器变为活动状态时,vrrp重选应该选择配置了最高优先级的服务器。

答案 1 :(得分:0)

问题由我解决了。 最初在 eth0 接口( lb_1 lb_2 )上有一个主要IP地址,我已在中使用它们keepalived 配置。

On loadbalancer_1 : xx.237.193.132/27
On loadbalancer_2 : xx.237.193.134/27

然后,我刚刚编辑了 keepalived 配置,并在同一子网中替换了其他IP地址:

For loadbalancer_1 : xx.237.193.150/27
For loadbalancer_2 : xx.237.193.151/27

因此,当系统启动时, eth0 将使用旧的主IP地址进行初始化,但 keepalived 将使用来自同一子网的其他虚拟IP地址。 我不知道为什么第一个解决方案不起作用,我还没有在任何地方找到解释或要求。

是否有人可以解释问题是什么,为什么我不能使用在 keepalived 配置中在操作系统启动时分配给接口的主IP地址?