使用强制持久设置的haproxy工作配置

Dav*_*man 5 haproxy ubuntu-14.04

我不确定我是否遗漏了一些关键的配置文件,或者只是从根本上误解了haproxy中强制持久的目的(在Ubuntu 14.04上使用版本1.5.11).从文档:

"force-persist"语句允许声明各种基于ACL的条件,当满足这些条件时,将导致请求忽略服务器的关闭状态并仍尝试连接到它.这样就可以启动服务器,仍然将错误回复到运行状况检查,并运行专门配置的浏览器来测试服务.

这听起来就像我想要的行为,在那里我可以将所有应用服务器置于"维护模式"以进行代码部署,但允许某些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
Run Code Online (Sandbox Code Playgroud)

有了这个配置,我我应该能够发出以下命令:

echo "disable server mysite/app-1" | socat /run/haproxy/admin.sock stdio
Run Code Online (Sandbox Code Playgroud)

将单个应用服务器撤出,只要我来自/etc/haproxy/whitelist.lst中列出的IP地址,我仍然可以看到该网站,就好像服务器仍然启用一样.但是,我最终看到的是503错误页面,如果我是普通用户,我通常会发现这一点,但不是来自列入白名单的IP.为了消除我错误地指定IP地址或错误地使用acl命令的可能性,我尝试了一个变体,我只需设置:

force-persist if TRUE
Run Code Online (Sandbox Code Playgroud)

从我对文档的阅读中,我认为无论我来自哪个IP,我都不会禁用服务器.不幸的是我仍然得到503.

有一些笨拙的方法,包括传递额外的配置和重新加载haproxy,我可以使用它来使这个工作,但"强制持久"以及通过命令行禁用的方便能力似乎是一个更优雅的方法,我如果我能让它发挥作用,我肯定更喜欢它.

有没有其他人试图让haproxy以这种方式工作?以这种方式解释"强制坚持"我是错的吗?我是否需要一些额外的配置才能使其正常工作?

Wil*_*eau 4

没有规则指示在此配置中要坚持什么。通常您会将其与基于 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
Run Code Online (Sandbox Code Playgroud)

然后在您的客户端上,访问第一个服务器,分配 cookie,禁用该服务器,然后再次访问它,您将继续访问那里。通常人们会实现一个特定的 HTML 页面,列出所有服务器及其各自的 cookie,只需单击服务器即可帮助从客户端选择服务器。