How to make keepalived respond on failover on HAProxy?

1.6k views Asked by At

I am using HAProxy as load balancer for my application and to make it highly available I am using keepalive service and floating ip address concept. But whenever my primary load balancer server gets down, by removing it from network or turning it off, my all services go down instead of making secondary load balancer server available. My keepalived.conf for master server is,

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
        }
}

For backup server it is like,

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
        }
}

The virtual IP address is assigned and working when both load balancers are up. But whenever machine goes down, my service also goes down. I am using CentOS7, Please help.

1

There are 1 answers

0
PankajS On

Use this,

global_defs {

router_id ovp_vrrp

} vrrp_script haproxy_check { script "killall -0 haproxy" interval 2 weight 2 }

vrrp_instance OCP_EXT { interface ens192

virtual_router_id 51

priority 100 state MASTER virtual_ipaddress { 10.19.114.231 dev ens192

} track_script { haproxy_check } authentication { auth_type PASS auth_pass 1cee4b6e-2cdc-48bf-83b2-01a96d1593e4 } }

more info: read here, https://www.openshift.com/blog/haproxy-highly-available-keepalived