Configuring one or more Ubuntu servers to utilize load balancing with the mod_proxy_balancer module is a piece of cake. I’ve setup two freshly imaged virtual machines with static IP addresses running Ubuntu 12.10 for this tutorial, and will be walking you through the process of configuring load balancing with Apache. This is an easy and inexpensive way to scale your existing web infrastructure out horizontally, using little more than software to accomplish higher levels of performance and redundancy. There are highly specialized hardware solutions out there that can achieve this, but they tend to be expensive and difficult to implement. Here’s how you setup load balanced web servers on Ubuntu 12.10 :
I’ve already taken the liberty of installing Apache ahead of time, but if you are curious on how to do that you can check this article out here or here. Before we start there are a couple of concepts that we need to clear up to have a better understanding of load balancing with the mod_proxy_balancer module. Though we are starting with two servers, we could theoretically have any number of servers in this distributed pool – but the key is that only one of the servers will serve as the load balancer. This is the server that ensures the high availability and provides the load balancing. It helps if you think of it as one server taking all of the web requests, then daisy chaining them out to the other servers in whatever order you specify in the config files. Let’s say you have 2 servers, and 1 has 3X the resources of the other, then you would likely want to split the load accordingly by giving the more capable machine every 3 out of 4 GET/WGET requests.
That being said, let’s jump into it. Make sure you have two freshly imaged servers that are fully up to date.
Now enable the proxy, proxy_balancer, and proxy_http apache modules and restart the apache service. Do this on the designated load balancer server only.
Next up we’ll create the /etc/apache2/conf.d/proxy-balancer file and start designating our member servers.
So we’ve designated two servers to distribute web requests, LB-APACHE1 and LB-APACHE2. Next we need to configure the proxy we just created to adjust the host access directive.
Notice that we didn’t uncomment the #Allow from .example.com line – for the purposes of this tutorial, we don’t need this. This would be a good way to serve internal get requests in an intranet though.
Restart the apache service once more :
And that’s pretty much it – if you want to see the load balancing in action, you can run a simple netstat on your computer requesting web services on the load balanced cluster, and you would be able to see the proxy handing off requests.