In this tutorial we’ll learn how to install HAProxy on Ubuntu 16.04. We will also install and configure its prerequisites. HAProxy is an open-source solution that works TCP- and – HTTP-based software. This alternative provides transparent connections, server offloading, policy authorities, connection limiting, and more. If you’re afraid adding such a coating to your web servers will be too complex, panic not. Installing and setting up HAProxy is remarkably easy.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install HAProxy Ubuntu 16.04
Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:
apt-get update -y apt-get upgrade -y
Step 2. Installing HAProxy.
First, you will need to add the new repository with the following command:
sudo add-apt-repository ppa:vbernat/haproxy-1.7
Run the below command to install HAProxy:
sudo apt update sudo apt install -y haproxy
Once the installation is done successfully, you can make sure of that by running the below command on the terminal to ensure that HAProxy is working:
HA-Proxy version 1.7.8-1ppa1~xenial 2017/07/09 Copyright 2000-2017 Willy Tarreau <email@example.com>
Step 3. Configure HAProxy.
Open the configuration file, for example, using nano with the command underneath:
Add the following sections to the end of the file. Replace the <server name> with what ever you want to call you servers on the statistics page and the <private IP> with the private IPs for the servers you wish to direct the web traffic to:
frontend http_front bind *:80 stats uri /haproxy?stats default_backend http_back backend http_back balance roundrobin server <server1 name> <private IP 1>:80 check server <server2 name> <private IP 2>:80 check
After making the configurations, save the file and restart HAProxy with the next command:
systemctl restart haproxy
Congratulation’s! You have successfully install and configure HAProxy on your Ubuntu 16.04 server. Thanks for using this tutorial for installing HAProxy on Ubuntu system.