front-end Apache cloud load balancer

The next step in our fully redundant, high-availability LAMP stack is adding load balancing. This means setting up a new server in front of our two web servers. This load balancing server will monitor both web servers, and switch traffic between them intelligently. Load balancing setup on ElasticHosts has special requirements, because our system does not allow floating Mac addresses. This makes using VRRP (Virtual Router Redundancy Protocol), which is the basis for many load balancers, problematic. We use the Apache module mod_proxy_balancer. This turns Apache into a load balancer, retrieving requested pages from two or more backend web servers and delivering them to the user’s computer. If required, mod_proxy_balancer can keep track of sessions, so a single user always deals with the same backend webserver. The steps are as follows:

  • Step 1: Set up a new server
  • Step 2: Install Apache and mod_proxy_balancer
  • Step 3: Configure mod_proxy_balancer

 

Step 1: Set up a new server

First we create a fifth Ubuntu 10.04 server, which will be our load balancer. We’ll call this new server herring. Then set herring up to share a private VLAN with our web and database servers, as described in our How To Set Up a VLAN tutorial. In this tutorial, we’ve given herring the IP address 10.0.0.5. In addition, we will need an external static IP: add this as described in our Add a Static IP Address tutorial. In this tutorial, we’ve given herring the IP address 46.20.121.121. Note: In the next tutorial, you’ll be setting up a second load balancer with another static IP address. These should be within the same class C range, so you may find it helpful to set up two static IP addresses now, and check that they are within the same A.B.C.* range. Just to recap, we currently have five servers in total:

  • puffin: Web server 1, private IP address 10.0.0.1.
  • albatross: Web server 2, private IP address 10.0.0.4.
  • beagle: Database server 1, private IP address 10.0.0.2.
  • crocodile: Database server 2, private IP address 10.0.0.3.
  • herring: Load balancer 1, private IP address 10.0.0.5 and static IP address 46.20.121.121. In a real system, at this point you might want to configure your DNS servers to give each of your servers with a subdomain (e.g. db1.yourdomain.com, web1.yourdomain.com, loadb1.yourdomain.com etc) in order to check their status easily.

 

Step 2: Install Apache and mod_proxy_balancer

First, on our new load balancing server, we need to install Apache and enable the proxy modules:

$ apt-get update
$ apt-get install apache2
$ a2enmod proxy
$ a2enmod proxy_balancer
$ a2enmod proxy_http
$ /etc/init.d/apache2 force-reload

 

Step 3: Configure mod_proxy_balancer

Now, we need to configure our cluster, in a new file in conf.d:

$ vi /etc/apache2/conf.d/proxy-balancer
<Proxy balancer://mycluster>
BalancerMember http://10.0.0.1
BalancerMember http://10.0.0.4
</Proxy>
ProxyPass / balancer://mycluster

Then we need to configure our proxy to allow access from all hosts:

$ vi /etc/apache2/mods-enabled/proxy.conf

Change the line “Deny from all” in this file to “Allow from all”. Then restart Apache:

$ /etc/init.d/apache2 restart

– See more at: http://www.elastichosts.com/support/tutorials/add-a-front-end-apache-cloud-load-balancer/#sthash.9AsJ8nRx.dpuf

Advertisements
Leave a comment

Leave your opinion

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: