haproxy配置文件详解
global
daemon
maxconn 30000 #ulimit -n至少为60018
user haproxy
pidfile /home/ha/haproxy/conf/haproxy.pid
log 127.0.0.1 local0 info
log 127.0.0.1 local1 warning
defaults
mode http
log global
option http-keep-alive #使用keepAlive连接
option forwardfor #记录客户端IP在X-Forwarded-For头域中
option httplog #开启httplog,HAProxy会记录更丰富的请求信息
timeout connect 5000ms
timeout client 10000ms
timeout server 50000ms
timeout http-request 20000ms #从连接创建开始到从客户端读取完整HTTP请求的超时时间,用于避免类DoS攻击
option httpchk GET /healthCheck.html #定义默认的健康检查策略
frontend http-in
bind *:80
maxconn 30000 #定义此端口上的maxconn
# acl url_ms1 path_beg -i /ms1/ #定义ACL,当uri以/ms1/开头时,ACL[url_ms1]为true
# acl url_ms2 path_beg -i /ms2/ #同上,url_ms2
# use_backend ms1 if url_ms1 #当[url_ms1]为true时,定向到后端服务群ms1中
# use_backend ms2 if url_ms2 #当[url_ms2]为true时,定向到后端服务群ms2中
default_backend default_servers #其他情况时,定向到后端服务群default_servers中
#backend ms1 #定义后端服务群ms1
# balance roundrobin #使用RR负载均衡算法
# cookie HA_STICKY_ms1 insert indirect nocache #会话保持策略,insert名为"HA_STICKY_ms1"的cookie
# #定义后端server[ms1.srv1],请求定向到该server时会在响应中写入cookie值[ms1.srv1]
# #针对此server的maxconn设置为300
# #应用默认健康检查策略,健康检查间隔和超时时间为2000ms,两次成功视为节点UP,三次失败视为节点DOWN
# server ms1.srv1 192.168.8.111:8080 cookie ms1.srv1 maxconn 300 check inter 2000ms rise 2 fall 3
# #同上,inter 2000ms rise 2 fall 3是默认值,可以省略
# server ms1.srv2 192.168.8.112:8080 cookie ms1.srv2 maxconn 300 check
#
#backend ms2 #定义后端服务群ms2
# balance roundrobin
# cookie HA_STICKY_ms2 insert indirect nocache
# server ms2.srv1 192.168.8.111:8081 cookie ms2.srv1 maxconn 300 check
# server ms2.srv2 192.168.8.112:8081 cookie ms2.srv2 maxconn 300 check
#
backend default_servers #定义后端服务群default_servers
balance roundrobin
cookie HA_STICKY_def insert indirect nocache
server def.srv1 192.168.72.130:80 cookie def.srv1 maxconn 300 check
server def.srv2 192.168.72.131:80 cookie def.srv2 maxconn 300 check
listen stats #定义监控页面
bind *:1080 #绑定端口1080
stats refresh 30s #每30秒更新监控数据
stats uri /stats #访问监控页面的uri
stats realm HAProxy\ Stats #监控页面的认证提示
stats auth admin:admin #监控页面的用户名和密码
详见:http://www.ttlsa.com/linux/haproxy-study-tutorial/