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 the epel repository on our system depending on the operating system version using the following command.
CentOS/RHEL 6 , 32 bit:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
CentOS/RHEL 6 , 64 bit:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
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 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections. This is dependent on ulimit
user haproxy
group haproxy
daemon
defaults
timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s
# Configuration for HTTP site
listen http_idroot 192.168.1.102:80
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server server1 192.168.1.100:80 weight 1 maxconn 512 check
server server2 192.168.1.101:80 weight 1 maxconn 512 check
# Configuration for HTTPS site listen
https_idroot 192.168.1.102:443
mode tcp
balance source# Load Balancing algorithm
reqadd X-Forwarded-Proto:\ http
server server1 192.168.1.100:443 weight 1 maxconn 512 check
server server2 192.168.1.101:443 weight 1 maxconn 512 check
listen stats 192.168.1.102:31337
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
If you require help, contact SupportPRO Server Admin