我有这个HAProxyconfiguration,你可以看到我有很多在backend s重复的东西。 有没有办法摆脱重复,如stats ?
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice daemon maxconn 2000 defaults log global mode http option httplog option dontlognull retries 3 option redispatch timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend http-in bind *:80 acl url_a path_reg ^\/a$|\/a\/ use_backend webservers_a if url_a acl url_b path_reg ^\/b$|\/b\/ use_backend webservers_b if url_b default_backend webservers_main backend webservers_main mode http stats enable stats auth admin:admin stats uri /haproxy?stats balance roundrobin option httpchk option forwardfor option http-server-close server web1 192.168.50.21:80 maxconn 32 check backend webservers_a mode http stats enable stats auth admin:admin stats uri /haproxy?stats balance roundrobin option httpchk option forwardfor option http-server-close server web2 192.168.50.22:80 maxconn 32 check backend webservers_b mode http stats enable stats auth admin:admin stats uri /haproxy?stats balance roundrobin option httpchk option forwardfor option http-server-close server web3 192.168.50.23:80 maxconn 32 check
你可以在你的configuration文件中添加如下内容:
listen stats bind ${PRIVATE_IP}:${PORT} stats enable stats uri /stats stats auth admin:admin
我假设以下几点:
你不想把你的stats暴露给公众。 如果不是这种情况,只需将您的统计信息移入现有的frontend指令。
将${PRIVATE_IP}replace${PRIVATE_IP}您计算机上可用的私有IP(或为此设置一个), ${PORT}replace为未使用的端口(例如8080 。
注意事项:如果您在统计指令中使用不同于80端口,则必须通过指定url的端口来调用您的stats页面。 为了防止和规避:
frontend绑定到${PUBLIC_IP}:80 ,将您的listen stats部分绑定到${PRIVATE_IP}:80 。