How to install and configure HAProxy loadbalancer on Ubuntu 18.04

Windows Articles

How to update apps on Android

Hi folks! In this post, we will show you how to update your Android apps. Updating the apps on your device is...

How to install Apache Ant on Ubuntu 20.04?

Hello, friends. Apache Ant is a very important tool for the development of applications in Java. So in this post, we will...

How to use the ss command

For Linux users, there will come a time when you need to know about the network. Several tools help in this process,...

How to create user template in Windows Server 2019/2016

Hello! Windows Server has many features that support system administration. For example, through the users it is possible to manage many administrative...

Debian 10.6 available

Several volunteers have developed the free software distributed under the name of Debian. Debian does not sell its software directly, the developers...
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

How to update apps on Android

Hi folks! In this post, we will show you how to update your Android apps. Updating the apps on your device is...

How to install Apache Ant on Ubuntu 20.04?

Hello, friends. Apache Ant is a very important tool for the development of applications in Java. So in this post, we will...

How to use the ss command

For Linux users, there will come a time when you need to know about the network. Several tools help in this process,...

How to create user template in Windows Server 2019/2016

Hello! Windows Server has many features that support system administration. For example, through the users it is possible to manage many administrative...

Debian 10.6 available

Several volunteers have developed the free software distributed under the name of Debian. Debian does not sell its software directly, the developers...