1.安装haproxy
yum -y install haproxy
2.配置文件
# this config needs haproxy-1.1. or haproxy-1.2. global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn chroot /usr/share/haproxy uid gid daemon #debug #quiet defaults log global mode http option httplog option dontlognull retries redispatch maxconn contimeout clitimeout srvtimeout listen appli1-rewrite 0.0.0.0: cookie SERVERID rewrite balance roundrobin server app1_1 192.168.34.23: cookie app1inst1 check inter rise fall server app1_2 192.168.34.32: cookie app1inst2 check inter rise fall server app1_3 192.168.34.27: cookie app1inst3 check inter rise fall server app1_4 192.168.34.42: cookie app1inst4 check inter rise fall listen appli2-insert 0.0.0.0: option httpchk balance roundrobin cookie SERVERID insert indirect nocache server inst1 192.168.114.56: cookie server01 check inter fall server inst2 192.168.114.56: cookie server02 check inter fall capture cookie vgnvisitor= len option httpclose # disable keep-alive rspidel ^Set-cookie:\ IP= # do not let this cookie tell our internal IP address listen appli3-relais 0.0.0.0: dispatch 192.168.135.17: listen appli4-backup 0.0.0.0: option httpchk /index.html option persist balance roundrobin server inst1 192.168.114.56: check inter fall server inst2 192.168.114.56: check inter fall backup listen ssl-relay 0.0.0.0: option ssl-hello-chk balance source server inst1 192.168.110.56: check inter fall server inst2 192.168.110.57: check inter fall server back1 192.168.120.58: backup listen appli5-backup 0.0.0.0: option httpchk * balance roundrobin cookie SERVERID insert indirect nocache server inst1 192.168.114.56: cookie server01 check inter fall server inst2 192.168.114.56: cookie server02 check inter fall server inst3 192.168.114.57: backup check inter fall capture cookie ASPSESSION len srvtimeout option httpclose # disable keep-alive option checkcache # block response if set-cookie & cacheable rspidel ^Set-cookie:\ IP= # do not let this cookie tell our internal IP address errorloc http://192.168.114.58/error502.html errorfile /etc/haproxy/errors/.http