How To Set Up A Loadbalanced High-Availability Apache Cluster Based On Ubuntu 8.04 LTS

Please note that my main reference and source is Falko's article here just modified for Ubuntu 8.04 LTS. Also some parts were taken from Falko's article "The Perfect Server - Ubuntu 8.04 LTS" here.

Version 1.0
Author: Mohamed Ghaleb <Mohamed_Ghaleb [at] msn [dot] com>  (English and German only please)

This tutorial shows how to set up a two-node Apache web server cluster that provides high-availability. In front of the Apache cluster we create a load balancer that splits up incoming requests between the two Apache nodes. Because we do not want the load balancer to become another "Single Point Of Failure", we must provide high-availability for the load balancer, too. Therefore our load balancer will in fact consist out of two load balancer nodes that monitor each other using heartbeat, and if one load balancer fails, the other takes over silently.

The advantage of using a load balancer compared to using round robin DNS is that it takes care of the load on the web server nodes and tries to direct requests to the node with less load, and it also takes care of connections/sessions. Many web applications (e.g. forum software, shopping carts, etc.) make use of sessions, and if you are in a session on Apache node 1, you would lose that session if suddenly node 2 served your requests. In addition to that, if one of the Apache nodes goes down, the load balancer realizes that and directs all incoming requests to the remaining node which would not be possible with round robin DNS.

For this setup, we need four nodes (two Apache nodes and two load balancer nodes) and five IP addresses: one for each node and one virtual IP address that will be shared by the load balancer nodes and used for incoming HTTP requests.

I will use the following setup here:

  • Apache node 1: (webserver1) - IP address:; Apache document root: /var/www
  • Apache node 2: (webserver2) - IP address:; Apache document root: /var/www
  • Load Balancer node 1: (loadb1) - IP address:
  • Load Balancer node 2: (loadb2) - IP address:
  • Virtual IP Address: (used for incoming requests)

Have a look at the drawing on to understand how this setup looks like.

In this tutorial I will use Ubuntu 8.04 LTS for all four nodes, just install basic Ubuntu 8.04 LTS on all four nodes.

I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

I also recommend you to have a DNS server in place.

Step 1 to 6 should be done on all four servers.


1 Enable The root Account


sudo passwd root

and give root a password. Afterwards we become root by running



2 Install The SSH Server

If you did not install the OpenSSH server during the system installation, you can do it now:

apt-get install ssh openssh-server

From now on you can use an SSH client such as PuTTY and connect from your workstation to your Ubuntu 8.04 LTS server and follow the remaining steps from this tutorial.


3 Install vim-full

I'll use vi as my text editor in this tutorial. The default vi program has some strange behavior on Ubuntu and Debian; to fix this, we install vim-full:

apt-get install vim-full

(You don't have to do this if you use a different text editor such as joe or nano.)


4 Configure The Network

Because the Ubuntu installer has configured our system to get its network settings via DHCP, we have to change that now because a server should have a static IP address. Edit /etc/network/interfaces and adjust it to your needs (in this example setup I will use the IP address

vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static

Please make sure your network configuration are set correctly, feel free to change that based on your network configuration.

Then restart your network:

/etc/init.d/networking restart

Then edit /etc/hosts. Make it look like this:

vi /etc/hosts       localhost.localdomain   localhost loadb1

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Now run

echo > /etc/hostname
/etc/init.d/ start

Afterwards, run

hostname -f

Both should show now.

If you have a DNS server in place (recommended) make sure the 4 servers configured to use it, if you don't have a DNS click here

vi /etc/resolv.conf

search tm.local
Share this page:

Suggested articles

2 Comment(s)

Add comment


From: chris

Please help me getting this error

Error [6900] reading file /etc/ha.d/ at line 8: Unknown command  real=****** gate

From: Andrei


Thank you for your tutorial.

Is this possible with only 2 webservers? Without lb servers.