I have recently tried to load balance my application using HAProxy and was able to do it successfully. Later, I have come across a concept called Floating IP, which can be u
Assumptions:
Steps:
sudo ufw allow in from 198.51.100.20 to 224.0.0.18 # on 198.51.100.10sudo ufw allow in from 198.51.100.10 to 224.0.0.18 # on 198.51.100.20/etc/sysctl.confnet.ipv4.ip_nonlocal_bind=1sudo sysctl -p # reload config changesudo apt-get install keepalived/etc/keepalived/keepalived.conf/etc/haproxy/haproxy.cfgbind 198.51.100.50:80sudo service haproxy restartsudo ip addr show | grep eth0 # should list the shared IPsudo ip addr show | grep eth0 # should NOT list the shared IPsudo service haproxy stopsudo ip addr show | grep eth0 # should NOT list the shared IPsudo ip addr show | grep eth0 # should list the shared IPsudo service haproxy startsudo ip addr show | grep eth0 # should list the shared IPsudo ip addr show | grep eth0 # should NOT list the shared IP vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of priority if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on primary, 100 on secondary
virtual_ipaddress {
198.51.100.50
}
track_script {
chk_haproxy
}
}