A. What is Haproxy
Haproxy provides high availability, load balancing, and proxies based on TCP and HTTP applications to support virtual hosts, a free, fast, and reliable solution. Haproxy is especially useful for Web sites that are heavily loaded, which typically require session maintenance or seven-tier processing. Haproxy is running on the current hardware and can support tens of thousands of concurrent connections altogether. and its operating mode makes it easy and secure to integrate into your current architecture while protecting your Web server from being exposed to the network.
Two. Install Haproxy
System Environment: centos6.3
apache:httpd-2.4.4
haproxy:haproxy-1.4.8
Haproxy server:192.168.7.198
Apache client1:192.168.7.196
Apache client2:192.168.7.197
Close Iptables and SELinux
# Service Iptables Stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
Selinux=disabled
---------------
# wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.8.tar.gz
# tar ZXVF haproxy-1.4.8.tar.gz
# CD haproxy-1.4.8
# UNAME-A//view Linux kernel version
# Make Target=linux26 Prefix=/usr/local/haproxy
# Make Install Prefix=/usr/local/haproxy
# useradd-s/sbin/nologin Haproxy
# passwd Haproxy
# Chown-r Haproxy.haproxy/usr/local/haproxy
Three. Configure Haproxy
# vi/usr/local/haproxy/haproxy.cfg
-----------------
Global
Maxconn 5120
Chroot/usr/local/haproxy
User Haproxy
Group Haproxy
Daemon
Quiet
Nbproc 2
Pidfile/usr/local/haproxy/haproxy.pid
Defaults
Log Global
Mode http
Option Httplog
Option Dontlognull
Log 127.0.0.1 Local3
Retries 3
Option Redispatch
Maxconn 2000
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Listen web:80
Mode http
Balance Roundrobin
Option Httpclose
Option Forwardfor
Server client1 192.168.7.196:80 Check weight 1 minconn 1 Maxconn 3 check Inter 40000
Server Client2 192.168.7.197:80 Check weight 1 minconn 1 Maxconn 3 check Inter 40000
Listen stats:8888
Mode http
Transparent
Stats Uri/haproxy-stats
Stats Realm haproxy \ Statistic
#认证
Stats Auth Haproxy:password
-----------------