Configuring Load Balancer or Reverse Proxy on RHEL 8

Aditya Kumar
5 min readDec 18, 2020

--

Before Configuring the load Balancer Let us see What is Load Balancer ?

A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications. They improve the overall performance of applications by decreasing the burden on servers associated with managing and maintaining application and network sessions, as well as by performing application-specific tasks.

Load balancers are generally grouped into two categories: Layer 4 and Layer 7. Layer 4 load balancers act upon data found in network and transport layer protocols (IP, TCP, FTP, UDP). Layer 7 load balancers distribute requests based upon data found in application layer protocols such as HTTP.

Requests are received by both types of load balancers and they are distributed to a particular server based on a configured algorithm. Some industry standard algorithms are:

  • Round robin
  • Weighted round robin
  • Least connections
  • Least response time

Prerequisites :

  • For Configuring Load Balancer first we need at least three Systems one is for Load Balancer and the remaining two is for checking whether it is configured successfully or not. Either you can use RHEL 8 for configuring this or you can use AWS EC2 instances for that.
  • We also need httpd services while doing this configuration.

These are the Steps require for Configuring Load Balancer or HA-proxy

For Configuring Load Balancer on RHEL 8 First we have to install haproxy in any of the one instances you want by using a command called yum install haproxy

After the installation of haproxy successfully now you have to install httpd in the other two instances and for installing the httpd services type command yum install httpd

After installing httpd services on both of the two instances. Now go to the /var/www/html directory on both of the instances and create a html file called index.html. And in this file write some HTML rulesets for checking the Load Balancer and make sure that the content of both the index.html files are not same, it somehow quite different to each other due to because when response is come in the browser you are able to differentiate whether the output is coming from both the ips or from single ip.

So here is my both the index.html files

So here you can see that my both the index.html files are different in content wise.

After completing all these steps now we have to tell haproxy that from where the outputs were come. For that we have to go its configuration files and make some changes on it.

As shown in picture first you have to go it’s configuration file which is located at cd /etc/haproxy/haproxy.cfg either change the directory and then open the conf file or directly you can use vim /etc/haproxy/haproxy.cfg. After writing this command you are able to see a window like this..

Scroll down the page at the bottom you will able to see backend app option Now the task is that to the make some small changes on the backend app option. First go and check the IP addresses of both the instances in which httpd is configured, use command ifconfig enp0s3 to see the Ip Address of the machine.

After gathering the Ips now come to the configuration file and make entries of these Ips on the backend app option as shown in image below and by default the port is 5001 and so on, change the port no from 5001 to 80 because the httpd server is running on the port no 80 see the image below..

In my case these are my Ips as shown in image.

After changing the configuration file, Now you are set to use haproxy services. For that go to your both of the two instances and start the httpd services use command systemctl start httpd and for accessing this you have to stop firewall use command systemctl stop firewalld in both the instances

After this, Now start the haproxy to use Load Balancer for that use command systemctl start haproxy and for accessing it stop the firewall of haproxy to by using the same command as httpd systemctl stop firewalld

After starting the haproxy services, Now go to your Browser and type the Ip Address of your Machine in which haproxy installed along with the port no which is 5000, By default haproxy works on the port no 5000 so we have to write port no to along with the Ip Address.

These are the two pages which we have configured earlier in our two instances.

And now you can see that from one Ip Address both the pages were coming together one by another while refreshing the page. This gives security to our webpage or webapp that, If any Hacker comes in our page and try to access our backend where our Database details are there and suppose if any important data is available then he doesn’t able to access because he is not aware with the Ip of backend from where the content is coming in our webapp. So this makes our Webapp more secure..

This completes the configuration of Load Balancer on RHEL 8

For Further Queries Or Suggestions Feel Free to Connect with me LinkedIn..

Thank you Everyone For Reading ..!!

--

--

Aditya Kumar
0 Followers

Full Stack Web Developer | Linux System Administrator | Ansible | Kubernetes | Django | AWS | Coder