url_param:对用户请求的uri的部分中的参数的值作hash计算,并由服务器总权重相除以后派发至某挑出的服务器;通常用于追踪用户,以确保来自同一个用户的请求始终发往同一个Backend Server;
hdr():对于每个http请求,此处由指定的http首部将会被取出做hash计算; 并由服务器总权重相除以后派发至某挑出的服务器;没有有效值的会被轮询调度;
hdr(Cookie)
rdp-cookie
rdp-cookie()
hash-type:哈希算法
hash-type
map-based:除权取余法,哈希数据结构是静态的数组;
consistent:一致性哈希,哈希数据结构是一个树;
is the hash function to be used : 哈希函数
sdbm
djb2
wt6
hdr算法匹配报文字段请求(这里匹配的是浏览器)
addr :检测时使用的IP地址;
port :针对此端口进行检测;
inter :连续两次检测之间的时间间隔,默认为2000ms;
rise :连续多少次检测结果为“成功”才标记服务器为可用;默认为2;
fail :连续多少次检测结果为“失败”才标记服务器为不可用;默认为3;
注意:option httpchk,"smtpchk", "mysql-check", "pgsql-check" and "ssl-hello-chk" 用于定义应用层检测方法;
cookie :为当前server指定其cookie值,用于实现基于cookie的会话黏性;
disabled:标记为不可用;一般用来做发布
on-error :后端服务故障时的行动策略;
- 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 :将发往此server的所有GET和HEAD类的请求重定向至指定的URL;
- stats uri : /haproxy?stats 访问页默认地址,支持重写
- stats realm : "HAProxy Statistics"
- stats auth : no authentication
- stats scope : no restriction
示例
maxconn :为指定的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”后即断开连接;
例子:
-i : 在子串匹配时候忽略大小写
-m : 使用特定匹配模式(很少使用)
-n : 忽略dns做名称解析
-u : 要求ACL使用唯一名称
-- : force end of flags. Useful when a string looks like one of the flags.
[operator]
匹配整数值:eq、ge、gt、le、lt
匹配字符串:
- exact match (-m str) : the extracted string must exactly match the patterns ;
- substring match (-m sub) : the patterns are looked up inside the extracted string, and the ACL matches if any of them is found inside ;
- prefix match (-m beg) : the patterns are compared with the beginning of the extracted string, and the ACL matches if any of them matches.
- suffix match (-m end) : the patterns are compared with the end of the extracted string, and the ACL matches if any of them matches.
- subdir match (-m dir) : the patterns are looked up inside the extracted string, delimited with slashes ("/"), and the ACL matches if any of them matches.
- domain match (-m dom) : the patterns are looked up inside the extracted string, delimited with dots ("."), and the ACL matches if any of them matches.
acl作为条件时的逻辑关系:
- AND (implicit)
- OR (explicit with the "or" keyword or the "||" operator)
- Negation with the exclamation mark ("!")
if invalid_src invalid_port 要求同时满足
if invalid_src || invalid_port 或表示
if ! invalid_src invalid_port 取反,不满足第一个但是满足第二个
:
dst : ip 目标ip或者范围
dst_port : integer 目标端口或范围
src : ip 源ip或者范围
src_port : integer 源端口后缀范围
acl invalid_src src 172.16.200.2
path : string 七层检查
/path;
path : exact string match 精确匹配
path_beg : prefix match 前缀匹配
path_dir : subdir match 子串匹配
path_dom : domain match 子域匹配
path_end : suffix match 路径后缀匹配
path_len : length match 长度匹配
path_reg : regex match 正则匹配
path_sub : substring match 子串匹配
示例
path_beg /images/ 除去ip:port之后以/images/开头
path_end .jpg .jpeg .png .gif url以jpg jpeg png gif后缀的文件
path_reg ^/images.*\.jpeg$ images开头 jpeg结尾
path_sub image
path_dir jpegs
path_dom ilinux
/images/jpegs/20180312/logo.jpg
url : string 对url进行匹配
url : exact string match
url_beg : prefix match
url_dir : subdir match
url_dom : domain match
url_end : suffix match
url_len : length match
url_reg : regex match
url_sub : substring match
req.hdr([[,]]) : string
hdr([[,]]) : exact string match
hdr_beg([[,]]) : prefix match
hdr_dir([[,]]) : subdir match
hdr_dom([[,]]) : domain match
hdr_end([[,]]) : suffix match
hdr_len([[,]]) : length match
hdr_reg([[,]]) : regex match
hdr_sub([[,]]) : substring match