#定义日志格式
capture request header Host len 40
capture request header Content-Length len 10
capture request header Referer len 200
capture response header Server len 40
capture response header Content-Length len 10
capture response header Cache-Control len 8
acl mall hdr_reg(host) -i ^(b2c-admin.hichao.com|ecshop.hichao.com)$
acl sa hdr_reg(host) -i ^(sa.hichao.com|sa1.hichao.com)$
use_backend mall_pool if mall
use_backend sa_pool if sa
default_backend default_pool
backend mall_pool
balance roundrobin
cookie SERVERID
option httpchk HEAD /index.html HTTP/1.0
server web-01 192.168.0.113 check port 80 inter 1500 rise 2 fall 3 weight 1
server web-02 192.168.0.114 check port 80 inter 1500 rise 2 fall 3 weight 1
server web-03 192.168.0.115 check port 80 inter 1500 rise 2 fall 3 weight 1
backend default_pool
balance roundrobin
cookie SERVERID
option httpchk HEAD /index.html HTTP/1.0
server web-01 192.168.0.113 check port 80 inter 1500 rise 2 fall 3 weight 1
backend sa_pool
balance roundrobin
cookie SERVERID
#option httpchk HEAD /index.html HTTP/1.0
server sa-01 192.168.1.17:81 check port 81 inter 1500 rise 2 fall 3 weight 1
#---------------------------------------------------------------------------------------------
配置启动脚本:
vim /usr/local/haproxy-1.5.10/haproxy.sh
#---------------------------------------------------------------------------------------------
[iyunv@chn-bj-yj-mall-ha-01 conf]# cat ../haproxy.sh
#!/bin/bash
#date:2015-01-02
#author:zhangluya
HA_DIR="/usr/local/haproxy-1.5.10"
RETVAL=0
[ -f ${HA_DIR}/conf/haproxy.cfg ] || exit 1
start() {
${HA_DIR}/sbin/haproxy -c -q -f ${HA_DIR}/conf/haproxy.cfg
if [ $? -ne 0 ]; then
echo "Errors found in configuration file,Please check haproxy.cfg"
return 1
fi
if [ ! -e ${HA_DIR}/haproxy.pid ];then
echo -e "Starting Haproxy ^_^ \n"
${HA_DIR}/sbin/haproxy -D -f ${HA_DIR}/conf/haproxy.cfg -p ${HA_DIR}/haproxy.pid
else
/bin/mv ${HA_DIR}/haproxy.pid /tmp
echo -e "Starting Haproxy ^_^ \n"
${HA_DIR}/sbin/haproxy -D -f ${HA_DIR}/conf/haproxy.cfg -p ${HA_DIR}/haproxy.pid
fi
}
stop() {