HAProxy 的 server 参数和 stats 相关参数详解
1、实验环境及基础配置请参考如下博客
HAProxy 简单示例及 HAProxy_Log 的简单配置
HAProxy Balance 调度算法详解
1.1 实验拓扑
2、HAProxy Server 参数
2.1 官方文档说明
2.2 常用参数说明
## server <name> <address>[:[port]] [param*]
## 定义后端主机的各服务器及其选项
## server <name> <address>[:port] [settings ...]
## default-server [settings ...]
## <name> # 服务器在haproxy上的内部名称;出现在日志及警告信息中
## <address> # 服务器地址,支持使用主机名
## [:[port]] # 端口映射;省略时,表示同bind中绑定的端口
## [param*] # 参数
## maxconn <maxconn> # 当前server的最大并发连接数
## backlog <backlog> # 当前server的连接数达到上限后的后援队列长度
## backup # 设定当前server为备用服务器
## check # 对当前server做健康状态检测
## addr # 检测时使用的IP地址
## port # 针对此端口进行检测
## inter <delay> # 连续两次检测之间的时间间隔,默认为2000ms
## rise <count> # 连续多少次检测结果为“成功”才标记服务器为可用;默认为2
## fall <count> # 连续多少次检测结果为“失败”才标记服务器为不可用;默认为3
## 注意:option httpchk,"smtpchk", "mysql-check", "pgsql-check" and ##
## "ssl-hello-chk" 用于定义应用层检测方法 ##
## cookie <value> # 为当前server指定其cookie值,用于实现基于cookie的会话黏性
## disabled # 标记为不可用
## on-error <mode> # 后端服务故障时的行动策略
## - fastinter: force fastinter
## - fail-check: simulate a failed check, also forces fastinter (default)
## - sudden-death: simulate a pre-fatal failed health check, one more failed check will mark a server down, forces fastinter
## - mark-down: mark the server immediately down and force fastinter
## redir <prefix> # 将发往此server的所有GET和HEAD类的请求重定向至指定的URL
## weight <weight> # 权重,默认为1
3、HAProxy stats 相关参数
## stats enable # 启用统计页;基于默认的参数启用 stats page
## - stats uri : /haproxy?stats
## - stats realm : "HAProxy Statistics"
## - stats auth : no authentication
## - stats scope : no restriction
## stats auth <user>:<passwd> # 认证时的账号和密码,可使用多次
## stats realm <realm> # 认证时的 realm
## stats uri <prefix> # 自定义 stats page uri
## stats refresh <delay> # 设定自动刷新时间间隔
## stats admin {
if | unless } <cond> # 启用stats page中的管理功能
3.1 HAProxy stats 相关参数配置示例
## stats enable # 启用基于程序编译时默认设置的统计报告,不能用于"frontend"区段
## stats uri # /haproxy?stats
## stats realm # "HAProxy Statistics"
## stats auth # no authentication
## stats scope # no restriction
## 尽管"stats enable"一条就能够启用统计报告,但还是建议设定其它所有的参数,以免依赖于默认设定而带来非预期后果
backend public_www
server websrv1 172.16.100.11:80
stats enable
stats hide-version # 启用统计报告并隐藏HAProxy版本报告,不能用于"frontend"区段
stats scope .
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics # stats auth身份认证时的提示信息。设置的提示信息中,如果有空白字符,则需要转义。仅在与"stats auth"配合使用时有意义
stats auth statsadmin:password # 启用带认证的统计报告功能并授权一个用户帐号和对应的密码(明文)。也就是说,想要查看统计报告需要提供身份和密码。不能用于"frontend"区段。
stats auth statsmaster:password
## stats admin # 满足指定条件时启用统计报告页面的管理功能,它允许通过web接口启用或禁用后端服务器
## stats admin {
if | unless } <cond>
## 限制仅能在本机打开报告页面时启用管理功能
backend stats_localhost
stats enable
stats admin if LOCALHOST
## 定义了仅允许通过认证的用户使用管理功能
backend stats_auth
stats enable
stats auth haproxyadmin:password
stats admin if TRUE
listen stats
bind :9099
stats enable
stats realm HAPorxy\ Stats\ Page
stats auth admin:admin
stats admin if TRUE
4、其它参数
## default_backend <backend> # 设定默认的backend,用于frontend中
## default-server [param*] # 为backend中的各server设定默认选项;
## maxconn <conns> # 为指定的frontend定义其最大并发连接数;默认为2000
Fix the maximum number of concurrent connections on a frontend.
## mode {
tcp|http|health } # 定义haproxy的工作模式;
## tcp # 基于layer4实现代理;可代理mysql, pgsql, ssh, ssl等协议
## http # 仅当代理的协议为http时使用
## health # 工作为健康状态检查的响应模式,当连接请求到达时回应“OK”后即断开连接
## mode tcp 示例 ##
listen ssh
bind :22022
balance leastconn
mode tcp
server sshsrv1 172.16.100.6:22 check
server sshsrv2 172.16.100.7:22 check
## cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ] [ postonly ] [ preserve ] [ httponly ] [ secure ] [