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.
How to create Floating IP and use it to configure HAProxy
13k views Asked by mahu At
2
There are 2 answers
0
On
The answer from Matt Rice is excellent, but be aware that if you're running SELinux enforcing on Red Hat EL 7, you'll need
sudo setsebool haproxy_connect_any on
...or haproxy will fail to start on the system that does not currently have the virtual ipaddress, with a complaint that it can't bind.
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/etc/keepalived/keepalived.conf