0

我正在使用 HAProxy 作为我的应用程序的负载均衡器,并使其具有高可用性,我正在使用 keepalive 服务和浮动 IP 地址概念。但是,每当我的主负载均衡器服务器关闭时,通过将其从网络中删除或关闭它,我的所有服务都会关闭,而不是使辅助负载均衡器服务器可用。我的主服务器的 keepalived.conf 是,

global_defs
{
        # Keepalived process identifier
        lvs_id haproxy_DH
}
# Script used to check if HAProxy is running
vrrp_script check_haproxy
{
        script "pidof haproxy"
        interval 2
        weight 2
}
# Virtual interface
vrrp_instance VI_01
{
        state MASTER
        interface eno16777984           #here eth0 is the name of network interface
        virtual_router_id 51
        priority 101
        # The virtual ip address shared between the two loadbalancers
        virtual_ipaddress {
                172.16.231.162
        }
        track_script {
                check_haproxy
        }
}

对于备份服务器,就像,

global_defs
{
        # Keepalived process identifier
        lvs_id haproxy_DH_passive
}
# Script used to check if HAProxy is running
vrrp_script check_haproxy
{
        script "pidof haproxy"
        interval 2
        weight 2
}
# Virtual interface
vrrp_instance VI_01
{
        state BACKUP
        interface eno16777984           #here eth0 is the name of network interface
        virtual_router_id 51
        priority 100
        # The virtual ip address shared between the two loadbalancers
        virtual_ipaddress {
                172.16.231.162
        }
        track_script {
                check_haproxy
        }
}

当两个负载平衡器都启动时,虚拟 IP 地址被分配并工作。但是每当机器出现故障时,我的服务也会下降。我正在使用 CentOS7,请帮助。

4

1 回答 1

0

用这个,

全局定义{

router_id ovp_vrrp

} vrrp_script haproxy_check { 脚本“killall -0 haproxy” 间隔 2 权重 2 }

vrrp_instance OCP_EXT { 接口 ens192

virtual_router_id 51

优先级 100 状态 MASTER virtual_ipaddress { 10.19.114.231 dev ens192

} track_script { haproxy_check } 身份验证 { auth_type PASS auth_pass 1cee4b6e-2cdc-48bf-83b2-01a96d1593e4 } }

更多信息:在这里阅读,https ://www.openshift.com/blog/haproxy-highly-available-keepalived

于 2021-07-18T19:08:36.970 回答