Configuration of HAProxy Load Balancer on CentOS

HAProxy stands for High Availability proxy.  It is a very fast and reliable solution for high availability and load balancing. HAProxy is used as TCP/HTTP Load Balancer and for proxy Solutions.The HAProxy application will share the workload with multiple servers.

Steps for Installation and configuring  HAproxy

Step 1: Before proceeding with the installation of  HAProxy in the server, we need to install epel repository on our system depending on the operating system version using the following command.

CentOS/RHEL 6 , 32 bit:
rpm -Uvh

CentOS/RHEL 6 , 64 bit:
rpm -Uvh

Step 2. Install HAProxy using Yum

yum install haproxy

Step 3: Configure HAProxy

The configuration file of haproxy is  /etc/haproxy/haproxy.cfg and modify the configuration file as per our requirement.

vi /etc/haproxy/haproxy.cfg global

log local0
log local1 debug
maxconn 45000 # Total Max Connections. This is dependent on ulimit
user haproxy
group haproxy

timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s

# Configuration for HTTP site
listen http_idroot
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

# Configuration for HTTPS site listen
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

listen stats
mode http
option httpclose
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
stats refresh 5s
stats auth admin:passwd123

Step4: Start the haproxy service using the following command

# service haproxy start
# chkconfig haproxy on

Leave a Reply