Skip to content

realayo/Apache_LoadBalancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Load Balancer Solution With Apache

We will be using servers we configured for our tooling website which consists of:

  1. Two RHEL8 Web Servers
  2. One MySQL DB Server (based on Ubuntu 20.04)
  3. One RHEL8 NFS server

Configure Apache As A Load Balancer

  1. Set up a new Ubuntu server on EC2.
  2. Install Apache Load Balancer on the server and configure it to point traffic coming to Load Balancer to both Web Servers:
# Install apache2
sudo apt update
sudo apt install apache2 -y
sudo apt-get install libxml2-dev

# Enable the following modules:
sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod lbmethod_bytraffic
  1. Restart apache2 service
sudo systemctl restart apache2
  1. Make sure apache is running
sudo systemctl status apache2

5. Configure load balancing

sudo vi /etc/apache2/sites-available/000-default.conf
  1. Add this configuration between section <VirtualHost *:80> and </VirtualHost> section:
<Proxy "balancer://mycluster">
        BalancerMember <WebServer1-Private-IP-Address>:80 loadfactor=5 timeout=1
        BalancerMember <WebServer2-Private-IP-Address> loadfactor=5 timeout=1
          roxySet lbmethod=bytraffic
        # ProxySet lbmethod=byrequests
 </Proxy>

        ProxyPreserveHost On
        ProxyPass / balancer://mycluster/
        ProxyPassReverse / balancer://mycluster/ 
  1. Verify that our configuration works by accessing our LB’s public IP address or Public DNS name from the web browser

Unmount log directory

  1. Remember we mounted /var/log/httpd/ from our Web Servers to the NFS server in our tooling project - unmount them and make sure that each Web Server has its own log directory.
sudo umount -l <WebServer-Private-IP-Address>:/mnt/logs
  1. Open two ssh consoles for both Web Servers and run following command:
sudo tail -f /var/log/httpd/access_log
  1. Refresh your browser page http://<Load-Balancer-Public-IP-Address>/index.php several times and make sure that both servers receive HTTP GET requests from your LB - new records must appear in each server’s log file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published