How to install and configure HAProxy loadbalancer on Ubuntu 18.04


A load balancer goes about as the “traffic cop” sitting before your servers and steering customer asks for over all servers fit for satisfying those solicitations in a way that boosts speed and limit use and guarantees that nobody server is exhausted, which could debase execution. In the event that a solitary server goes down, the load balancer diverts activity to the staying on the web servers. At the point when another server is added to the server gathering, the heap balancer naturally begins to send demands to it.

To install and configure HAProxy loadbalancer on Ubuntu 18.04 we will consider three system as follows

1. One is web server1>IP Address:>
2. Two is web server2>IP Address:>
3. HAproxy loadbalancer>IP Address:>

Step 01: Make sure that system1 and system2 has apache2 installed. Please use below command for Ubuntu 18.04 to install apache2 for both system1 and system2.



Now type system1 and system2 IP address on web browser and visit apach2 default web page.

You can change default index.html file from /var/www/html.
You can also change /etc/hosts file to visit web page by host name, like I did.






Step 02:

We will now configure loadbalancer machine. At first we will install HAProxy by executing below commands

Step 03:

Edit haproxy default configuration file /etc/haproxy/haproxy.cfg and start configuration.

At the end of the file we will add folowing information

Step 04:

To verify the configuration

It will show output : Configuration file is valid

Step 05:

Restart HAproxy

Now type system ip) on web browser and refresh 2/3times. You will see HAProxy loadbalancer is working.





Thank you.

Spread the love

PS. If you like this post please share it with your friends on the social networks using the buttons above.Thanks.


Please enter your comment!
Please enter your name here