技术标签: linux运维
在Haproxy中的代理的配置包括4个模块,defaults、listen、frontend、backend。
defaults:用于为所有其它配置段提供默认参数,listen、frontend、backend将使用defaults中的设置,如果想通的参数被重复设置,那么listen、frontend、backend的优先级高于defaults.
frontend:监听客户端的链接。
backend:代理的后端服务器。
listen:包括监听客户端和代理的后端服务器,是一个完整的代理的模块,通常使用在tcp的模式中。
Tips 1:所有的代理名称是由大小字母、数字、:、-、_ 组成,且不区分大小写。
Tips 2:如果使用相同的代理名称,那么使用haproxy -f [confFile] -c 命令检查,会报错。
acl invalid_src src 0.0.0.0/7 224.0.0.0/3
acl invalid_src src_port 0:1023
acl local_dst hdr(host) -i localhost
backlog
防止SYN洪水攻击,解决方案是加大SYN backlog值,默认情况haproxy传递frontend中的maxconn。最大值是32768,这里可以查阅SYN Flood攻击的相关资料。可用区域:
defaults | frontend | listen | backend
yes | yes | yes | no
参数:
conns 挂起连接数量,取决于操作系统。
balance [ ]
balance url_param [check_post]
定义后端使用的负载算法。可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
1、 roundrobin:表示简单的轮询,每个服务器根据权重轮流使用,在服务器的处理时间平均分配的情况下这是最流畅和公平的算法。该算法是动态的,对于实例启动慢的服务器权重会在运行中调整。
2、static-rr:每个服务器根据权重轮流使用,类似roundrobin,但它是静态的,意味着运行时修改权限是无效的。另外,它对服务器的数量没有限制。该算法一般不用;
3、first:可用连接槽的第一个服务器接收连接。并且在第一个服务器恢复之后,能够主动切回来,对于MySQL主主代理来说,绝对是一个福音。
4、 leastconn:连接数最少的服务器优先接收连接。leastconn建议用于长会话服务,例如LDAP、SQL、TSE等,而不适合短会话协议。如HTTP.该算法是动态的,对于实例启动慢的服务器权重会在运行中调整。
5、source:对请求源IP地址进行哈希,用可用服务器的权重总数除以哈希值,根据结果进行分配。只要服务器正常,同一个客户端IP地址总是访问同一个服务器。如果哈希的结果随可用服务器数量而变化,那么客户端会定向到不同的服务器;该算法一般用于不能插入cookie的Tcp模式。它还可以用于广域网上为拒绝使用会话cookie的客户端提供最有效的粘连;该算法默认是静态的,所以运行时修改服务器的权重是无效的,但是算法会根据“hash-type”的变化做调整。
6、uri:表示根据请求的URI左端(问号之前)进行哈希,用可用服务器的权重总数除以哈希值,根据结果进行分配。只要服务器正常,同一个URI地址总是访问同一个服务器。一般用于代理缓存和反病毒代理,以最大限度的提高缓存的命中率。该算法只能用于HTTP后端;该算法一般用于后端是缓存服务器;该算法默认是静态的,所以运行时修改服务器的权重是无效的,但是算法会根据“hash-type”的变化做调整。
7、url_param:在HTTP GET请求的查询串中查找中指定的URL参数,基本上可以锁定使用特制的URL到特定的负载均衡器节点的要求;该算法一般用于将同一个用户的信息发送到同一个后端服务器;该算法默认是静态的,所以运行时修改服务器的权重是无效的,但是算法会根据“hash-type”的变化做调整。
8、hdr(name):在每个HTTP请求中查找HTTP头,HTTP头将被看作在每个HTTP请求,并针对特定的节点;如果缺少头或者头没有任何值,则用roundrobin代替;该算法默认是静态的,所以运行时修改服务器的权重是无效的,但是算法会根据“hash-type”的变化做调整。
9、rdp-cookie(name):为每个进来的TCP请求查询并哈希RDP cookie;该机制用于退化的持久模式,可以使同一个用户或者同一个会话ID总是发送给同一台服务器。如果没有cookie,则使用roundrobin算法代替;该算法默认是静态的,所以运行时修改服务器的权重是无效的,但是算法会根据“hash-type”的变化做调整。
balance roundrobin
balance url_param userid
balance url_param session_id check_post 64
balance hdr(User-Agent)
balance hdr(host)
balance hdr(Host) use_domain_only
listen http_proxy
bind :80,:443
bind 10.0.0.1:10080,10.0.0.1:10443
bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy
listen http_https_proxy
bind :80
bind :443 ssl crt /etc/haproxy/site.pem
listen http_https_proxy_explicit
bind ipv6@:80
bind ipv4@public_ssl:443 ssl crt /etc/haproxy/site.pem
bind unix@ssl-frontend.sock user root mode 600 accept-proxy
listen external_bind_app1
bind "fd@${FD_APP1}"
listen app_ip1
bind 10.0.0.1:80
bind-process odd
listen app_ip2
bind 10.0.0.2:80
bind-process even
listen management
bind 10.0.0.3:80
bind-process 1 2 3 4
listen management
bind 10.0.0.4:80
bind-process 1-4
block { if | unless }
capture cookie len
在请求和响应中捕获并记录一个cookie。如果头中没有此cookie将会记录“-”。最大capture的长度是tune.http.cookielen。默认63个字符。
参数说明:
name 是cookie名称的开头,为了精确匹配cookie可使用“=”
length 记录的最大长度,包括cookiename,如果长度超限将被截取。
可用区域:
defaults | frontend | listen | backend
no | yes | yes | no
capture cookie ASPSESSION len 32
capture request header Host len 15
capture request header X-Forwarded-For len 15
capture request header Referer len 15
capture response header Content-length len 9
capture response header Location len 15
compression algo deflate
compression type text/html text/plain
cookie JSESSIONID prefix
cookie SRV insert indirect nocache
cookie SRV insert postonly indirect
cookie SRV insert indirect nocache maxidle 30m maxlife 8h
default-server inter 1000 weight 13
use_backend dynamic if url_dyn
use_backend static is usl_caa_url_img extension_img
default_backend dynamic
use_backend dynamic if url_dyn
use_backend static if url_css url_img extension_img
default_backend dynamic
# intercept incoming TLS requests based on the SNI field
use-server www if {
req_ssl_sni -i www.example.com }
server www 192.168.0.1:443 weight 0
use-server mail if {
req_ssl_sni -i mail.example.com }
server mail 192.168.0.1:587 weight 0
use-server imap if {
req_ssl_sni -i imap.example.com }
server mail 192.168.0.1:993 weight 0
# all the rest is forwarded to this server
server default 192.168.0.2:443 check
description
描述字符串,将在haproxy stats 中展示相关的描述。
可用区域:
defaults | frontend | listen | backend
no | yes | yes | yes
disabled
禁用代理,前端或后端。
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | yes
“disable”关键字用于禁用实例,比如临时停用某个服务,实例会被创建,配置也会被检查,但是将会被标记为stopped。它将不会接收任何的流量和健康检查会日志。将所有都禁用则可在default区域中配置disable
enabled
启用代理,前端或后端。
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | yes
当defaults中设置为disable,可使用enable来启用
dispatch {address}:{port}
设置默认服务器地址
可用区域:
defaults | frontend | listen | backend
no | no | yes | yes
“dispatch”定义了一个默认的服务,当其他的服务都不能进行连接,建议不要使用它。
dynamic-cookie-key
给后端设置动态cookie 秘钥。
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
当动态cookie被启用,则每台服务都会使用IP地址的hash,port,和secret key创建动态cookie。
errorfile
返回文件内容而不是由HAProxy生成的错误
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | yes
参数说明:
code: 是http状态码,目前支持:200,400,403,405,425,429,500,502,503,504
file:文件包含完整的http响应内容,建议使用“.http”后缀,并使用绝对路径。
errorloc
errorloc302
errorloc303
将HTTP重定向返回到URL而不是由HAProxy生成的错误。
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | yes
#可设置在globals、listen、frontend、backend
errorfile 400 /etc/haproxy/errorfiles/400badreq.http
errorfile 408 /dev/null # work around Chrome pre-connect bug
errorfile 403 /etc/haproxy/errorfiles/403forbid.http
errorfile 503 /etc/haproxy/errorfiles/503sorry.http
listen
bind *:80
filter trace name BEFORE-HTTP-COMP
filter compression
filter trace name AFTER-HTTP-COMP
compression algo gzip
compression offload
server srv1 192.168.0.1:80
backend dynamic
fullconn 10000
server srv1 dyn1:80 minconn 100 maxconn 1000
server srv2 dyn2:80 minconn 100 maxconn 1000
grace
hash-balance-factor
指定一致性散列hash负载,将设置为0(默认值)将禁用此功能。
可用区域:
defaults | frontend | listen | backend
yes | no | no | yes
hash-type
指定用于将哈希映射到服务器的方法
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
method可用值:map-based、consistent、
function可用值:sdbm、djb2、wt6、crc32
modifier可用值:avalanche、
http-check disable-on-404
在HTTP/404响应健康检查时启用维护模式
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
如果配置此选项,检查后端返回404的服务将会被移出负载。但是仍然可以接收persistent 连接,它提供了一个很方便的方式去停用服务。
http-check expect [!]
使HTTP健康检查考虑回应内容或特定状态代码
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
参数说明:
match: 是从响应中查找模式的关键字,可用:status,rstatus,string,rstring
pattern: 查找模式。
默认情况下,“option httpchk”认为响应码为2xx和3xx表示正常,其他表示不可用,当启用“http-check expect”它会自定义什么是可用或不可用,
需要注意响应大小被限制为“tune.chksize”默认为16384 bytes。同时该模式不支持keep-alive,他会自动添加头“connection:close”
# only accept status 200 as valid
http-check expect status 200
# consider SQL errors as errors
http-check expect ! string SQL\ Error
# consider status 5xx only as errors
http-check expect ! rstatus ^5
# check that we have a correct hexadecimal tag before /html
http-check expect rstring <!--tag:[0-9a-f]*</html>
X-Haproxy-Server-State: UP 2/3; name=bck/srv2;node=lb1; weight=1/2;scur=13/22; qcur=0
acl nagios src 192.168.129.3
acl local_net src 192.168.0.0/16
acl auth_ok http_auth(L1)
http-request allow if nagios
http-request allow if local_net auth_ok
http-request auth realm Gimme if local_net auth_ok
http-request deny
acl key req.hdr(X-Add-Acl-Key) -m found
acl add path /addacl
acl del path /delacl
acl myhost hdr(Host) -f myhost.lst
http-request add-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key add
http-request del-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key del
acl value req.hdr(X-Value) -m found
acl setmap path /setmap
acl delmap path /delmap
use_backend bk_appli if {
hdr(Host),map_str(map.lst) -m found }
http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if setmap value
http-request del-map(map.lst) %[src] if delmap
acl auth_ok http_auth_group(L1) G1
http-request auth unless auth_ok
resolvers mydns
nameserver local 127.0.0.53:53
nameserver google 8.8.8.8:53
timeout retry 1s
hold valid 10s
hold nx 3s
hold other 3s
hold obsolete 0s
accepted_payload_size 8192
frontend fe
bind 10.42.0.1:80
http-request do-resolve(txn.myip,mydns,ipv4) hdr(Host),lower
http-request capture var(txn.myip) len 40
# return 503 when the variable is not set,
# which mean DNS resolution error
use_backend b_503 unless {
var(txn.myip) -m found }
default_backend be
backend b_503
# dummy backend used to return 503.
# one can use the errorfile directive to send a nice
# 503 error page to end users
backend be
# rule to prevent HAProxy from reconnecting to services
# on the local network (forged DNS name used to scan the network)
http-request deny if {
var(txn.myip) -m ip 127.0.0.0/8 10.0.0.0/8 }
http-request set-dst var(txn.myip)
server clear 0.0.0.0:0
http-request replace-header Cookie foo=([^;]*);(.*) foo=\1;ip=%bi;\2
# applied to:
Cookie: foo=foobar; expires=Tue, 14-Jun-2016 01:40:45 GMT;
# outputs:
Cookie: foo=foobar;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT;
http-request replace-header User-Agent curl foo
# applied to:
User-Agent: curl/7.47.0
# outputs:
User-Agent: foo
# prefix /foo : turn /bar?q=1 into /foo/bar?q=1 :
http-request replace-uri (.*) /foo\1
# suffix /foo : turn /bar?q=1 into /bar/foo?q=1 :
http-request replace-uri ([^?]*)(\?(.*))? \1/foo\2
# strip /foo : turn /foo/bar?q=1 into /bar?q=1
http-request replace-uri /foo/(.*) /\1
# or more efficient if only some requests match :
http-request replace-uri /foo/(.*) /\1 if {
url_beg /foo/ }
http-request replace-value X-Forwarded-For ^192\.168\.(.*)$ 172.16.\1
# applied to:
X-Forwarded-For: 192.168.10.1, 192.168.13.24, 10.0.0.37
# outputs:
X-Forwarded-For: 172.16.10.1, 172.16.13.24, 10.0.0.37
http-request set-dst hdr(x-dst)
http-request set-dst dst,ipmask(24)
http-request set-dst-port hdr(x-port)
http-request set-dst-port int(4000)
http-request set-header X-Haproxy-Current-Date %T
http-request set-header X-SSL %[ssl_fc]
http-request set-header X-SSL-Session_ID %[ssl_fc_session_id,hex]
http-request set-header X-SSL-Client-Verify %[ssl_c_verify]
http-request set-header X-SSL-Client-DN %{
+Q}[ssl_c_s_dn]
http-request set-header X-SSL-Client-CN %{
+Q}[ssl_c_s_dn(cn)]
http-request set-header X-SSL-Issuer %{
+Q}[ssl_c_i_dn]
http-request set-header X-SSL-Client-NotBefore %{
+Q}[ssl_c_notbefore]
http-request set-header X-SSL-Client-NotAfter %{
+Q}[ssl_c_notafter]
http-request set-path /%[hdr(host)]%[path]
http-request set-query %[query,regsub(%3D,=,g)]
http-request set-src hdr(x-forwarded-for)
http-request set-src src,ipmask(24)
http-request set-src-port hdr(x-port)
http-request set-src-port int(4000)
http-request set-var(req.my_var) req.fhdr(user-agent),lower
http-request send-spoe-group [ { if | unless } ]
发送spoe消息
http-request silent-drop [ { if | unless } ]
立即停掉客户端请求,但是连接仍在。
http-request tarpit [deny_status ] [ { if | unless } ]
阻止请求,无返回直到超时。可用于阻止爬虫
http-request track-sc0 [table
] [ { if | unless } ]http-request track-sc1 [table
] [ { if | unless } ]http-request track-sc2 [table
] [ { if | unless } ]http-request unset-var() [ { if | unless } ]
取消变量
http-request unset-var(req.my_var)
http-request use_service prometheus-exporter if {
path /metrics}
直到ssl握手完成才进行下一步
acl key_acl res.hdr(X-Acl-Key) -m found
acl myhost hdr(Host) -f myhost.lst
http-response add-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
http-response del-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
acl value res.hdr(X-Value) -m found
use_backend bk_appli if {
hdr(Host),map_str(map.lst) -m found }
http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value
http-response del-map(map.lst) %[src] if ! value
http-response set-status 503
http-response set-status 503 reason "slow down"
http-response set-tos [ { if | unless } ]
http-response set-var() [ { if | unless } ]
http-response silent-drop [ { if | unless } ]
http-response track-sc0 [table
] [ { if | unless } ]http-response track-sc1 [table
] [ { if | unless } ]http-response track-sc2 [table
] [ { if | unless } ]http-response unset-var() [ { if | unless } ]
http-reuse { never | safe | aggressive | always }
声明请求之间可以共享闲置的HTTP连接
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
默认使用safe策略,
可用策略:
1、never: 空闲连接不共享,
2、safe: 默认策略,一个session的请求只会使用它自己的连接,它的子请求可能分配到其他已存在的连接上,这确保了万一当请求发送后服务关闭了连接,客户端可尝试重试,这和keep-alive类似。
3、aggressive:
4、always
http-send-name-header [
id :
proxy 唯一标识
可用区域:
defaults | frontend | listen | backend
no | yes | yes | yes
ignore-persist { if | unless }
声明某种条件下忽略持久性
可用区域:
defaults | frontend | listen | backend
no | no | yes | yes
默认,当cookie persistent 开启,每个包含cookie的请求都会无条件的持久。
acl url_static path_beg /static /images /img /css
acl url_static path_end .gif .png .jpg .css .js
ignore-persist if url_static
global
stats socket /tmp/socket
server-state-file /tmp/server_state
defaults
load-server-state-from-file global
backend bk
server s1 127.0.0.1:22 check weight 11
server s2 127.0.0.1:22 check weight 12
socat /tmp/socket - <<< "show servers state" > /tmp/server_state
log global
log stdout format short daemon # send log to systemd
log stdout format raw daemon # send everything to stdout
log stderr format raw daemon notice # send important events to stderr
log 127.0.0.1:514 local0 notice # only send important events
log 127.0.0.1:514 local0 notice notice # same but limit output level
log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
log-format
指定用于流量日志的日志格式字符串
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | no
log-format-sd
指定RFC5424结构化数据日志格式字符串
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | no
log-tag
指定要用于所有传出日志的日志标记
可用区域:
defaults | frontend | listen | backend
yes | yes | yes | yes
max-keep-alive-queue
设置维护保持连接的最大服务器队列大小
可用区域:
defaults | frontend | listen | backend
yes | no | yes | yes
保持会话将尝试复用服务器的连接,但有时候会适得其反,例如一个服务有很多的连接而其他的服务确很闲。
默认值为-1,表示没有限制大小,
max-session-srv-conns
连接客户端的最大闲置session连接数。默认5
maxconn
设置最大的连接数,默认是2000
defaults | frontend | listen | backend
yes | yes | yes | no
mode { tcp|http|health }
defaults | frontend | listen | backend
yes | yes | yes | yes
monitor fail { if | unless }
添加条件以报告监视器HTTP请求的失败。
defaults | frontend | listen | backend
no | yes | yes | no
frontend www
mode http
acl site_dead nbsrv(dynamic) lt 2
acl site_dead nbsrv(static) lt 2
monitor-uri /site_alive
monitor fail if site_dead
monitor-net
声明一个限于监视请求的源网络
defaults | frontend | listen | backend
yes | yes | yes | no
monitor-uri
拦截外部组件的监视请求使用的URI
defaults | frontend | listen | backend
yes | yes | yes | no
# addresses .252 and .253 are just probing us.
frontend www
monitor-net 192.168.0.252/31
# Use /haproxy_test to report haproxy's status
frontend www
mode http
monitor-uri /haproxy_test
option abortonclose
no option abortonclose
如果设置了此参数,可以在服务器负载很高的情况下,自动结束掉当前队列中处理时间比较长的连接。
option accept-invalid-http-request
no option accept-invalid-http-request
启用或禁用轻松解析HTTP请求
defaults | frontend | listen | backend
yes | yes | yes | no
option accept-invalid-http-response
no option accept-invalid-http-response
启用或禁用缓解HTTP响应解析
option allbackups
no option allbackups
一次使用所有备份服务器,或仅使用第一个备份服务器
defaults | frontend | listen | backend
yes | no | yes | yes
默认当正常的服务器down掉以后使用第一个backup服务器。有时需要使用多个。
option checkcache
no option checkcache
分析所有服务器响应,并使用可缓存的Cookie阻止响应
defaults | frontend | listen | backend
yes | no | yes | yes
option clitcpka
no option clitcpka
启用或禁用在客户端发送TCP Keepalive报文
defaults | frontend | listen | backend
yes | yes | yes | no
option contstats
启用连续流量统计更新
defaults | frontend | listen | backend
yes | yes | yes | no
option dontlog-normal
no option dontlog-normal
启用或禁用日志记录正常,成功的连接
defaults | frontend | listen | backend
yes | yes | yes | no
option dontlognul
no option dontlognull
启用或禁用日志记录的空连接
defaults | frontend | listen | backend
yes | yes | yes | no
option forceclose
no option forceclose
响应传输后启用或禁用活动连接关闭。
option forwardfor [ except ] [ header ] [ if-none ]
在请求头中插入x-forwarded-for
defaults | frontend | listen | backend
yes | yes | yes | yes
参数说明:
except network :当匹配此源地址的时候不执行
name:自定义头名称
frontend www
mode http
option forwardfor except 127.0.0.1
backend www
mode http
option forwardfor header X-Client
option h1-case-adjust-bogus-client
no option h1-case-adjust-bogus-client
开启或关闭发送到伪客户端的头部大小写调整
defaults | frontend | listen | backend
yes | yes | yes | no
头部名称并没有标准的大小写,它对大小写并不敏感,所以应用中必须处理这种情况,但是一些伪客户端的要求一致,尤其在HTTP/2中头部必须小写,所以haproxy中要求所有的头部都用小写传递,不用管http的版本。
option h1-case-adjust-bogus-server
no option h1-case-adjust-bogus-server
开启或关闭发送到伪服务器的头部大小写调整
defaults | frontend | listen | backend
yes | no | yes | yes
option http-buffer-request
no option http-buffer-request
启用或禁用等待整个HTTP请求正文,然后继续
defaults | frontend | listen | backend
yes | yes | yes | yes
有时候需要等待整个http请求的body内容再进行下一步。
option http-ignore-probes
no option http-ignore-probes
启用或禁用日志记录空连接和请求超时
defaults | frontend | listen | backend
yes | yes | yes | no
option http-keep-alive
no option http-keep-alive
启用或禁用从客户端到服务器的HTTP保持会话
defaults | frontend | listen | backend
yes | yes | yes | yes
默认使用该模式,
option http-no-delay
no option http-no-delay
指示系统支持HTTP中的低性能交互延迟
defaults | frontend | listen | backend
yes | yes | yes | yes
不建议使用
option http-pretend-keepalive
no option http-pretend-keepalive
定义haproxy是否会向服务器通告keepalive
defaults | frontend | listen | backend
yes | no | yes | yes
option http-server-close
no option http-server-close
在服务器端启用或禁用HTTP连接
defaults | frontend | listen | backend
yes | yes | yes | yes
haproxy默认使用keep-alive,server-close将会开启服务端关闭连接,而客户端抱持会话,将有利于保留服务器端资源,
option http-use-proxy-header
no option http-use-proxy-header
使用非标准的代理连接
defaults | frontend | listen | backend
yes | yes | yes | no
option httpchk
option httpchk
option httpchk
option httpchk
此选项表示启用HTTP的服务状态检测功能。HAProxy作为一款专业的负载均衡器,它支持对backend部分指定的后端服务节点进行健康检查,以保证在后端backend中某个节点不能服务时,把从frontend端进来的客户端请求分配至backend中其他健康节点上,从而保证整体服务的可用性。
defaults | frontend | listen | backend
yes | no | yes | yes
option httpclose
no option httpclose
此选项表示在客户端和服务器完成一次连接请求后,HAProxy将主动关闭http连接.
defaults | frontend | listen | backend
yes | yes | yes | yes
当完成request和response后haproxy关闭连接,并添加头“connection:close”
option httplog [clf]
开启日志记录http请求,session状态和timers
defaults | frontend | listen | backend
yes | yes | yes | no
参数说明:
clf:如果给出此参数,将使用clf的格式代替默认的http格式
在默认情况下,日志记录的项目很少,只记录source,destination和instance name,此选项将丰富记录内容,包括请求,连接时间,session状态,连接数,和捕获的头或cookie,前端,后端,和服务名,和源地址和端口。
option http_proxy
no option http_proxy
启用或禁用普通HTTP代理模式
defaults | frontend | listen | backend
yes | yes | yes | yes
此模式只工作在传入纯ip地址
option independent-streams
no option independent-streams
设置双向tcp读写单独的超时
defaults | frontend | listen | backend
yes | yes | yes | yes
option ldap-check
使用LDAPv3运行状况检查进行服务器测试
defaults | frontend | listen | backend
yes | no | yes | yes
option external-check
使用外部进程进行服务器健康检查
defaults | frontend | listen | backend
yes | no | yes | yes
option log-health-checks
no option log-health-checks
启用或禁用日志记录健康检查状态更新
defaults | frontend | listen | backend
yes | no | yes | yes
option log-separate-errors
no option log-separate-errors
为非完全成功的连接更改日志级别
defaults | frontend | listen | backend
yes | yes | yes | no
option logasap
no option logasap
启用或禁用HTTP请求的早期记录
defaults | frontend | listen | backend
yes | yes | yes | no
option mysql-check [ user [ post-41 ] ]
使用MySQL健康检查进行服务器测试
defaults | frontend | listen | backend
yes | no | yes | yes
option nolinger
no option nolinger
关闭后启用或禁用即时会话资源清理
defaults | frontend | listen | backend
yes | yes | yes | yes
当客户端和服务端不寻常的关闭了 连接
sessio将会超时并关闭,该选项将强制系统回收资源。不建议使用。
option originalto [ except ] [ header ]
启用将X-Original-To标头插入发送到服务器的请求
defaults | frontend | listen | backend
yes | yes | yes | yes
option persist
no option persist
在下载服务器上启用或禁用强制持久性
defaults | frontend | listen | backend
yes | no | yes | yes
option pgsql-check [ user ]
使用PostgreSQL运行状况检查进行服务器测试
option prefer-last-server
no option prefer-last-server
允许多个负载均衡请求保留在同一台服务器上
defaults | frontend | listen | backend
yes | no | yes | yes
option redispatch
option redispatch
no option redispatch
当连接失败的时候重新分配。
defaults | frontend | listen | backend
yes | no | yes | yes
此参数用于cookie保持的环境中。在默认情况下,HAProxy会将其请求的后端服务器的ServerID插入到cookie中,以保证会话的Session持久性。而如果后端服务器出现故障,客户端的cookie是不会刷新的,这就出现了问题。此时,如果设置此参数,就会将客户端的请求强制定向到另外一个健康的后端服务器上,以保证服务的正常。
option redis-check
使用redis健康检查进行服务器测试
defaults | frontend | listen | backend
yes | no | yes | yes
option socket-stats
为每个套接字收集和提供单独的统计信息。
defaults | frontend | listen | backend
yes | yes | yes | no
option splice-auto
在两个方向上启用或禁用套接字上的自动内核加速
defaults | frontend | listen | backend
yes | yes | yes | yes
option splice-request
套接字上的自动内核加速请求
defaults | frontend | listen | backend
yes | yes | yes | yes
option splice-response
自动内核加速以进行响应
defaults | frontend | listen | backend
yes | yes | yes | yes
option spop-check
使用SPOP健康检查进行服务器测试
defaults | frontend | listen | backend
no | no | no | yes
option srvtcpka
在服务器端发送TCP Keepalive报文
defaults | frontend | listen | backend
yes | no | yes | yes
option ssl-hello-chk
使用SSLv3客户端hello运行状况检查进行服务器测试
defaults | frontend | listen | backend
yes | no | yes | yes
option tcp-check
使用tcp-check send/expect序列进行健康检查
defaults | frontend | listen | backend
yes | no | yes | yes
option tcp-check
tcp-check expect string +OK\ POP3\ ready comment POP\ protocol
option tcp-check
tcp-check comment PING\ phase
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check comment role\ check
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check comment QUIT\ phase
tcp-check send QUIT\r\n
tcp-check expect string +OK
external-check path "/usr/bin:/bin"
listen tse-farm
bind :3389
# wait up to 5s for an RDP cookie in the request
tcp-request inspect-delay 5s
tcp-request content accept if RDP_COOKIE
# apply RDP cookie persistence
persist rdp-cookie
# if server is unknown, let's balance on the same cookie.
# alternatively, "balance leastconn" may be useful too.
balance rdp-cookie
server srv1 1.1.1.1:3389
server srv2 1.1.1.2:3389
listen smtp
mode tcp
bind :25
rate-limit sessions 10
server smtp1 127.0.0.1:1025
] [{if | unless} ]
] [{if | unless} ]
] [{if | unless} ]
当条件满足时进行重定向
defaults | frontend | listen | backend
no | yes | yes | yes
参数说明:
loc:loc值将会替换头部Location的值,
pfx:重定向到url
sch:例如http跳转到https
code:301,302,303,307,308
option选项:
1、drop-query:当应用于prefix 查询参数将会被丢弃。
2、append-slash: 当取消掉查询参数后,在最后添加“/”
3、set-cookie name=value:添加cookie
4、clear-cookie name[=]:清理cookie
acl clear dst_port 80
acl secure dst_port 8080
acl login_page url_beg /login
acl logout url_beg /logout
acl uid_given url_reg /login?userid=[^&]+
acl cookie_set hdr_sub(cookie) SEEN=1
redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set
redirect prefix https://mysite.com if login_page !secure
redirect prefix http://mysite.com drop-query if login_page !uid_given
redirect location http://mysite.com/ if !login_page secure
redirect location / clear-cookie USERID= if logout
acl missing_slash path_reg ^/article/[^/]*$
redirect code 301 prefix / drop-query append-slash if missing_slash
redirect scheme https if !{
ssl_fc }
retries
设置连接后端服务器的失败重试次数,
defaults | frontend | listen | backend
yes | no | yes | yes
retry-on [list of keywords]
自动重连
defaults | frontend | listen | backend
yes | no | yes | yes
参数说明:
keyword:
none:不重试
conn-failure:当连接或ssl握手失败,默认值
empty-response:无返回时
junk-response:当返回并不是完整的http响应
response-timeout:当返回超时
0rtt-reject:当请求被拒绝
status:当某个状态码时
all-retryable-errors:所有错误发生时,包括以上所有
server
[:port] [param*]server first 10.1.1.1:1080 cookie first check inter 1000
server second 10.1.1.2:1080 cookie second check inter 1000
server transp ipv4@
server backup "${SRV_BACKUP}:1080" backup
server www1_dc1 "${LAN_DC1}.101:80"
server www1_dc2 "${LAN_DC2}.101:80"
global
server-state-file-base /etc/haproxy/states
backend bk
load-server-state-from-file
server-template srv 1-3 google.com:80 check
# or
server-template srv 3 google.com:80 check
# would be equivalent to:
server srv1 google.com:80 check
server srv2 google.com:80 check
server srv3 google.com:80 check
backend private
# Connect to the servers using our 192.168.1.200 source address
source 192.168.1.200
backend transparent_ssl1
# Connect to the SSL farm from the client's source address
source 192.168.1.200 usesrc clientip
backend transparent_ssl2
# Connect to the SSL farm from the client's source address and port
# not recommended if IP conntrack is present on the local machine.
source 192.168.1.200 usesrc client
backend transparent_ssl3
# Connect to the SSL farm from the client's source address. It
# is more conntrack-friendly.
source 192.168.1.200 usesrc clientip
backend transparent_smtp
# Connect to the SMTP farm from the client's source address/port
# with Tproxy version 4.
source 0.0.0.0 usesrc clientip
backend transparent_http
# Connect to the servers using the client's IP as seen by previous
# proxy.
source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1)
backend stats_localhost
stats enable
stats admin if LOCALHOST
backend stats_auth
stats enable
stats auth admin:AdMiN123
stats admin if TRUE
userlist stats-auth
group admin users admin
user admin insecure-password AdMiN123
group readonly users haproxy
user haproxy insecure-password haproxy
backend stats_auth
stats enable
acl AUTH http_auth(stats-auth)
acl AUTH_ADMIN http_auth_group(stats-auth) admin
stats http-request auth unless AUTH
stats admin if AUTH_ADMIN
backend pop
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 30m
server s1 192.168.1.1:110
server s2 192.168.1.1:110
backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
# The following form ...
stick on src table pop if !localhost
# ...is strictly equivalent to this one :
stick match src table pop if !localhost
stick store-request src table pop if !localhost
backend pop
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 30m
server s1 192.168.1.1:110
server s2 192.168.1.1:110
backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
# Learn SSL session ID from both request and response and create affinity.
backend https
mode tcp
balance roundrobin
# maximum SSL session ID length is 32 bytes.
stick-table type binary len 32 size 30k expire 30m
acl clienthello req_ssl_hello_type 1
acl serverhello rep_ssl_hello_type 2
# use tcp content accepts to detects ssl client and server hello.
tcp-request inspect-delay 5s
tcp-request content accept if clienthello
# no timeout on response inspect delay by default.
tcp-response content accept if serverhello
# SSL session ID (SSLID) may be present on a client or server hello.
# Its length is coded on 1 byte at offset 43 and its value starts
# at offset 44.
# Match and learn on request if client hello.
stick on payload_lv(43,1) if clienthello
# Learn on response if server hello.
stick store-response payload_lv(43,1) if serverhello
server s1 192.168.1.1:443
server s2 192.168.1.1:443
# Keep track of counters of up to 1 million IP addresses over 5 minutes
# and store a general purpose counter and the average connection rate
# computed over a sliding window of 30 seconds.
stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
option tcp-check
tcp-check connect
tcp-check send GET\ /\ HTTP/1.0\r\n
tcp-check send Host:\ haproxy.1wt.eu\r\n
tcp-check send \r\n
tcp-check expect rstring (2..|3..)
tcp-check connect port 443 ssl
tcp-check send GET\ /\ HTTP/1.0\r\n
tcp-check send Host:\ haproxy.1wt.eu\r\n
tcp-check send \r\n
tcp-check expect rstring (2..|3..)
server www 10.0.0.1 check port 80
# check both POP and IMAP from a single server:
option tcp-check
tcp-check connect port 110
tcp-check expect string +OK\ POP3\ ready
tcp-check connect port 143
tcp-check expect string *\ OK\ IMAP4\ ready
server mail 10.0.0.1 check
# redis check in binary
option tcp-check
tcp-check send-binary 50494e470d0a # PING\r\n
tcp-check expect binary 2b504F4e47 # +PONG
defaults | frontend | listen | backend
no | yes | yes | no
tcp-request content use-service lua.deny {
src -f /etc/haproxy/blacklist.lst }
tcp-request content set-var(sess.my_var) src
tcp-request content unset-var(sess.my_var2)
# Accept HTTP requests containing a Host header saying "example.com"
# and reject everything else.
acl is_host_com hdr(Host) -i example.com
tcp-request inspect-delay 30s
tcp-request content accept if is_host_com
tcp-request content reject
# reject SMTP connection if client speaks first
tcp-request inspect-delay 30s
acl content_present req_len gt 0
tcp-request content reject if content_present
# Forward HTTPS connection only if client speaks
tcp-request inspect-delay 30s
acl content_present req_len gt 0
tcp-request content accept if content_present
tcp-request content reject
# Track the last IP(stick-table type string) from X-Forwarded-For
tcp-request inspect-delay 10s
tcp-request content track-sc0 hdr(x-forwarded-for,-1)
# Or track the last IP(stick-table type ip|ipv6) from X-Forwarded-For
tcp-request content track-sc0 req.hdr_ip(x-forwarded-for,-1)
# track request counts per "base" (concatenation of Host+URL)
tcp-request inspect-delay 10s
tcp-request content track-sc0 base table req-rate
frontend http
# Use General Purpose Counter 0 in SC0 as a global abuse counter
# protecting all our sites
stick-table type ip size 1m expire 5m store gpc0
tcp-request connection track-sc0 src
tcp-request connection reject if {
sc0_get_gpc0 gt 0 }
...
use_backend http_dynamic if {
path_end .php }
backend http_dynamic
# if a source makes too fast requests to this dynamic site (tracked
# by SC1), block it globally in the frontend.
stick-table type ip size 1m expire 5m store http_req_rate(10s)
acl click_too_fast sc1_http_req_rate gt 10
acl mark_as_abuser sc0_inc_gpc0(http) gt 0
tcp-request content track-sc1 src
tcp-request content reject if click_too_fast mark_as_abuser
tcp-request inspect-delay
检查数据的最长等待时间
defaults | frontend | listen | backend
no | yes | yes | yes
tcp-response content [{if | unless} ]
tcp-request session [{if | unless} ]
tcp-response inspect-delay
timeout connect
设置成功连接到一台服务器的最长等待时间,默认单位是毫秒。但是也可以使用其他的时间单位后缀
defaults | frontend | listen | backend
yes | no | yes | yes
timeout http-keep-alive
设置等待新http请求出现的超时时间
timeout http-request
设置完整的http 请求超时时间
defaults | frontend | listen | backend
yes | yes | yes | yes
timeout queue
设置队列连接slot free 的超时时间
defaults | frontend | listen | backend
yes | no | yes | yes
timeout client:
设置连接客户端发送数据时最长等待时间,默认单位是毫秒。但是也可以使用其他的时间单位后缀
defaults | frontend | listen | backend
yes | yes | yes | no
timeout client-fin
为半关闭连接设置客户端超时时间
defaults | frontend | listen | backend
yes | yes | yes | no
timeout server:
设置服务器端回应客户端数据发送的最长等待时间,默认单位是毫秒。但是也可以使用其他的时间单位后缀
defaults | frontend | listen | backend
yes | no | yes | yes
timeout server-fin
timeout tarpit
tarpitted 连接保持时间
defaults | frontend | listen | backend
yes | yes | yes | yes
timeout tunnel
设置客户端和服务端隧道超时时间
timeout check
设置多后端服务器的检测超时时间,默认单位是毫秒。但是也可以使用其他的时间单位后缀
defaults | frontend | listen | backend
yes | no | yes | yes
unique-id-format
产生一个unique id 为每一个请求
defaults | frontend | listen | backend
yes | yes | yes | no
unique-id-header
为请求的header 中添加unique id
use-fcgi-app
定义一个fasetcgi应用作为backend
use-server if
use-server unless
stats refresh:设置 HAProxy 监控统计页面自动刷新的时间。
stats uri:设置 HAProxy 监控统计页面的URL 路径,可随意指定。例如:指定stats uri /haproxy-status,就可以过http://IP:9188/haproxy-status 查看。
stats realm:设置登录 HAProxy 统计页面时密码框上的文本提示信息。
stats auth:设置登录 HAProxy 统计页面的用户名和密码。用户名和密码通过冒号分割。可为监控页面设置多个用户名和密码,每行一个。
stats hide-version:用来隐藏统计页面上 HAProxy 的版本信息。
stats admin if TRUE:通过设置此选项,可以在监控页面上手工启用或禁用后端真实服务器,仅在 haproxy1.4.9 以后版本有效。
文章浏览阅读789次。给c种不同颜色宝石能穿成多少种长度为s的宝石项链(本质不同)Burnside定理的应用:当n为奇数时,有n种翻转,每种翻转都是以一个顶点和该顶点对边的中点对称。有k^(n/2+1)*n种。当n为偶数时,有n种翻转,其中一半是以两个对应顶点,另一半是以两条对边对称。有k^(n/2+1)*n/2+k^(n/2)*n/2种。..._组合数学项链问题
文章浏览阅读575次,点赞2次,收藏7次。第一题标题:迷宫X星球的一处迷宫游乐场建在某个小山坡上。它是由10x10相互连通的小房间组成的。房间的地板上写着一个很大的字母。我们假设玩家是面朝上坡的方向站立,则:L表示走到左边的房间,R表示走到右边的房间,U表示走到上坡方向的房间,D表示走到下坡方向的房间。X星球的居民有点懒,不愿意费力思考。他们更喜欢玩运气类的游戏。这个游戏也是如此!开始的时候,直升机把10..._第八届蓝桥杯c语言a组
文章浏览阅读1.3k次。建议先了解不同协议和网络层的数据包结构。不然,你将无法了解如何做包分组工作,以及这些工具如何使用。出于学习目的,在使用这些工具列表之前,你必须了解不同协议的数据包,包中的不同字段,这些包字段的含义或目的,以及这些包在网络通信中的使用方式。一旦你知道这些事情,你将能够改变这些值,以便你在网络中看到你所需的效果。1. HpingHping是最受欢迎和免费的抓包工具之一。它允许你修改和发送自定义..._tcap包
文章浏览阅读1.5w次。本文介绍了一种面对linux指令“没有那个文件或目录”时的自查和解决方法_没有那个文件或目录
文章浏览阅读462次。{"rules" : { // 定义对象的set存取器属性时,强制定义get "accessor-pairs": 2, // 指定数组的元素之间要以空格隔开(,后面), never参数:[ 之前和 ] 之后不能带空格,always参数:[ 之前和 ] 之后必须带空格 "array-bracket-spacing": [2, "never"], // 在块级作用域外访问块内定义的变量是否报错提示 "block-scoped-var": 0, // if while functi._eslint 参数
文章浏览阅读3.7k次。问题描述:使用anaconda来管理包,十分方便,也可以到达使得python2和python3共存的目的,但当导入anaconda以外的包时,可能会产生一些问题,在近期学习中,由于会用到scikit-learn模块,此模块为python2.7版本的模块,在使用终端通过pip安装时,ppip默认为为python3安装包。对此,可以尝试用pycharm导入此模块:打开pycharm,选择file菜_mac anaconda 配置两个 python
文章浏览阅读1.1k次。背景在 C++11 之前,无论是类模板还是函数模板,都只能按其指定的样子,接受一组固定数量的模板参数;而C++11 加入了新的表示方法,允许任意个数、任意类别的模板参数,同时也不需要在定义时将参数的个数固定。可变参数模板和普通模板的语义是一样的,只是写法上稍有区别,声明可变参数模板时需要在typename或class后面带上省略号“...”template<typename....._template
文章浏览阅读269次。HTML<a href="" target="_blank"> 业务需求分析书-系统营业日扎帐报表、收费汇总表及收费明细表 </a>cssa{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;width: 100%;display: inline-block;}overflow:..._css a标签超出宽度自动隐藏
文章浏览阅读2k次。References:纠删码解析_向前纠错的编码过程
文章浏览阅读6.8k次,点赞12次,收藏53次。文章目录准备数据搭建模型训练模型推断完整代码在本笔记本中我们将使用在本论文中介绍的Transformer模型。具体来说,我们将使用来自这篇论文中的BERT(Bidirectional Encoder Representations from Transformers)模型。Transformer模型比之前笔记中介绍的任何模型都要大得多。因此,我们将使用transformers library获得预先训练的transformers,并使用它们作为我们的嵌入层。我们将冻结(而不是训练)transformer_基于transformer的情感分析
文章浏览阅读1.2k次。Computational Optimal Transport笔记——Introduction最优运输可以看做是更一般的最短路问题最短路原则:当在给定的点处有一个商品、人或者一些信息,这些东西需要被送到目标点。我们希望使用最少的工作量完成任务。(我们可以沿着直线或者测地线移动)最忧运输理论将这个问题一般化,一个人不是一次移动一个物品而是同时移动多个物品。经证明,有计划地运输一堆个体到指定的位..._最优运输理论 偏微分方程
文章浏览阅读3.4k次。刚入门spring security,感觉东西有点多,不好好研究出了问题都不知道为什么。rememberMe功能配置核心代码(有问题的): protected void configure(HttpSecurity http) throws Exception { List<SysPermission> allPermission = permissionFe..._spring security记住我功能有令牌不实现