This article will help you to install HAProxy on CentOS, RHEL servers.
Setup Instructions:
Step 1: Setup EPEL Repository
Install epel repository on your system depending on your operating system version using following command.
1 2 3 4 5 6 7 8 9 10 11 |
<orange style="color: orange;">CentOS/RHEL 5 , 32 bit:</orange> # rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm <orange style="color: orange;">CentOS/RHEL 5 , 64 bit:</orange> # rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm <orange style="color: orange;">CentOS/RHEL 6 , 32 bit:</orange> # rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm <orange style="color: orange;">CentOS/RHEL 6 , 64 bit:</orange> # rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm |
Step 2: Install HAProxy
Install HAProxy package using yum package manager from command line interface using following comamnd.
1 |
# yum <orange style="color: orange;">install</orange> haproxy |
Step 3: Configure HAProxy
Update your HAProxy configuration file /etc/haproxy/haproxy.cfg as per your requirement, You may also use below given configuration file as an example of setup and modify it.
1 |
# vim <orange style="color: orange;">/etc/haproxy/haproxy.cfg</orange> |
[ Update red mark values as per your network setup ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 <span id="IL_AD3" class="IL_AD" style="border-top-width: 0px; border-right-width: 0px; border-left-width: 0px; font-variant: inherit; line-height: inherit; vertical-align: baseline; position: static; padding-bottom: 1px !important; border-bottom-width: 1px !important; border-bottom-style: dotted !important; border-bottom-color: rgb(27, 142, 222) !important; color: rgb(27, 142, 222) !important; background-image: none !important; background-attachment: scroll !important; background-color: transparent !important; cursor: pointer !important; display: inline !important; float: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important;">processing</span> cores. Dual Dual-core Opteron is 4 cores for example. defaults timeout server 86400000 timeout connect 86400000 timeout client 86400000 timeout queue 1000s # Configuration for HTTP site listen http_web <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.10:80</span> mode http balance roundrobin # Load Balancing algorithm option httpchk option forwardfor server server1 <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.100:80</span> weight 1 maxconn 512 check server server2 <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.101:80</span> weight 1 maxconn 512 check # Configuration for HTTPS site listen https_web <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.10:443</span> mode tcp balance source# Load Balancing algorithm reqadd X-Forwarded-Proto:\ <span id="IL_AD5" class="IL_AD" style="border-top-width: 0px; border-right-width: 0px; border-left-width: 0px; font-variant: inherit; line-height: inherit; vertical-align: baseline; position: static; padding-bottom: 1px !important; border-bottom-width: 1px !important; border-bottom-style: dotted !important; border-bottom-color: rgb(27, 142, 222) !important; color: rgb(27, 142, 222) !important; background-image: none !important; background-attachment: scroll !important; background-color: transparent !important; cursor: pointer !important; display: inline !important; float: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important;">http server</span> server1 <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.100:443</span> weight 1 maxconn 512 check server server2 <span style="border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; color: red;">192.168.10.101:443</span> weight 1 maxconn 512 check |
OR
Download it using below url:
1 |
# wget http://tecadmin.net/wp-content/downloads/files/haproxy.cfg |
Change the ips in configuration file as per your network setup.
Step 4: HAProxy System Specific Configuration
You also need to make few changes in configuration file as per your system configuration.
1 2 3 |
<orange style="color: orange;">nbproc <value></orange> # Number of processing cores in your system. <orange style="color: orange;">mode <value></orange> # 'http' for http site and 'tcp' for https site <orange style="color: orange;">balance <value></orange> # Type of load balancing like 'source', 'roundrobin' etc. |
Step 5: Start HAProxy Service
Start HAProxy service using following command, also configure it to auto start on system boot.
1 2 |
# service haproxy start # chkconfig haproxy on |
Finally You have done it.
For more configuration details check below url. http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
I hope this article will help to setup HAProxy for your high availability setup.