How To Install and Configure HAProxy on RHEL/CentOS 6x
-- HAProxy (High Availability Proxy) is an open-source load-balancer which can load balance any TCP service. HAProxy is a free, very fast and reliable solution that offers load-balancing, high-availability, and proxying for TCP and HTTP-based applications.
Step: 1. Set Hostname (On All Servers) :
# vi /etc/sysconfig/network
server1.kousik.com
-- Save & Quit (:wq)
# hostname server1.kousik.com
Step: 2. Bind Hosts File (On All Servers) :
# vi /etc/hosts
## IP's of HaProxy ##
192.168.72.181 server1.kousik.com server1
## IP's of Web Servers ##
192.168.72.182 www1.kousik.com www1
192.168.72.183 www2.kousik.com www2
-- Save & Quit (:wq)
Step: 3. Stop Firewall & Disable Selinux (On All Servers) :
# service iptables stop
# chkconfig iptables off
# vi /etc/sysconfig/selinux
SELINUX=disabled
-- Save & Quit (:wq)
Step: 4. Install NTP Server For Time Synchronization (On All Servers) :
# yum -y install ntp ntpdate
# service ntpd restart
# chkconfig ntpd on
# ntpdate pool.ntp.org
Step: 5. Reboot the System (On All Servers) :
# init 6
Step: 6. Copy hosts file to Other Server :
# scp /etc/hosts www1:/etc/
# scp /etc/hosts www2:/etc/
Step: 7. Web Server Configurations :
-- On Both Web Servers :
# yum -y install httpd
# service httpd start
# chkconfig httpd on
-- On Web1 :
# echo "<h1>www1.kousik.com</h1>" > /var/www/html/index.html
-- On Web2 :
# echo "<h1>www2.kousik.com</h1>" > /var/www/html/index.html
-- On LB (HAP) :
# yum -y install epel-release
# yum -y install haproxy
# yum -y remove httpd
# mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
# vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#debug
#quiet
user haproxy
group haproxy
#---------------------------------------------------------------------
# Defaults that are optimized for a Cloud Servers based
# Infrastructure.
#---------------------------------------------------------------------
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 20000
contimeout 5000
clitimeout 50000
srvtimeout 50000
#---------------------------------------------------------------------
# HTTP Default Webfarm
#---------------------------------------------------------------------
listen webfarm 0.0.0.0:80
mode http
stats enable
stats uri /haproxy?stats
stats realm Haproxy\ Statistics
stats auth admin:redhat # Username is 'admin' & Password is 'redhat'
balance roundrobin
cookie JSESSIONID prefix
option httpclose
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
server Web01 192.168.72.182:80 cookie A weight 50 check # Webserver1 IP Address.
server Web02 192.168.72.183:80 cookie B weight 50 check # Webserver2 IP Address.
-- Save & Quit (:wq)
# chkconfig haproxy on
# service haproxy start
Step: 8. Open Browser & Type for Statistics :
http://192.168.72.181/haproxy?stats
User: admin
Pass: redhat
Step: 9. Open Web Browser & Check Load Balancing :
http://192.168.72.181
Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog