Ubuntu 14.04 – Web Server Load-Balancing with HAProxy

HAProxy (High Availability Proxy) is an open-source load-balancer which can load balance any TCP service. HAProxy is a free, very fast and reliable solution that offers load-balancing, high-availability, and proxying for TCP and HTTP-based applications. It is particularly well suited for very high traffic web sites and powers many of the world’s most visited ones.

Since it’s existence, it has become the de-facto standard open-source load-balancer. Although it does not advertise itself, but is used widely

Installing HAProxy (Ubuntu 14.04)

sudo apt-get install haproxy

Check the version by:

haproxy -v

We need to enable HAProxy to be started by the init script /etc/default/haproxy. Set ENABLED option to 1 as:

ENABLED=1

To verify if this change is done properly, execute the init script of HAProxy without any parameters. You should see the following:

sudo service haproxy reload | restart | start | status | stop

HAProxy is now installed. Let us now create a setup in which we have 2(two) Apache Web Server instances and 1(one) HAProxy instance. Below is the setup information:

We will be using three systems, spawned virtually through VirtualBox:

Instance 1 – Load Balancer
Hostname: haproxy
OS: Ubuntu
Private IP: 192.168.205.15

Instance 2 – Web Server 1
Hostname: webser01
OS: Ubuntu with LAMP
Private IP: 192.168.205.16

Instance 2 – Web Server 2
Hostname: webserver02
OS: Ubuntu with LAMP
Private IP: 192.168.205.17

Here is the diagram of how the setup looks like:

Read the whole article from source: howtoforge.com