Failover and Load Balancing using HAProxy
HAProxy is open source proxy that can be used to enable high availability and load balancing for web applications. It was designed especially for high load projects so it is very fast and predictable, HAProxy is based on single-process model.
In this post I’ll describe sample setup of HAProxy: users’ requests are load balanced between two web servers Web1 and Web1, if one of them goes down then all the request are processed by alive server, once dead servers recovers load balancing enables again. See topology to the right.
HAProxy is included into repositories for major Linux distributions, so if you’re using Centos, Redhat or Fedora type the following command:
yum install haproxy
If you’re Ubuntu, Debian or Linux Mint user use this one instead:
apt-get install haproxy
As soon as HAProxy is installed it’s time to edit its configuration file, usually it’s placed in /etc/haproxy/haproxy.cfg. Official documentation for HAProxy 1.4 (stable) is here.
Here is configuration file to implement setup shown at the diagram and described above:
log 127.0.0.1 daemon