Archive

Posts Tagged ‘Clusters’

HTTP Load Balancing

August 2, 2008 Leave a comment

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: 10.50.51.52
cluster member A: 10.51.51.10
cluster member B: 10.51.51.20
cluster member C: 10.51.51.30
cluster member D: 10.51.51.40

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

$ ipvsadm -A -t 10.50.51.52:http -s rr -p5200
$ ipvsadm -a -t 10.50.51.52:http -r 10.51.51.10:http -m
$ ipvsadm -a -t 10.50.51.52:http -r 10.51.51.20:http -m
$ ipvsadm -a -t 10.50.51.52:http -r 10.51.51.30:http -m
$ ipvsadm -a -t 10.50.51.52:http -r 10.51.51.40:http -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 10.50.51.52:http

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

ipvsadm -D -t 10.50.51.52:http

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

Categories: Clusters Tags: