具有 force-persist 设置的 haproxy 的工作配置
working configuration for haproxy with the force-persist setting
我不确定我是否遗漏了一些关键配置部分,或者只是从根本上误解了 haproxy 中 force-persist 的目的(在 Ubuntu 14.04 上使用版本 1.5.11)。来自文档:
The "force-persist" statement allows one to declare various ACL-based
conditions which, when met, will cause a request to ignore the down status of
a server and still try to connect to it. That makes it possible to start a
server, still replying an error to the health checks, and run a specially
configured browser to test the service.
这听起来正是我想要的行为,我可以将所有应用程序服务器放入 "maintenance mode" 以进行代码发布,但仍允许某些 IP 连接以进行测试,post-rollout,然后再次授予所有人访问权限。这是我设置的配置:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL).
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 300s
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen mysite
bind *:80
bind *:443 ssl crt mysite.pem
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
redirect scheme https if !{ ssl_fc }
balance roundrobin
option forwardfor
option httpchk HEAD /haproxy_health_check.php
acl whitelist src -f /etc/haproxy/whitelist.lst
force-persist if whitelist
server app-1 10.1.4.32:80 maxconn 20 check inter 10000
使用此配置,我认为我应该能够发出以下命令:
echo "disable server mysite/app-1" | socat /run/haproxy/admin.sock stdio
停止轮换使用单个应用程序服务器,只要我来自 /etc/haproxy/whitelist.lst 中列出的 IP 地址,我应该仍然能够看到该网站,就好像服务器是仍然启用。但是,我最终看到的是 503 错误页面,如果我是普通用户,我通常会期望出现这种情况,但不是来自列入白名单的 IP。为了消除我错误地指定 IP 地址或错误地使用 acl 命令的可能性,我尝试了一种变体,我只是设置:
force-persist if TRUE
根据我对文档的阅读,我认为无论我来自哪个 IP,这都好像我从未禁用过服务器一样。不幸的是,我仍然得到 503。
有一些更笨拙的方法,包括传递额外的配置和重新加载 haproxy,我可以使用它们来使它正常工作,但是 "force-persist" 以及通过命令行禁用的便捷功能似乎要多得多优雅的方法,如果可以的话,我绝对会喜欢它。
有没有其他人试图让 haproxy 以这种方式工作?我这样解释 "force-persist" 是不是错了?我需要一些额外的配置才能让它工作吗?
没有规则指示在此配置中要坚持什么。通常,您会将此与 cookie-based 持久性结合使用。例如:
cookie SERVERID insert indirect nocache
server srv1 1.1.1.1:80 cookie s1 check
server srv2 2.2.2.2:80 cookie s2 check
acl from_management_net src 10.0.0.0/8
force-persist if from_management_net
然后在你的客户端上,访问第一个服务器,获取分配的cookie,禁用服务器,再次访问它,你会继续去那里。通常人们会实现一个特定的 HTML 页面,列出所有服务器及其各自的 cookie,这有助于通过单击从客户端选择服务器。
我不确定我是否遗漏了一些关键配置部分,或者只是从根本上误解了 haproxy 中 force-persist 的目的(在 Ubuntu 14.04 上使用版本 1.5.11)。来自文档:
The "force-persist" statement allows one to declare various ACL-based conditions which, when met, will cause a request to ignore the down status of a server and still try to connect to it. That makes it possible to start a server, still replying an error to the health checks, and run a specially configured browser to test the service.
这听起来正是我想要的行为,我可以将所有应用程序服务器放入 "maintenance mode" 以进行代码发布,但仍允许某些 IP 连接以进行测试,post-rollout,然后再次授予所有人访问权限。这是我设置的配置:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL).
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 300s
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen mysite
bind *:80
bind *:443 ssl crt mysite.pem
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
redirect scheme https if !{ ssl_fc }
balance roundrobin
option forwardfor
option httpchk HEAD /haproxy_health_check.php
acl whitelist src -f /etc/haproxy/whitelist.lst
force-persist if whitelist
server app-1 10.1.4.32:80 maxconn 20 check inter 10000
使用此配置,我认为我应该能够发出以下命令:
echo "disable server mysite/app-1" | socat /run/haproxy/admin.sock stdio
停止轮换使用单个应用程序服务器,只要我来自 /etc/haproxy/whitelist.lst 中列出的 IP 地址,我应该仍然能够看到该网站,就好像服务器是仍然启用。但是,我最终看到的是 503 错误页面,如果我是普通用户,我通常会期望出现这种情况,但不是来自列入白名单的 IP。为了消除我错误地指定 IP 地址或错误地使用 acl 命令的可能性,我尝试了一种变体,我只是设置:
force-persist if TRUE
根据我对文档的阅读,我认为无论我来自哪个 IP,这都好像我从未禁用过服务器一样。不幸的是,我仍然得到 503。
有一些更笨拙的方法,包括传递额外的配置和重新加载 haproxy,我可以使用它们来使它正常工作,但是 "force-persist" 以及通过命令行禁用的便捷功能似乎要多得多优雅的方法,如果可以的话,我绝对会喜欢它。
有没有其他人试图让 haproxy 以这种方式工作?我这样解释 "force-persist" 是不是错了?我需要一些额外的配置才能让它工作吗?
没有规则指示在此配置中要坚持什么。通常,您会将此与 cookie-based 持久性结合使用。例如:
cookie SERVERID insert indirect nocache
server srv1 1.1.1.1:80 cookie s1 check
server srv2 2.2.2.2:80 cookie s2 check
acl from_management_net src 10.0.0.0/8
force-persist if from_management_net
然后在你的客户端上,访问第一个服务器,获取分配的cookie,禁用服务器,再次访问它,你会继续去那里。通常人们会实现一个特定的 HTML 页面,列出所有服务器及其各自的 cookie,这有助于通过单击从客户端选择服务器。