{"id":6061,"date":"2020-06-06T00:26:41","date_gmt":"2020-06-05T21:26:41","guid":{"rendered":"https:\/\/kifarunix.com\/?p=6061"},"modified":"2024-03-14T21:55:45","modified_gmt":"2024-03-14T18:55:45","slug":"install-and-setup-haproxy-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-haproxy-on-ubuntu-20-04\/","title":{"rendered":"Install and Setup HAProxy on Ubuntu 20.04"},"content":{"rendered":"\n

Welcome to our guide on how to install and setup HAProxy on Ubuntu 20.04. HAProxy<\/a> (H<\/strong>igh A<\/strong>vailability Proxy), as you might already be aware, is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world’s most visited ones. <\/p>\n\n\n\n

It features connection persistence through HTTP cookies, load balancing, header addition, modification, deletion both ways. It has request blocking capabilities and provides interface to display server status.<\/p>\n\n\n\n

Installing HAProxy on Ubuntu 20.04<\/h2>\n\n\n\n

HAProxy is available on the default Ubuntu 20.04 repos. However, the available package might not be up-to-date.<\/p>\n\n\n\n

apt show haproxy<\/code><\/pre>\n\n\n\n
Package: haproxy\nVersion: 2.0.13-2\nPriority: optional\nSection: net\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\nOriginal-Maintainer: Debian HAProxy Maintainers <haproxy@tracker.debian.org>\nBugs: https:\/\/bugs.launchpad.net\/ubuntu\/+filebug\nInstalled-Size: 3,287 kB\nPre-Depends: dpkg (>= 1.17.14)\nDepends: libc6 (>= 2.17), libcrypt1 (>= 1:4.1.0), libgcc-s1 (>= 3.0), liblua5.3-0, libpcre2-8-0 (>= 10.22), libssl1.1 (>= 1.1.1), libsystemd0, zlib1g (>= 1:1.1.4), adduser, lsb-base (>= 3.0-6)\nSuggests: vim-haproxy, haproxy-doc\nHomepage: http:\/\/www.haproxy.org\/\nDownload-Size: 1,519 kB\nAPT-Sources: http:\/\/ke.archive.ubuntu.com\/ubuntu focal\/main amd64 Packages<\/code><\/pre>\n\n\n\n

As you can see, the HAProxy package available on the default repos is version 2.0.13 while the current stable release is version 2.1.5.<\/p>\n\n\n\n

Create HAProxy PPA Repository for Ubuntu<\/a><\/h3>\n\n\n\n

There are however, PPA repos that provides the latest stable release versions of HAProxy maintained by Vincent Bernat<\/a>. These PPA repos can be installed as follows;<\/p>\n\n\n\n

install software-properties-common<\/code><\/pre>\n\n\n\n
add-apt-repository ppa:vbernat\/haproxy-2.1 --yes<\/code><\/pre>\n\n\n\n

Run system update<\/h3>\n\n\n\n

Once the PPA repos are added to system, update your system package cache;<\/p>\n\n\n\n

apt update<\/code><\/pre>\n\n\n\n

Install HAProxy on Ubuntu 20.04<\/a><\/h3>\n\n\n\n

You can now be able to install the latest stable version of HAProxy;<\/p>\n\n\n\n

apt-cache policy haproxy<\/code><\/pre>\n\n\n\n
haproxy:\n  Installed: (none)\n  Candidate: 2.1.5-1ppa1~focal\n  Version table:\n     2.1.5-1ppa1~focal 500<\/strong>\n        500 http:\/\/ppa.launchpad.net\/vbernat\/haproxy-2.1\/ubuntu focal\/main amd64 Packages\n     2.0.13-2 500\n<\/strong>        500 http:\/\/ke.archive.ubuntu.com\/ubuntu focal\/main amd64 Packages<\/code><\/pre>\n\n\n\n

Note the versions provided by individual repos.<\/p>\n\n\n\n

You can now install HAProxy;<\/p>\n\n\n\n

apt install haproxy<\/code><\/pre>\n\n\n\n

To check the version of installed HAProxy, run the command below;<\/p>\n\n\n\n

haproxy -v<\/code><\/pre>\n\n\n\n
HA-Proxy version 2.1.5-1ppa1~focal 2020\/06\/01 - https:\/\/haproxy.org\/\nStatus: stable branch - will stop receiving fixes around Q1 2021.\nKnown bugs: http:\/\/www.haproxy.org\/bugs\/bugs-2.1.5.html\nRunning on: Linux 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64<\/code><\/pre>\n\n\n\n

Configure HAProxy Load Balancer on Ubuntu 20.04<\/a><\/h3>\n\n\n\n

With HAProxy, you can define multiple proxy services and configure HAProxy to load balance the traffic for the defined proxies. Proxies are made up of frontend system and one or more back-end systems. The front-end system defines the IP address and port on which the proxy listens as well as the back-end systems to use for a particular proxy.<\/p>\n\n\n\n

The main configuration file for HAProxy is \/etc\/haproxy\/haproxy.cfg<\/code><\/strong>.<\/p>\n\n\n\n

The HAProxy configuration file is made up of four sections;<\/p>\n\n\n\n