Install HAProxy on Ubuntu

67 views 0 Comments

Ubuntu 20.04 is a great choice for installing your HAProxy software load balancer. It’s a free Linux operating system that’s fast, secure, and best of all, it’s easy to use.
One of the features that make Ubuntu so accessible to even the newest of users is its package managerapt, the Advanced Packaging Toolapt lets you easily install and remove packages and dependencies, generally without having to worry about the nitty-gritty details of file paths, libraries, compilers, and version conflicts.
It’s so easy that installing HAProxy on a brand new Ubuntu box can be as simple as a one-line apt command:

 $ sudo apt install haproxy

view raw

But wait, there’s more!™

Yes, that simple command will quickly and easily set you up with HAProxy, but you’ll find that the version you’ve just installed probably lags behind the current release by a minor version number or two, sometimes as much as a major version number.

The version you get with apt out-of-the-box will be stable and secure, but it’s going to lack some of the cool new features you’ve been reading about, such as FIX protocol supportHTTP/2 WebSocketsor Dynamic SSL Certificate Storage

You can compile the source code yourself, but that can be a lot of extra steps. Fortunately, Vincent Bernat has done all of the hard work and released something called a PPA, or Personal Package Archive. A custom PPA tells Ubuntu to use a software source outside its normal channels and install a custom package. In the case of HAProxy, which is already provided by the official sources, once the PPA is installed, apt will use this custom package over the default.

​#Install the Latest HAProxy Using a PPA

Install Ubuntu 20.04 Server. For testing, I’m using a virtual machine running on my laptop. Everything we do here should work equally well on bare metal or any cloud provider.

Head over to haproxy.debian.net, where you can select the install instructions for your OS. At the time of this writing, the latest version was 2.4. Select the options for Ubuntu Focal (20.04 LTS) (long-term support) and HAProxy 2.4-stable (LTS). This will bring you to a page listing the commands you need to run:

$ sudo apt install –no-install-recommends software-properties-common
$ sudo add-apt-repository ppa:vbernat/haproxy-2.4 -y

view raw

The first command installs the software-properties-common package which helps you manage any PPAs you install. It’s probably already installed, but running it again ensures that it’s available. The second command puts the PPA into the list of software sources.

We’re now ready to install the very latest HAProxy:

$ sudo apt install haproxy=2.4.\*

view raw

Adding =2.4.\* to the end tells apt that we want to maintain the latest version of HAProxy in the 2.4 branch, so if there are future updates in that branch, you’ll get them when you do an apt upgrade .

To show what you’ve installed:

$ haproxy -v
HAProxy version 2.4.2-1ppa1~focal 2021/07/07 – https://haproxy.org/
Status: long-term supported branch – will stop receiving fixes around Q2 2026.
Known bugs: http://www.haproxy.org/bugs/bugs-2.4.2.html
Running on: Linux 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64

view raw

Do an update and upgrade, to ensure you have the latest software packages and any security fixes:

$ sudo apt update && sudo apt upgrade -y

view raw

You now have a fully up-to-date Ubuntu system running the latest version of HAProxy with a stock configuration located at /etc/haproxy/haproxy.cfg; you’re ready to start customizing.