HAProxy (High Availability Proxy) is an opensource TCP/HTTP load balancer, we can use this to improve the performace of web sites and services by sending requestess across multiple servers. It is written in C and also fast, efficient and stable. It is created to hanndle high traffic websites.
In this article I will show you the installation of HAProxy on CentOS 6.4 and we will load balance it for HTTP request. I am using 3 instance for this.
WebServer 1 - 192.168.2.100
WebServer 2 - 192.168.2.101
HAProxy Server - 192.168.2.102
Step 1: On HAProxy Server
Before Installing HAProxy on the server we need to install epel repository on our system depending on our operating system version using following command.
CentOS/RHEL 5 , 32 bit:
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
CentOS/RHEL 5 , 64 bit:
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
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.
Now we will install haproxy application using following command.
# yum install haproxy
Step 3: Now we will configure HAProxy
We have to modify the configuraion file of haproxy i.e. /etc/haproxy/haproxy.cfg as per our requirement. (Change this configuration as your network requirements)
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
maxconn 45000 # Total Max Connections. This is dependent on ulimit
timeout server 86400000
timeout connect 86400000
timeout client 86400000
timeout queue 1000s
# Configuration for HTTP site
listen http_LinuxFunda 192.168.2.102:80
balance roundrobin # Load Balancing algorithm
server server1 192.168.2.100:80 weight 1 maxconn 512 check
server server2 192.168.2.101:80 weight 1 maxconn 512 check
listen stats 192.168.2.102:31337
stats uri /
stats realm Haproxy\ Statistics
stats refresh 5s
stats auth admin:password123
Step 4: Start HAProxy service
After finishing the edit we will now start the haproxy server by issuing following command. Also we have to add it to auto sratr on system boot.
# service haproxy start
# chkconfig haproxy on
Finally You have done it.
Now you will able to browse your applicaiton using the IP of the haproxy server. For haproxy Status dashboard you have to browse the URL: http://192.168.2.102:31337/. It will ask you for the username and password. Use the username and password you defined on the configuraion file as “stats auth”
Share and Enjoy
Latest posts by Tapas Mishra (see all)
- Working with Docker – II - December 16, 2016
- Working with Docker – I - November 28, 2016
- How to work with Chef using Oracle VirtualBox and Vagrant on a Windows host – Part II - November 30, 2014