DebianLinuxTutorials

How To Install HAProxy on Debian 10

Install HAProxy on Debian 10

In this tutorial, we will show you how to install HAProxy on Debian 10. For those of you who didn’t know, HAProxy is an open-source, reliable, and High-Performance TCP/HTTP Load Balancer and Proxy server which runs on Linux, FreeBSD, and Solaris. HAProxy is written in C and it provides a high availability load balancer for TCP and HTTP-based applications that run on multiple servers. The best thing is that it has a free community edition, and it is an open-source application. The enterprise edition is also there, but it has a price tag.

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 the step-by-step installation of the HAProxy load balancer on a Debian 10 (Buster).

Prerequisites

  • A server running one of the following operating systems: Debian 10 (Buster).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Network Details.

Below is our network server. There are 2 web servers running with Apache2 and listening on port 80 and one HAProxy server:

Web Server Details:
  Server 1:    webserver1.idroot.us     192.168.0.10
  Server 2:    webserver2.idroot.us     192.168.0.11
HAProxy Server: 
  HAProxy:     haproxy                  192.168.0.8

Install HAProxy on Debian 10 Buster

Step 1. Before running the tutorial below, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update

Step 2. Installing HAProxy on Debian 10.

By default, the HAProxy package is not available in the Debian 10 default repository. So you will need to add the repository for that. Now download the GPG key for HAProxy with the following command:

curl https://haproxy.debian.net/bernat.debian.org.gpg | sudo apt-key add -

Next, add the HAProxy repository to apt:

echo deb http://haproxy.debian.net buster-backports-2.2 main | sudo tee /etc/apt/sources.list.d/haproxy.list

Once done, run the following commands to install it:

sudo apt update
sudo apt install haproxy=2.2.\*

Check the version of HAProxy with the following command:

 haproxy -v

You can also check the HAProxy service using the following command:

sudo systemctl start haproxy
sudo systemctl enable haproxy

Step 3. Configure HAProxy.

Now we set up HAProxy Load Balancer on Debian 10 for load balancing. You can achieve this by editing a file /etc/haproxy/haproxy.cfg:

nano /etc/haproxy/haproxy.cfg

Add your HAProxy server IP address and port 80 as shown below:

frontend Local_Server
  bind 192.168.0.8:80
  mode http
  default_backend Web_Servers

Next, add your web servers IP as shown below:

backend Web_Servers
  mode http
  balance roundrobin
  option forwardfor
  http-request set-header X-Forwarded-Port %[dst_port]
  http-request add-header X-Forwarded-Proto https if { ssl_fc }
  option httpchk HEAD / HTTP/1.1rnHost:localhost
  server webserver1.idroot.us  192.168.0.10
  server webserver2.idroot.us  192.168.0.11

Next, add the following lines to enable Haproxy statistics to monitor HAProxy from the web browser:

listen stats
  bind 192.168.0.8:8181
  stats enable
  stats hide-version
  stats refresh 30s
  stats show-node
  stats auth admin:meilana123
  stats uri  /stats

Save and close. Then, restart the HAProxy service:

 sudo systemctl restart haproxy

Step 4. Check HAProxy Load Balancing.

Once successfully set up, open your web browser and type the URL http://192.168.0.8:8181/stats. You will be redirected to the HAProxy statistics login page.

Congratulations! You have successfully installed HAProxy. Thanks for using this tutorial for installing the latest version of the HAProxy load balancing server on the Debian system. For additional help or useful information, we recommend you check the official HAProxy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button