In this tutorial we will show you how to install HAProxy on Ubuntu 18.04 LTS. For those of you who didn’t know, HAProxy is a free HTTP/TCP high availability load balancer and proxy server. It spreads requests among multiple servers to mitigate issues resulting from single server failure. HA Proxy is used by a number of high-profile websites including GitHub, Bitbucket, Stack Overflow, Reddit, Tumblr, Twitter and Tuenti and is used in the OpsWorks product from Amazon Web Services.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation HAProxy on an Ubuntu 18.04 bionic beaver.
Install HAProxy on Ubuntu 18.04 LTS Bionic Beaver
Step 1. First, make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.
To install and configure HAProxy load balancer on Ubuntu 18.04 we will consider three system as follows:
Server1: web1.idroot.us 192.168.1.104
Server2: web2.idroot.us 192.168.1.105
HAProxy: haproxy 192.168.1.46
At first we will install HAProxy by executing below commands:
Now edit haproxy default configuration file /etc/haproxy/haproxy.cfg and start configuration:
At the end of the file we will add folowing information:
To verify the configuration:
If above command return output as “configuration file is valid” then restart HAProxy service:
With the HAProxy configured and running, open your load balancer server’s public IP in a web browser and check that you get connected to your backend correctly. The parameter stats uri in the configuration enables the statistics page at the defined address:
Congratulation’s! You have successfully installed HAProxy. Thanks for using this tutorial for installing HAProxy load balancer in Ubuntu 18.04 bionic beaver system. For additional help or useful information, we recommend you to check the official HAProxy website.