How to install and configure HAProxy loadbalancer on Ubuntu 18.04

Windows Articles

Install GLPI with Lighttpd on Ubuntu 20.04

Ubuntu 20.04 is a very popular distribution on servers because it is quite stable and offers commercial support. That is why it...

How to install Lighttpd on Ubuntu 20.04?

There are many web services in Unix but we always look for the one that best suits our needs. In this case,...

How to install Docker on Ubuntu 20.04 / Debian 10?

Docker is a fairly popular technology in today's sysadmin. It is logical to think because it means a complete change in the way images...

How to install Mantis Bug Tracker on Ubuntu 20.04?

Hi, folks. In this post, I will help you to install Mantis Bug Tracker on Ubuntu 20.04 If you...

How to install WordPress with Nginx on Ubuntu 20.04?

Hi, folks. In this post, we will help you install Wordpress with Nginx on Ubuntu 20.04. It's a lot easier than you...
Mel Khamlichi
Mel Khamlichihttp://www.osradar.com
Founder of Osradar, from Amsterdam Netherlands

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: 192.168.64.137>Hostname:system1.osrader.com
2. Two is web server2>IP Address: 192.168.64.139>Hostname:system2.osrader.com
3. HAproxy loadbalancer>IP Address: 192.168.64.141>Hostname:loadbalancer.osrader.com

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.

$ sudo apt-get update
$ sudo apt-get install apache2
$sudo ufw app list (to check list of application profiles)

 

 

$sudo ufw allow 'Apache'
$sudo ufw status (for verifying)
$sudo systemctl status apache2 (to check service status)

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

$ sudo add-apt-repository ppa:vbernat/haproxy-1.7
$ sudo apt-get update
$ sudo apt-get install haproxy

Step 03:

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

$ vim /etc/haproxy/haproxy.cfg

At the end of the file we will add folowing information

frontend Local_Server
bind 192.168.64.141:80
mode http
default_backend webserver

backend webserver
mode http
balance roundrobin
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk HEAD / HTTP/1.1rnHost:localhost
server system1.osradar.com 192.168.64.137:80
server system2.osradar.com 192.168.64.139:80

Step 04:

To verify the configuration

$ sudo haproxy -c -f /etc/haproxy/haproxy.cfg

It will show output : Configuration file is valid

Step 05:

Restart HAproxy

$ sudo service haproxy restart

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

 

 

 

 

Thank you.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Install GLPI with Lighttpd on Ubuntu 20.04

Ubuntu 20.04 is a very popular distribution on servers because it is quite stable and offers commercial support. That is why it...

How to install Lighttpd on Ubuntu 20.04?

There are many web services in Unix but we always look for the one that best suits our needs. In this case,...

How to install Docker on Ubuntu 20.04 / Debian 10?

Docker is a fairly popular technology in today's sysadmin. It is logical to think because it means a complete change in the way images...

How to install Mantis Bug Tracker on Ubuntu 20.04?

Hi, folks. In this post, I will help you to install Mantis Bug Tracker on Ubuntu 20.04 If you...

How to install WordPress with Nginx on Ubuntu 20.04?

Hi, folks. In this post, we will help you install Wordpress with Nginx on Ubuntu 20.04. It's a lot easier than you...