Installing Apache Load Balancer

Published by burgerboydaddy on Sun, 02/10/2013 - 23:02

As first step to get configuration done, we need to have Apache Load Balancer installed and configured to talk with web farm.

Apache web server ships a load balancer module called mod_proxy_balancer (since version 2.2). All you need to do is to enable this module and the modules mod_proxy and mod_proxy_http. Please note that without mod_proxy_http, balancer just won't work.

LoadModule proxy_module mod_proxy.so
LoadModule proxy_http_module mod_proxy_http.so
LoadModule proxy_balancer_module mod_proxy_balancer.so

Because mod_proxy makes Apache become an (open) proxy server, and open proxy servers are dangerous both to your network and to the Internet at large, I completely disable this feature: 
ProxyRequests Off

<Proxy>
Order deny,allow
Deny from all

</Proxy>


The load balancer doesn't need this feature at all.
Now assuming that all web servers has same code, next step is to configure load balancer. It is done adding to the top of default file (located inside /etc/apache2/sites-available) next code:

<Location /balancer-manager>
SetHandler balancer-manager


Order Deny,Allow
Deny from all
Allow from all

</Location>
<Proxy balancer://mycluster>

# cluster member 1
BalancerMember http://server1.dev:80 route=lb1


# cluster memeber 2
BalancerMember http://server2.dev:80 route=lb2
</Proxy>
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/ lbmethod=byrequests stickysession=BALANCEID
ProxyPassReverse / http://server1.dev
ProxyPassReverse / http://server2.dev

The <Proxy>...</Proxy> container defines which backend servers belong to my balancer. I chose the name mycluster for this server group, but you are free to choose any name you want. 

And the ProxyPass directive instructs the Apache to forward all incoming requests to this group of backend servers. Also since I want client to be forwarder only to the already selected server, I added stickysession directive to the configuration.

There is no need to change anything on web servers site. Drupal will normally work. Please note site this is installed on my test machine I added to machine hosts file IP addresses of server1.dev and server2.dev. They have static IP assigned by my VirtualBox configuration.

More details about configuring Apache mod_proxy_balancer can be found here:


Add new comment