Keepalived - samuel-richardson/Sam-Tech-Journal GitHub Wiki

Keepalived

sudo apt install keepalived
sudo vim /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {
    script "killall -0 haproxy"   # Check if HAProxy process is running
    interval 2                    # Check every 2 seconds
    weight 2                      # Weight to influence master election
}

vrrp_instance VI_1 {
    state MASTER
    interface ens160                 # Network interface to bind to
    virtual_router_id 30
    priority 101                  # Higher priority on the primary server
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass Gf77e3NMYzDT     # Set a strong authentication password
    }
    virtual_ipaddress {
        10.0.6.10              # Your VIP address
    }
    track_script {
        chk_haproxy
    }
}

For second node change MASTER to BACKUP and id to 100.
sudo systemctl start keepalived
Use ip a to see if the ip is assigned to the correct interface on MASTER node. Turn off and check backup for the same. Curl both pages to test.