Share

In this guide we will see how to install and configure Apache load balancer in debian based distro Ubuntu 14.04. This tutorial was performed on Ubuntu 14.04, but it should also run on other versions of Ubuntu and other debian based distros.

 

Prerequisites

  • Three System with Debian / Ubuntu OS.
  • Apache HTTP Server installed on above systems.
  • System 1 IP: 173.34.34.27
  • System 2 IP: 173.34.34.26
  • Load Balancer IP: 173.34.34.21

Steps for configuring Apache Load Balancer In Ubuntu

Install Apache web server on all three systems using following command.

# apt-get install -y apache2

Start the Apache service using below command.

 # service apache2 restart

Now log into System 1 and System 2 and remove default index.html file and create a new index.html file on both the systems and put different content in both of the files to distinguish each web server.

Now login to Load-Balancer System and goto the directory “/etc/apache2/sites-available” and look for the the file 000-default.conf.

# cd /etc/apache2/sites-available/

Take the backup of this file as 000-default.conf.bkp

 # cp 000-default.conf 000-default.conf.bkp

Now edit the file 000-default.conf using any editor.

 # vi 000-default.conf

Enter the following content in the file.

<VirtualHost *:80> 
# The ServerName directive sets the request scheme, hostname and port that 
# the server uses to identify itself. This is used when creating 
# redirection URLs. In the context of virtual hosts, the ServerName 
# specifies what hostname must appear in the request's Host: header to 
# match this virtual host. For the default virtual host (this file) this 
# value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com  ProxyRequests off 
ServerAdmin webmaster@localhost 
DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,  # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. 
#LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access.log combined 
# For most configuration files from conf-available/, which are 
# enabled or disabled at a global level, it is possible to 
# include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only 
# after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf 

<Proxy balancer://cluster> 
BalancerMember https://173.34.34.27:80 
BalancerMember https://173.34.34.26:80 
Order Deny,Allow 
Deny from none Allow from all 
ProxySet lbmethod=byrequests 
</Proxy> 
<Location /balancer-manager> 
SetHandler balancer-manager #lock this down tightly Order deny,allow Allow from all </Location> ProxyPass /balancer-manager ! ProxyPass / balancer://cluster/ 
</VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Also change the IP addresses to your system IP addresses of your load balancing machines. Similarly set the server name and document root attributes as per your requirement, otherwise keep them as they are.

Enable the below modules for the load balancer to work properly.

# a2enmod proxy
# a2enmod proxy_http
# a2enmod proxy_balancer
# a2enmod lbmethod_byrequests

Last step is to restart the Apache2 service and check the configuration via browser.

# service apache2 restart

Share