Monday, December 1, 2014

Step by Step Configuration of HAProxy on CentOS/RHEL 5/6

* HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world's most visited ones.






Step 1: Setup Yum Repository :

=> CentOS/RHEL 5 users required to add EPEL repository in order to install HAProxy packages. For CentOS 6 HAProxy packages are available under base repository, So there are no need to add any repository for them.

On CentOS/RHEL 5:

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Step 2: Install HAProxy : Install HAProxy package using yum command line interface.

# yum install haproxy

Step 3: Configure HAProxy

# vim /etc/haproxy/haproxy.cf

global
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections. This is dependent on ulimit
daemon
nbproc 1 # Number of processing cores. Dual Dual-core Opteron is 4 cores for example.
defaults
timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s

# [HTTP Site Configuration]
listen http_web 192.168.10.10:80 #change IP according to your loadbalancer IP
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server server1 192.168.10.100:80 weight 1 maxconn 512 check #change webserver 1 IP
server server2 192.168.10.101:80 weight 1 maxconn 512 check #change webserver 2 IP


# [HTTPS Site Configuration] Use this setting also if you have https configured on your server
listen https_web 192.168.10.10:443 #change IP according to your loadbalancer IP
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

Step 4: Start HAProxy Service : Restart your haproxy server

# service haproxy start
# chkconfig haproxy on

Now Haproxy configured successfully enjoy it .

Note : if you want to add more webserver in backend simply add the server as you need to add
you can add N number of Web Server's

server server3 192.168.10.100:80 weight 1 maxconn 512 check #change webserver 1 IP
server server4 192.168.10.100:80 weight 1 maxconn 512 check #change webserver 1 IP
server server5 192.168.10.100:80 weight 1 maxconn 512 check #change webserver 1 IP

Understanding "server server5 192.168.10.100:80 weight 1 maxconn 512 check"
server => Predifine variable to add Web Server
server5 => You can use any name on this place (basically it's indicate the hostname of Server"
192.168.10.100:80 => IP Address of backen web server : port number of web server
maxconn => Maxmimum connection
check => To check server is alive or not before sending the load on server .

No comments:

Post a Comment

Installing Jenkins on RHEL 8 is a straightforward process. Here's a step-by-step guide

Introduction  Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) pipelines...