Comments on Setting Up A High-Availability Load Balancer With HAProxy/Keepalived On Debian Lenny
Setting Up A High-Availability Load Balancer (With Failover And Session Support) With HAProxy/Keepalived On Debian Lenny This article explains how to set up a two-node load balancer in an active/passive configuration with HAProxy and keepalived on Debian Lenny. The load balancer sits between the user and two (or more) backend Apache web servers that hold the same content. Not only does the load balancer distribute the requests to the two backend Apache servers, it also checks the health of the backend servers. If one of them is down, all requests will automatically be redirected to the remaining backend server. In addition to that, the two load balancer nodes monitor each other using keepalived, and if the master fails, the slave becomes the master, which means the users will not notice any disruption of the service. HAProxy is session-aware, which means you can use it with any web application that makes use of sessions (such as forums, shopping carts, etc.).
9 Comment(s)
Comments
When haproxy starts, it attempts to bind to the address in the listen statement ( listen webfarm 192.168.0.99:80). But this address doesn't exist on lb2 until lb1 fails over to lb2, so haproxy fails to run initially.
I got around this by adding the following three lines to the keepalived configuration file (on both lb1 and lb2), right underneath the virtual_ipaddress{} line:
notify_master /opt/keepalived/bin/notify_master.sh
notify_backup /opt/keepalived/bin/notify_backup.sh
notify_fault /opt/keepalived/bin/notify_backup.sh
notify_master.sh simply starts haproxy. notify_backup.sh simply does a killall -TERM haproxy. I couldn't really figure out the difference between a LB being a "backup" vs a LB "fail", so in both cases, I just killall haproxy.
So when a LB1 & LB2 start up, LB1 is the master, so it starts haproxy. LB2 is the backup, so it does a killall haproxy (which doesn't do anything since it never started, but that's ok.) If LB1 fails for whatever reason (pull the network cord, system crashes hard, etc) then LB2 starts haproxy. Depending on how hard LB1 crashed, it may have had time to switch take down haproxy or not (probably not.) When LB1 comes back up and becomes the master again, it runs haproxy, and LB2 is demoted back to backup status and does a killall haproxy.
I am not doign practical right now so just going through the article. It might be a stupid question but just wondering how should I be configuring DNS server or A records?
Hello,
First, Thank you for this tutorial.
I have implemented the same architecture using 2 RHEL7 with Keepalived and Haproxy installed on each server. When testing keepalived service crash; the failover to slave server works fine, the VIP is assigned the slave server which is then declared as newly primary server.That is not the case when crashing Haproxy service. Failover procedure is not triggered and users requests are still routed to the primary server, which is obviously not responding.I think vrrp_script is not working correctly on redhat 7 as killall command does not exist in this version. Is there any other alternatives i can use in this case ?
"yum install psmisc" will provide you killall command on RHEL7.
Hi!
First of all thanks for this guide!
I have a question regarding this conf. I've followed it but I cannot access my backend servers through the virtual IP (in your case 192.168.0.99) of haproxy/keepalived as I get a connection refused error although I can access to my backend servers through their IP (in your case 192.168.0.102). I dont have any iptables rule set.
I am missing something?
Thanks
Yes, i have same problem. Did you solve it?
If yes, can you help me, please?
thanks
Thanks a lot this is really helpful articles.
This will never work. haproxy will try to bind to 192.168.0.99 which is virtual IP set by keepalilved. On the server that is not active keepalived it will fail to start (for instance lb2). If for some reason lb1 crashes lb2 will neve become active since priority will always be lower then lb1
Hello All,
We have two redis web servers behind haproxy, but i need all traffic should go to Redis-web1 only and haproxy should divert traffic to Redis-web2 only when Redis-web1 is down ?
Is this possible ? Please suggest
ThanksSushil R