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 ]

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

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

# [HTTPS Site Configuration]
listen  https_web 192.168.10.10:443
        mode tcp
        balance source# Load Balancing algorithm
        reqadd X-Forwarded-Proto: http
        server server1 192.168.10.100:443 weight 1 maxconn 512 check
        server server2 192.168.10.101:443 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 192.168.10.10 on port 80, this will be Redirected to port 80 of 192.168.10.100 or even 192.168.10.101 servers. Similarly, in HTTPS Site Configuration if any petition on Ip 192.168.10.10 on port 443, this is redirected to port 443 of 192.168.10.100 or 192.168.10.101 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.