How to Install HAProxy CentOS 7

r00t October 11, 2017

Install HAProxy CentOS 7

In this tutorial we’ll learn how to install HAProxy on CentOS 7. We will also install and configure its prerequisites. HAProxy is an open-source solution that works TCP- and – HTTP-based software. This alternative provides transparent connections, server offloading, policy authorities, connection limiting, and more. If you’re afraid adding such a coating to your web servers will be too complex, panic not. Installing and setting up HAProxy is remarkably easy.

I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install HAProxy CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Installing HAProxy CentOS 7.

HAProxy package is available under default yum repository for CentOS systems. Use the following yum package manager command to install HAProxy:

sudo yum install haproxy

Step 3. Configure HAProxy.

Open the configuration file in a text editor:

nano /etc/haproxy/haproxy.conf

[ Update blue mark values as per your network setup ]

        log   local0
        log   local1 debug
        maxconn   45000 # Total Max Connections.
        nbproc      1 # Number of processing cores.
        timeout server 86400000
        timeout connect 86400000
        timeout client 86400000
        timeout queue   1000s

# [HTTP Site Configuration]
listen  http_web
        mode http
        balance roundrobin  # Load Balancing algorithm
        option httpchk
        option forwardfor
        server server1 weight 1 maxconn 512 check
        server server2 weight 1 maxconn 512 check

# [HTTPS Site Configuration]
listen  https_web
        mode tcp
        balance source# Load Balancing algorithm
        reqadd X-Forwarded-Proto: http
        server server1 weight 1 maxconn 512 check
        server server2 weight 1 maxconn 512 check

Change the IPs in configuration file in accordance with your network setup. In HTTP Site Configuration Section if any petition on ip on port 80, this will be Redirected to port 80 of or even servers. Similarly, in HTTPS Site Configuration if any petition on Ip on port 443, this is redirected to port 443 of or servers.

After making the configurations, save the file and restart HAProxy with the next command:

systemctl enable haproxy
systemctl restart haproxy

Congratulation’s! You have successfully install and configure HAProxy on your CentOS 7 server. Thanks for using this tutorial for installing HAProxy on CentOS 7 system.

The Tags:

Leave a Comment

Comments are closed.