Skip to content

Latest commit

 

History

History
97 lines (61 loc) · 3.54 KB

File metadata and controls

97 lines (61 loc) · 3.54 KB

LOAD BALANCER SOLUTION WITH APACHE

After completing Project-7 you might wonder how a user will be accessing each of the webservers using 3 different IP addreses or 3 different DNS names

When you have just one Web server and load increases – you want to serve more and more customers, you can add more CPU and RAM or completely replace the server with a more powerful one – this is called "vertical scaling"

Another approach used to cater for increased traffic is "horizontal scaling" – distributing load across multiple Web servers.

image

This is implemented using the Project 7

  • Two RHEL8 Web Servers
  • One MySQL DB Server (based on Ubuntu 20.04)
  • One RHEL8 NFS server

image

image

image

  • The NFS server mnt/apps has the html directory

image

  • Install Apache Load Balancer on Project-8-apache-lb server and configure it to point traffic coming to LB to both Web Servers:
#Install apache2
sudo apt update
sudo apt install apache2 -y
sudo apt-get install libxml2-dev

#Enable following modules:
sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod lbmethod_bytraffic

#Restart apache2 service
sudo systemctl restart apache2
  • Configure load balancing

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

#Add this configuration into this section <VirtualHost *:80>

<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/

image

  • The red highlight shows the public ip before load balancer
  • The blue highlight shows the private ip of the load balncer

image

image

  • Configure local domain name resolution. The easiest way is to use /etc/hosts file, to configure IP address to domain name mapping for our LB
#Open this file on your LB server

sudo vi /etc/hosts

#Add 2 records into this file with Local IP address and arbitrary name for both of your Web Servers

<WebServer1-Private-IP-Address> Web1
<WebServer2-Private-IP-Address> Web2

image

image

Sites reachable after changing the hosts file

image