我在VirtualBox VM(Boot2docker)中使用Haproxy 1.5.14,其中间歇性加载的资产显示503没有任何真正的押韵或原因,在群集启动时尤其如此.
集群看起来像这样,1个前端有端口80,443到2个后端分别为静态资源和websocket东西提供服务.
HAProxy的
例如,前端服务的静态资产可能是
https://local.dev.myproject.com/assets/images/back.png
尽管前端服务器正在运行,并且没有任何变化,但是点击刷新并查看chrome调试器,我将看到许多状态503或OK 200 304,但它不是确定的.任何资产都可以从503到OK再到503.当直接连接到网络服务器时,资产返回正常,所以它看起来像haproxy.
我能想到的最好的是健康检查工作不正常,并且正在从haproxy的内部名册暂时删除FE/BE服务器,但这没有意义,它每隔半秒检查一次,我可以看到haproxy的调用是发送由FE/BE终端输出窗口返回,按预期每半秒发送一次.
如果我查看haproxy统计报告,我可以看到服务器定期来来去去,闪烁,尽管在终端窗口中haproxy仍然无间隙地调用运行状况检查,服务器按预期返回它们.
附件是我正在使用的当前haproxy配置,任何帮助表示赞赏.
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# …Run Code Online (Sandbox Code Playgroud) 我有 3 个不同的 Restful 服务器:w1、w2、w3
引用我的负载均衡器的客户端提供名为“ip”(ipv4) 的 url 参数。请求之间的 url 参数 ip 是不同的:
curl -XGET http://localhost:8080/api/v1/link?ip=x.x.x.x
Run Code Online (Sandbox Code Playgroud)
我想使用 HASH 算法根据 ip 参数平衡 HAProxy 到 w1、w2、w3。
HAProxy 配置如下:
global
#daemon
maxconn 3000
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend workers
backend workers
balance url_param ip
hash-type consistent
server w1 localhost:8080 weight 1 maxconn 1000 check
server w2 localhost:8081 weight 1 maxconn 1000 check
server w3 localhost:8082 weight 1 maxconn 1000 check
listen …Run Code Online (Sandbox Code Playgroud) 我已经设置了 REDIS 复制(1 个主站 + 2 个从站)以及 3 个哨兵和 1 个 HAProxy 负载均衡器。它可以工作,但除了故障转移之外,我想在从属设备之间平衡只读指令的负载。可以使用HAProxy吗?这是我的 HAProxy 配置的一部分:
backend bk_redis
option tcp-check
tcp-check connect
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis_1 localhost:6379 check inter 1s
server redis_2 localhost:6380 check inter 1s
Run Code Online (Sandbox Code Playgroud)
(据我所知)这将只是将所有流量重定向到当前主服务器,而我想在这里进行负载平衡。
在我的 python 应用程序中,浏览器向我的服务器发送请求以获取某些信息。我需要跟踪发出请求的源的 IP。通常,我可以通过此调用获取该信息:
request.headers.get('Remote-Addr')
但是,当我在 HaProxy 这样的负载均衡器后面部署应用程序时,给出的 IP 是负载均衡器的 IP,而不是浏览器的 IP。
当服务器位于负载均衡器后面时,如何获取服务器上浏览器的 IP?
我的案例的另一个问题是我通过 HAProxy 使用从浏览器到我的服务器的 TCP 连接,而不是使用 http。
好吧,我已经尝试解决这个问题有一段时间了,但没有结果。因此,我们在 aws 负载均衡器后面有一个 aws ec2 实例,并为负载均衡器分配了一个 aws free ssl。在我们的 ec2 实例中,我们有一个 apache Web 服务器侦听端口 1338 和一个 websocket 服务器(使用 Ratchet)侦听端口 8080。在我们之间,我们使用具有此配置的 HAProxy
global
log 127.0.0.1 local0
maxconn 10000
user haproxy
group haproxy
daemon
defaults
mode http
log global
option httplog
retries 3
backlog 10000
timeout client 30s
timeout connect 30s
timeout server 30s
timeout tunnel 3600s
timeout http-keep-alive 1s
timeout http-request 15s
frontend public
bind *:80
acl is_websocket hdr(Upgrade) -i WebSocket
use_backend ws if is_websocket #is_websocket_server
default_backend www
backend ws
option …Run Code Online (Sandbox Code Playgroud) 我正在解决 haproxy 设置上日志格式的一些问题。首先,我有多个代理设置,这意味着:
请求 -> 客户端代理 -> 中间代理 -> 应用程序
关于客户端代理上的这一点,我添加:
唯一 id 标头 X 唯一 ID
该值在日志中表示为:
日志格式 %ci:%cp\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ {%hrl}\ {%hsl}\ %{+Q}r\ {%ID}
这太棒了。另一方面,在中间代理上,我可以从前端的标头获取此值:
捕获请求标头 X-Unique-ID len 200
现在在这个代理(中间代理)上我有这样的条件:
acl uniq_header_exist hdr_cnt(X-唯一-ID) eq 0
http-request set-header X-Unique-ID %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid 如果 uniq_header_exist
(它完成了这项工作,所以我可以添加 uuid(如果不存在的话) - 很好)并且日志表示如下:
日志格式 %ci:%cp\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ {%hrl}\ {%hsl}\ %{+Q}r\ [id=%[capture.req.人类发展报告(2)]]
但我无法有任何可能做这样的事情:
if X-Unique-ID exist then use: …Run Code Online (Sandbox Code Playgroud) 我需要一些有关如何设置haproxy 的建议。我有两个网络服务器正在运行。为了进行测试,他们在端口 8080 上运行一个简单的节点服务器。
现在,在我的 haproxy 服务器上,我启动 haproxy,它提供了以下内容:
$> /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg
[WARNING] 325/202628 (16) : Server node-backend/server-a is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 325/202631 (16) : Server node-backend/server-b is DOWN, reason: Layer4 timeout, check duration: 2001ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 325/202631 …Run Code Online (Sandbox Code Playgroud) curl 当我使用without 打开网址时-k,我的请求正在通过,并且我能够看到预期的结果。
$ curl -vvv https://MYHOSTNAME/wex/archive.info -A SUKU$RANDOM
* Trying 10.38.202.192...
* Connected to MYHOSTNAME (10.38.202.192) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.MYCNAME
* Server certificate: ProdIssuedCA1
* Server certificate: InternalRootCA
> GET /wex/archive.info HTTP/1.1
> Host: MYHOSTNAME
> User-Agent: SUKU19816
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.10.2
< Date: Thu, 26 Jan 2017 01:08:40 GMT
< Content-Type: text/html;charset=ISO-8859-1
< Content-Length: 19
< Connection: keep-alive
< Set-Cookie: …Run Code Online (Sandbox Code Playgroud) 我有一台主机,HAProxy 使用 docker compose 作为 docker 容器运行。我想水平扩展我们的 HAProxy,使其在多个主机上高度可用。
我读了一些关于 keepalived 的教程,但这是在主机上完成的,并且是作为主机安装的 HAProxy 服务器,而不是在 docker 容器中。
是否可以通过docker化的方式部署高可用的HAProxy?
(我知道我有虚拟化设置)
我有两个后端,以便在我的应用程序中维护两组规则。一种用于通过浏览器访问的主网站(cookied 会话),另一种用于 API(无状态并通过 API 密钥进行身份验证)。
配置看起来像这样(大大简化)。
defaults
option httpchk HEAD /ping
backend web
cookie _srv insert indirect
server srv1 10.0.0.1:80 cookie srv1 check inter 10s
server srv2 10.0.0.2:80 cookie srv2 check inter 10s
backend api
stick-table type string len 50 expire 1d store http_req_cnt
stick on url_param(key)
server srv1 10.0.0.1:80 check inter 10s
server srv2 10.0.0.2:80 check inter 10s
Run Code Online (Sandbox Code Playgroud)
如图所示,两个后端使用相同的服务器,只是 API 不需要设置 cookie。有(或将会有)更多的逻辑需要分离,例如速率限制规则。
我的问题是如何避免重复健康检查?对每台服务器对同一端点执行两次 ping 操作会浪费资源。我想让web后端进行健康检查,并将api后端标记为启动或关闭。这可能吗?或者也许有更好的方法来分离后端但保留通用功能。