listen web-proxy 192.168.10.128:8000
mode http
option httpchk /index.html
balance roundrobin ##算法
server web1 192.168.10.129:80 cookie server01 check inter 2000 rise 2 fall 3
server web2 192.168.10.130:80 cookie server02 check inter 2000 rise 3 fall 3
##服务器定义(check指健康状况检查,inter 2000指检测频率;rise 2指从离线状态转换至正常状态需要成功检查的次数;fall 3指失败3次即认为服务器不可用)
listen status ##监控页面设置
mode http ##http的7层模式
bind 0.0.0.0:1080 ##监听端口
stats enable
stats hide-version ##隐藏统计页面上的HAproxy版本信息
stats uri /haproxyadmin ##监控页面URL
stats auth admin:admin ##监控页面用户名和密码
stats admin if TRUE ##手工启用、禁用后端服务器
错误:
1
2
3
4
[WARNING] 286/001645 (41708) : parsing [/etc/haproxy/haproxy.cfg:21]: keyword 'redispatch' is deprecated in favor of 'option redispatch', and will not be supported by future versions.
[WARNING] 286/001645 (41708) : parsing [/etc/haproxy/haproxy.cfg:23] : the 'contimeout' directive is now deprecated in favor of 'timeout connect', and will not be supported in future versions.
[WARNING] 286/001645 (41708) : parsing [/etc/haproxy/haproxy.cfg:24] : the 'clitimeout' directive is now deprecated in favor of 'timeout client', and will not be supported in future versions.
[WARNING] 286/001645 (41708) : parsing [/etc/haproxy/haproxy.cfg:25] : the 'srvtimeout' directive is now deprecated in favor of 'timeout server', and will not be supported in future versions.
解决:根据提示更改相应选项的名称即可
四、配置日志文件
1
2
3
# vi /etc/rsyslog.conf
local0.* /var/log/haproxy.log
# systemctl restart rsyslog