- mode health
该模式用于健康检查,tcp层面的,只返回OK,如下:
- stats
- 通过http页面查看状态:
1234567listen statusbind *:3127mode httpstats enablestats uri /stats realm HAProxy\ Statisticsstats auth statsadmin:password - 通过tcp socket查看状态:
1stats socket *:3126 #写在global中就可以
这个socket也可以是一个unix socket:(或者同时写两个都是可以的)
1stats socket /var/lib/haproxy/stats #目录要事先创建好
使用nc也行:
tcp(或unix模式)有很多命令可以使用
- 一个一般的配置
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283globallog 127.0.0.1 local2chroot /var/lib/haproxypidfile /var/run/haproxy.pidmaxconn 4000user haproxygroup haproxydaemon# turn on stats unix socketstats socket /var/lib/haproxy/statsstats socket *:3126defaultsmode httplog globaloption dontlognullretries 3timeout http-request 10stimeout queue 1mtimeout connect 10stimeout client 1mtimeout server 1mtimeout http-keep-alive 10stimeout check 10smaxconn 30000resolvers dnsnameserver svr1 172.16.162.194:53listen statusbind *:3127mode httpstats enablestats hide-versionstats uri /stats realm HAProxy\ Statisticsstats auth statsadmin:passwordlisten http_healthbind *:3129mode healthlisten http_tunbind *:3128mode httpoption http-tunneldefault_backend http_tun_backendbackend http_tun_backendmode httpacl acl_baidu req.hdr(host) -i www.baidu.comuse-server svr_baidu if acl_baiduserver svr_baidu www.baidu.com:80 resolvers dnslisten http_proxybind *:80mode httpdefault_backend http_backendbackend http_backendmode httpacl acl_baidu req.hdr(host) -i www.baidu.comacl acl_beebank req.hdr(host) -i www.beebank.comuse-server svr_baidu if acl_baiduuse-server svr_beebank if acl_beebankserver svr_baidu www.baidu.com:80 resolvers dnsserver svr_beebank www.beebank.com:80 resolvers dnslisten ssl_proxybind 127.0.0.1:443mode tcpdefault_backend ssl_backendbackend ssl_backendtcp-request inspect-delay 5stcp-request content accept if { req_ssl_hello_type 1 }acl acl_baidu req_ssl_sni -i www.baidu.comacl acl_beebank req_ssl_sni -i www.beebank.comuse-server svr_baidu if acl_baiduuse-server svr_beebank if acl_beebankserver svr_baidu www.baidu.com:443 resolvers dnsserver svr_beebank www.beebank.com:443 resolvers dns
- 通过http页面查看状态: