Keepalived vrrp_script不进行故障转移

时间:2015-11-30 07:46:07

标签: centos haproxy failover

我有2个节点,包括keepalived和haproxy服务(CentOS7)。 如果我关闭一个节点都工作正常。但是如果haproxy关闭,我想要故障转移VIPS。

这是第一个节点配置:

  vrrp_script ha_check {
script "/etc/keepalived/haproxy_check"
interval 2
weight 21
}

vrrp_instance VI_1 {
    state MASTER
        interface eno16777984
        virtual_router_id 151
        priority 101
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 11111
                        }
        virtual_ipaddress {
                10.0.100.233
                            }
        smtp_alert
track_script {
ha_check
}
}

第二节点:

vrrp_script ha_check {
script "/etc/keepalived/haproxy_check"
interval 2
fall 2
rise 2
timeout 1
weight 2
}

vrrp_instance VI_1 {
    state BACKUP
        interface eno16777984
        virtual_router_id 151
        priority 100
        advert_int 1
        authentication {
        auth_type PASS
        auth_pass 11111
                        }
        virtual_ipaddress {
                10.0.100.233
                            }
        smtp_alert
track_script {
ha_check
}
}

cat / etc / keepalived / haproxy_check

systemctl status haproxy | grep "inactive"

当我停止haproxy时,它仍然无法将VIP故障转移到下一个 主机。

[root@cks-hatest1 keepalived]# tail /var/log/messages
Nov 30 10:35:24 cks-hatest1 Keepalived_vrrp[5891]: VRRP_Script(ha_check) failed
Nov 30 10:35:33 cks-hatest1 systemd: Started HAProxy Load Balancer.
Nov 30 10:35:45 cks-hatest1 systemd: Stopping HAProxy Load Balancer...
Nov 30 10:35:45 cks-hatest1 systemd: Stopped HAProxy Load Balancer.
Nov 30 10:35:46 cks-hatest1 Keepalived_vrrp[5891]: VRRP_Script(ha_check) succeeded

我做错了什么?提前谢谢!

2 个答案:

答案 0 :(得分:0)

在您的脚本中,您正在检查是否

systemctl status haproxy

包含关键字"无效"。这是您手动停止haproxy服务时获得的价值吗?

只要haproxy服务停止,您的日志就会再次启动它。你能核实一下吗?

另外,请尝试将脚本替换为

script "killall -0 haproxy"

答案 1 :(得分:0)

这很容易。试试这个例子:

vrrp_script check_haproxy {
    script "pidof haproxy"
    interval 2
    weight 2
}

在配置结束时,您还应添加以下部分:

track_script {
    check_haproxy
}