How To Install HAProxy in Debian and Ubuntu
Overview:
This guide shows how to install the latest stable version of HAProxy on various versions of Debian and Ubuntu Linux systems.
Page Contents
Foreword
HAProxy is a popular open-source cross-platform load balancer and reverse proxy software for HTTP and TCP-based applications. It can run on Linux and several other Unix-based operating systems.
HAProxy is available in two editions: 1) HAProxy community edition is the free version of HAProxy and users of this edition rely solely on community support; 2) HAProxy enterprise edition, an enterprise-class version of HAProxy that ships with enterprise-class features such as a WAF (Web Application Firewall), services and premium support.
This guide will show how to install the latest stable version of the HAProxy community edition (2.8 at the time of writing), on Debian and Ubuntu Linux systems, from the official HAProxy repositories.
Install HAProxy 2.8-stable Community Edition on Ubuntu
Run the correct set of commands for your version of Ubuntu. These commands will install prerequisite packages, install the PPA configuration locally, update the local package index and install the required HAProxy package:
#Focal (20.04 LTS) and Jammy (22.04 LTS) # apt-get install --no-install-recommends software-properties-common # add-apt-repository ppa:vbernat/haproxy-2.8 #apt-get update # apt-get install haproxy=2.8.\*
Note that version 2.8 is only available on Focal (20.04 LTS) and Jammy (22.04 LTS) Ubuntu operating systems. Alternatively, you can install version 2.6-stable on other Ubuntu versions such as Bionic(18.04 LTS) and Lunar (23.04), as follows:
#Bionic (18.04 LTS) # apt-get install --no-install-recommends software-properties-common # add-apt-repository ppa:vbernat/haproxy-2.6 #apt-get update # apt-get install haproxy=2.6.\*
#Jammy (22.04 LTS) # apt-get update # apt-get install haproxy=2.6.\*
Install HAProxy 2.8-stable Community Edition on Debian
Run the appropriate set of commands for your version of Debian, as shown below. These commands will download the HAProxy repository key, setup the repository locally to use the key to verify the downloaded package, update the local package index and install the required package:
#Bookworm (Debian 12) # curl https://haproxy.debian.net/bernat.debian.org.gpg | gpg --dearmor > /usr/share/keyrings/haproxy.debian.net.gpg # echo deb "[signed-by=/usr/share/keyrings/haproxy.debian.net.gpg]" http://haproxy.debian.net bookworm-backports-2.8 main > /etc/apt/sources.list.d/haproxy.list #apt-get update # apt-get install haproxy=2.8.\*
#Bullseye (Debian 11) # curl https://haproxy.debian.net/bernat.debian.org.gpg | gpg --dearmor > /usr/share/keyrings/haproxy.debian.net.gpg # echo deb "[signed-by=/usr/share/keyrings/haproxy.debian.net.gpg]" http://haproxy.debian.net bullseye-backports-2.8 main > /etc/apt/sources.list.d/haproxy.list #apt-get update # apt-get install haproxy=2.8.\*
The latest stable version is not available for Debian 10, alternatively, you can install version 2.6-stable as follows:
#Buster (Debian 10) # curl https://haproxy.debian.net/bernat.debian.org.gpg | gpg --dearmor > /usr/share/keyrings/haproxy.debian.net.gpg # echo deb "[signed-by=/usr/share/keyrings/haproxy.debian.net.gpg]" http://haproxy.debian.net buster-backports-2.6 main > /etc/apt/sources.list.d/haproxy.list #apt-get update # apt-get install haproxy=2.6.\*
Note that:
- 1. If you can’t find instructions for your version of Debian or Ubuntu and the specific version of HAProxy you wish to install and use, check out the instructions on this official link: https://haproxy.debian.net/. Use the wizard to get the required installation instructions.
- 2. You can also find more information about community HAProxy packages here: https://github.com/haproxy/wiki/wiki/Packages
Verify HAProxy Installation
After successfully installing the HAProxy package, the service will be automatically started with the default configuration (stored in the /etc/haproxy/haproxy.cfg file) and managed by systemd, the default system and service manager in newer versions of Debian and Ubuntu.
To check the version of HAProxy package installed on your system, run the following command:
#haproxy -v
To check if the service is running and enabled to automatically start at system boot, issue the following commands:
#systemctl status haproxy.service #systemctl is-enabled haproxy.service
The default HAProxy configuration does not have any frontend and backend section defined, as a result, it does not listen on any port for requests. For example, if you are trying to test connections to it via port 80 or 443, the test will fail.
Conclusion
That’s all for now! In this guide, we have shown how to install the latest stable version of HAProxy on various Debian and Ubuntu Linux systems. In upcoming guides, we will show various ways to configure HAProxy for high availability and load balancing HTTP and TCP-based applications traffic within an IT environment. Use the comment section below to add your voice to this guide.
HAProxy community edition website: https://www.haproxy.org/