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

Want to support HowtoForge? Become a subscriber!
 
Submitted by msghaleb (Contact Author) (Forums) on Tue, 2008-06-10 18:09. :: Ubuntu | Apache | High-Availability

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)
Last edited 06/03/2008

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.tm.local (webserver1) - IP address: 192.168.0.103; Apache document root: /var/www
  • Apache node 2: webserver2.tm.local (webserver2) - IP address: 192.168.0.104; Apache document root: /var/www
  • Load Balancer node 1: loadb1.tm.local (loadb1) - IP address: 192.168.0.101
  • Load Balancer node 2: loadb2.tm.local (loadb2) - IP address: 192.168.0.102
  • Virtual IP Address: 192.168.0.105 (used for incoming requests)

Have a look at the drawing on http://www.linuxvirtualserver.org/docs/ha/ultramonkey.html 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

Run

sudo passwd root

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

su

 

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 192.168.0.101):

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
address 192.168.0.101
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

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

127.0.0.1       localhost.localdomain   localhost
192.168.0.101 loadb1.tm.local 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 loadb1.tm.local > /etc/hostname
/etc/init.d/hostname.sh start

Afterwards, run

hostname
hostname -f

Both should show loadb1.tm.local 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
nameserver 192.168.0.100

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.