Haproxy.cfg Configuration file Contents
#全局配置global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info m Axconn 8192 #chroot的路径 chroot/usr/local/haproxy #运行用户和组的id uid #以守护进程 Form run Daemon #debug quiet #进程数量 based on server performance tuning Nbproc #pid路径 pidfile/var/ru n/haproxy/haproxy.pid# The default global configuration, these parameters are used to configure the Frontend,backend,listen component defaults log global #所处理的类别 (#7层 http;4 Layer TCP) Mode HTTP #日志类别http日志格式 option httplog #不记录健康检查的日志信息 option Dontlognull #如果后端服务器需客户端真实ip需要配置的参数, the client IP option Forwardfor can be obtained from the Httpheader #serverId对应的服务器挂掉后, forcing direct access to other healthy servers Option Redispatch #当服务器负载很高的时候, automatically end the current queue processing longer than the connection option Abortonclose #3次连接失败就认为服务不可用, can also be set by the following Retries 3 #最高连接数 maxconn 8192 #连接超时 contimeout #客户端超时 Clit Imeout 50000 #服务器超时 srvtimeout 50000 #心跳检测超时 timeout check 2000listen appli1-rewrite 192.168.12.1:80 #允许插入serverid到cookie中, ServerID can be defined behind a cookie ServerID rewrite #负载均衡的方式, roundrobin mean mode balance Roundrobin #每次请求完毕后主动关闭http通道, Ha-proxy does not support keep-alive mode option Httpclose #服务器定义cookie 1 means ServerID is web1, Check Inter is Heartbeat frequency server web1 192.168.12.2:80 cookie web1 Check weight 1 minconn 1 Maxconn 8000 check Inter 5000 Server web2 192.168.12.3:80 Cookie web2 Check weight 1 minconn 1 Maxconn 8000 check Inter 5000
Haproxy Load Balancer Configuration Example