How to Install HAproxy Load Balancer in Ubuntu

How to Install HAproxy Load Balancer in Ubuntu

HAProxy is an open source TCP and HTTP load balancer and a proxy software used in Linux distributions. It distributes the workload among multiple servers to improve the performance of the servers. This article explains the installation process of the HAProxy Load Balancer in Ubuntu.


Installation of HAproxy Load Balancer

Before installing HAproxy, add the required package into repository.

root@linuxhelp:~# add-apt-repository ppa:vbernat/haproxy-1.6
 HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particular
gpg: key 1C61B9CD: public key "Launchpad PPA for Vincent Bernat" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Utilize the following command to update the machine.

root@linuxhelp:~# apt-get update
Hit wily InRelease
Get:1 wily-security InRelease [65.9 kB]             
Get:2 wily InRelease [15.4 kB]                        
Get:38 wily-security/universe Translation-en [37.4 kB]
Fetched 1,912 kB in 19s (97.3 kB/s)                                            
Reading package lists... Done

Now its time to install the HAproxy package.

root@linuxhelp:~# apt-get install haproxy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
Processing triggers for libc-bin (2.21-0ubuntu4) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (225-1ubuntu9) ...

The '-v' option used to check the version of HAproxy.

root@linuxhelp:~# haproxy -v
HA-Proxy version 1.6.7 2016/07/13
Copyright 2000-2016 Willy Tarreau <>

Use the below command to take the original HAproxy configuration file.

root@linuxhelp:~# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.original

Open the HAproxy configuration file and add content into the entry as shown below,

root@linuxhelp:~# vim /etc/haproxy/haproxy.cfg
frontend http_front
   bind *:80
   stats uri /haproxy?stats
   default_backend http_back

backend http_back
   balance      roundrobin
   server check
   server check

Once the HAproxy is configured, restart the service.

root@linuxhelp:~# service haproxy restart



Open the web browser with the HAproxy IP to check the status of web-servers.


Now you can access the web-server with IP address of Load Balancer. Also can view content of the backend webservers by each and every request.



Again open the configuration file of HAproxy and add the following line for authentication.

root@linuxhelp:~# vim /etc/haproxy/haproxy.cfg
listen stats
   bind *:8800
   stats enable
   stats uri /
   stats realm Haproxy Statistics
   stats auth admin:12345

Once the above process is completed, estart the HAproxy service .

root@linuxhelp:~# service haproxy restart

Now open the Browser with the Load Balacer IP and assigned port number. Enter the following credentials as follows,




Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Proxy server HAProxy HTTP TCP
user image Author :  Oliver