Home > Clusters > HTTP Load Balancing

HTTP Load Balancing

The following information is issued as a simple and basic tutorial of how to implement a load balancing system.

Load balancing is a technique to spread work between two or more computers, network links, CPUs, hard drives, or other resources, in order to get optimal resource utilization, throughput, or response time. – Wikipedia.

With load balancing we can get the power of a high availability cluster using cheap machines. Also it is easier to scale the systems horizontally and just add more servers as our needs increase.

Of course there exists hardware solutions specifically designed to take care of load balancing. Citrix and F5 being the most popular among datacenters but this are expensive and mostly targeted at the enterprise market, not the home user.

Fortunately Linux provides us with a powerful tool to develop load balancing: IPVS (Internet Protocol Virtual Server).

The procedure for the set up is fairly easy. First you need to define the machine that us gonna act as the main server and “father” of the cluster. Ideally this machine has to be one with post processing capabilities.

By default Linux comes with IPVS pre-installed, but in the case you don’t have it, just yum or apt-get it.

In this example we are going to set up a cluster with 4 machines:

Main cluster server:
cluster member A:
cluster member B:
cluster member C:
cluster member D:

Open a terminal on the machine that has installed IPVS ( and create the virtual host and assing the child machines as follows:

$ ipvsadm -A -t -s rr -p5200
$ ipvsadm -a -t -r -m
$ ipvsadm -a -t -r -m
$ ipvsadm -a -t -r -m
$ ipvsadm -a -t -r -m

A little explanation of the used parameters:

t – Use TCP protocol pointing to the IP address of the server on the specified port.
s – Use allocation of TCP and UDP connections.
rr – use rr-type balancing Robin Robin (distributes the burden equally in all servers).
p – Specify the persistence of TCP connections. If empty, 300 is assigned by default.
A – Registers a new virtual service. This is the main server.

Thats it, we have a fully functional mini cluster on port 80 (http).

But what if someday, one of your machines burns out. Don’t let the panic attacks you.

To delete a “child” machine just issue your godlike root powers and type the following command:

$ ipvsadm -d -t

Or if you want to completely remove the whole clustering, then type the following command:

ipvsadm -D -t

The d deletes the specified server, and D deletes the cluster and all related servers it may have assigned.

Categories: Clusters Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: