How to Install HA Proxy on CentOS 8

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"

HA Proxy stands for High Availability Proxy written on C. It is a free and open source TCP/HTTP load balancer and proxy solution for TCP and HTTP based applications. HA Proxy allows you to balance incoming TCP / HTTP Traffic by distributing load across backend server using different criteria.

The use of HA Proxy is to provide fault tolerance and high availability in case when one node is getting too many concurrent requests. It is used by most famous web sites like GitHub, Stack Overflow and Tumbler.

HA Proxy allows an application to restart automatically or reroute work to another server in the event of a failure. HA Proxy is a powerful, high power, reliable and secure load balancer.

In his tutorial we will install and configure HA Proxy on CentOS 8.

Install HA Proxy:

yum -y install haproxy

Configure HA Proxy:

Please note that the following configuration is for Application that use TCP connection to connect to the destination machine / Application.

Ha proxy Configuration involves 4 steps:

  1. global settings: First, we use to set process-wide parameters.
  2. defaults: Secondly, we defaults use to set default parameters for all other sections.
  3. frontend: In this section we define how we access HA Proxy externally to enable access to the backend.
  4. backend: Used to define a set of servers to which the proxy will connect to forward incoming connections.

Now, create a directory named run in /etc/haproxy for stats socket.

mkdir /etc/haproxy/run

Open HA proxy configuration file with the following command:

nano /etc/haproxy/haprxoy.conf

Remove the default configuration present in file.

Now, add the following configuration:

   log /dev/log local0
   log /dev/log local1 notice
   chroot /var/lib/haproxy
   stats socket /etc/haproxy/run/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy

     log global
     option dontlognull
     option tcplog
     mode tcp
     timeout connect 5000
     timeout client 50000
     timeout server 50000

listen  stats   
        mode            http
        maxconn 10
        timeout queue        300s

        stats enable
        stats refresh 10s
        stats show-node
        stats auth haproxyadmin:haproxyadmin
        stats uri  /haproxy

frontend server_front
     bind *:9909
     default_backend server_back

backend server_back
     balance roundrobin
     server S1 check
     server S2 check

Please note that the above configuration is for TCP connection or Application where TCP connection with server is required. You can also do the configuration for HTTP applications by replacing tcp with http in above configuration.

Start and Enable HA Proxy:

systemctl start haproxy.service
systemctl enable haproxy.service
systemctl status haproxy.service

Open HA Proxy url to see the connections statistics.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"
Unix/Linux Guru and FOSS supporter


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook