gpt4 book ai didi

ubuntu-14.04 - 使用 force-persist 设置的 haproxy 工作配置

转载 作者:行者123 更新时间:2023-12-04 20:01:34 26 4
gpt4 key购买 nike

我不确定我是否遗漏了一些关键的配置部分,或者只是从根本上误解了 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.



这听起来正是我想要的行为,在这种情况下,我可以将所有应用程序服务器置于“维护模式”以进行代码部署,但允许某些 IP 仍然连接以在部署后对其进行测试,然后再授予每个人访问权限。这是我设置的配置:
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,我可以用它来使这个工作正常工作,但是“强制持久化”以及通过命令行禁用的便捷功能似乎是一种更优雅的方法,我如果我能让它工作,我肯定会更喜欢它。

有没有其他人试图让 haproxy 以这种方式工作?我这样解释“force-persist”有错吗?我是否需要一些额外的配置才能使其工作?

最佳答案

没有规则指示在此配置中要坚持什么。通常,您会将其与基于 cookie 的持久性结合使用。例如 :

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,这有助于通过单击它们来帮助从客户端选择服务器。

关于ubuntu-14.04 - 使用 force-persist 设置的 haproxy 工作配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29248144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com