Load balancing for a web server refers to evenly distribution of incoming traffic across two or more backend servers. Load balancing leads to increased server functionality, decreased traffic congestion leading to faster page load times & also provide redundancy. Load balancing is what you need when you have a website with lots of traffic.

In this tutorial, we are going to discuss Pound Load balancer. Pound load balancer acts as a front end for all the http/https request, it can be used as a reverse proxy & will evenly distribute request to the backend servers.

When configured, pound will be the public facing server which will accept the incoming request form port 80 & 443. Then it will evenly distribute the request to the available backend servers. For example, if we have 2 backend servers first request will go to server1 & then to server2. & then pound server will deliver the content back to clients as per the request (reverse proxy).

(Recommended Read: How to use Apache reverse proxy as Load Balancer )

(Also Read: How to use Apache as Reverse Proxy on CentOS & RHEL)

 

Pre-requisites

In order to test the working of Pound load-balancer, we will need

  • A server with pound load balancer installed (epel repository needed). Install EPEL repository using the following steps,

RHEL/CentOS 7

$ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

RHEL/CentOS 6 (64 Bit)

$ sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

RHEL/CentOS 6 (32 Bit)

$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

  • Two backend servers with apache installed (for detailed installation & configuration, read our tutorials HERE & HERE)

 

Scenario

Pound server

Hostname- pound.ltechlab.com                                IP address- 192.168.1.100

Apache Servers

Hostname- server1.ltechlab.com                             IP address- 192.168.1.111

Hostname- server2.ltechlab.com                             IP address- 192.168.1.112

So now let’s move onto creating a Pound Load balancer,

 

Web Server

Installation

We will now prepare apache server on our backend machines. To install apache, run following command on both the machines,

$ yum install httpd

After installation has been done on both machines, we will move onto configuration part.

 

Configuration

Now we need to create an index.html to identify both web servers. Go to /var/www/html & create an index.html page with following content,

$ cd /var/www/html

$ echo “This is web server 1” > index.html

Similarly create index.html page on server 2 as well but change “This is web server 1” to “This is web server 2”

Restart apache service on both machines to implement the changes,

$ systemctl restart httpd

You can check the pages by entering the IP address or FQDN of the machine into your internet browser.

 

Pound server

Installation

To install Pound server, we first have to enable EPEL repository as Pound Load balancer is not available with default repositories. To enable EPEL repository, run

$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

Once the repo has been installed, we will install pound by running,

$ yum install pound

 

Configuration

Main configuration file for Pound load balancer is /etc/pound.cfg. We will edit this file to configure load  balancing for our backend servers.

$ vi /etc/pound.cfg

Now edit the file as done below,

ListenHTTP

    Address 192.168.1.100

    Port 80

End

ListenHTTPS

    Address 192.168.1.100

    Port    443

    Cert    "/etc/ssl/pound.pem"

End

Service

    BackEnd

        Address 192.168.1.111

        Port    80

    End

   BackEnd

        Address 192.168.1.112

        Port    80

    End

End

 

Save & exit the file.

NOTE:- Remove the section with ListenHTTPS if not using HTTPS, which in our case is true.

Now restart the pound services to implement changes to the configuration file,

$ systemctl restart pound

 

Testing the load balancer

To test the load balancer, open you browser & enter the Pound server’s IP address i.e. 192.168.1.100. It will open the web page saying “This is web server 1 ”, refresh the page & you will then be redirected to web server 2, keep refreshing & you will see that one request goes to server 1 & then to server 2.

 

This concludes our tutorial, feel free to mention any queries/questions in the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.