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 used along with keepalived to make the load balancer highly available. I wasn't able to understand how to create the floating Ip though. How can I create Floating IP and use it to configure HAProxy? Thanks.
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.conf
net.ipv4.ip_nonlocal_bind=1
sudo sysctl -p
# reload config changesudo apt-get install keepalived
/etc/keepalived/keepalived.conf
/etc/haproxy/haproxy.cfg
bind 198.51.100.50:80
sudo service haproxy restart
sudo ip addr show | grep eth0
# should list the shared IPsudo ip addr show | grep eth0
# should NOT list the shared IPsudo service haproxy stop
sudo ip addr show | grep eth0
# should NOT list the shared IPsudo ip addr show | grep eth0
# should list the shared IPsudo service haproxy start
sudo 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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With