Skip to content

digitalleks/LoadBalancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

LoadBalancer

Configuring Apache as a Loadbalancer

A new EC2 instance running Ubuntu Server 20.04 was created for this Load Balancer. Below is the snapshot of the available instance showing the Webservers, the NFS Server and the Database server:
EC2 STATUS

Port 80 was opened on the EC2 Instance security group as shown below:
Security group - http

Next is the installation of Apache Load Balancer.

sudo apt update
sudo apt install apache2 -y
sudo apt-get install libxml2-dev

apache-install
apache-lb-install\

After the installation, the following commands were run to enable some modules:

sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod lbmethod_byrequests

modules-enabled

Apache2 service was restarted and confirmed running:

sudo systemctl restart apache2
sudo systemctl status apache2

apache2-status

Next is the Configuration of the load balancer:

sudo vi /etc/apache2/sites-available/000-default.conf

The config entries is edited as shown below:

<Proxy "balancer://mycluster">
               BalancerMember http://172.31.33.120:80 loadfactor=5 timeout=1
               BalancerMember http://172.31.45.154:80 loadfactor=5 timeout=1
               ProxySet lbmethod=byrequests
        </Proxy>

        ProxyPreserveHost On
        ProxyPass / balancer://mycluster/
        ProxyPassReverse / balancer://mycluster/

Then the apache2 service is restarted:

sudo systemctl restart apache2

apache2-restart

Before testing, we needed to be able to log each webserver access in its own log, so we unmounted the log directory from the NFS as confirmed below:

sudo umount  172.31.43.227:/mnt/logs /var/log/httpd

umount-web1
umount-web3

To test our load balancer, we open the public IP from the web browser multiple times as follow:

http://ec2-3-137-204-64.us-east-2.compute.amazonaws.com/index.php

Test page opened shown below:
LB-Test-Page

Access logs for the two web servers are shown below:
Access_log_web1
Access_log_web2

About

Configuring Apache as a Loadbalancer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published