Skip to content

Latest commit

 

History

History
128 lines (82 loc) · 3.38 KB

Project_8.md

File metadata and controls

128 lines (82 loc) · 3.38 KB

Configure Apache As A Load Balancer

Create an Ubuntu Server 20.04 EC2 instance and name it Project-8-apache-lb.

servera

Open TCP port 80 on Project-8-apache-lb by creating an Inbound Rule in Security Group.

servera

On the LB instance - Update the repo, install Apache server and the xml package as well as enable some required apache modules.

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

# Required Modules
sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod lbmethod_bytraffic

servera Restart apache2 service

sudo systemctl restart apache2

servera

Configure load balancing - configuring the LB-Server enables it to efficiently manage the distribution of incoming traffic to the best available Web Server ( for this setup, traffic is distributed evenly - loadfactor=5)

Let's edit the Apache configuration file to register the two web servers

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

Add the following line of codes within <vitualhist tags> tags the file. This includes the private ip for both web servers

<Proxy "balancer://mycluster">
               BalancerMember http://<WebServer1-Private-IP-Address>:80 loadfactor=5 timeout=1
               BalancerMember http://<WebServer2-Private-IP-Address>:80 loadfactor=5 timeout=1
               ProxySet lbmethod=bytraffic
               # ProxySet lbmethod=byrequests
</Proxy>


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

configuration file

Restart the apache service to register the update

sudo systemctl restart apache2

Apache restarted

bytraffic balancing method will distribute incoming load between the Web Servers according to current traffic load. I have controlled which proportion of the traffic must be distributed by using the loadfactor parameter.

Verify the LB Server (via public ip) is serving the tooling website in the browser.

Apache restarted

Verify the log directory of both web servers are not mounted to the NFS server.

sudo umount -f /var/log/httpd/

Apache restarted

To see traffic distrubtion (Load balancing) in action - open log file for both web servers and refresh the LB-server serveral times.

sudo tail -f /var/log/httpd/access_log

web server 1

Apache restarted

web server 2

Apache restarted

From the Logs, you can see both Web Servers are receiving the same load of web traffic. This is because the loadfactor was set to the value 5

Optional Step – Configure Local DNS Names Resolution in the LB - Server

sudo vi /etc/hosts

Add the private ip address for the two web servers

172.31.88.47 Web1 172.31.95.118 Web2

Apache restarted

Update this changes in the configuration file of the apache server on the LB instance.

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

Apache restarted

Use Curl verfiy that LB-server can acces web servers the local dns Web1 Web2

curl http://Web1

Apache restarted