我们在 Amazon EC2 实例中使用 HA 代理将某些请求路由到两个不同的内部负载均衡器,即 EC2 ELB(弹性负载均衡器)。
以下是 HA 代理配置:
defaults
mode http
log global
no option redispatch
retries 25
timeout connect 10000 # default 10 second time out if a backend is not found
timeout client 30000
timeout server 30000
maxconn 20000
stats uri /haproxy?stats
option http-server-close
timeout http-request 100s
timeout http-keep-alive 124s
backend main-service-backend
option httpchk GET /ping
server main-service internal-main-service:80 check inter 5s fall 10
backend micro-service-backend
option httpchk GET /ping
server micro-service internal-micro-service:80 check inter 5s fall 10
frontend shared-frontend *:80
acl is-micro-service-url path_reg ^/(/rest/user/.*/?)
use_backend micro-service-backend if is-micro-service-url
default_backend main-service-backend
通常情况下,如果我暂时关闭一台服务器,HA 代理就会恢复。但是似乎发生了一些网络/路由错误,HA 代理无法恢复。
以下是 HA 代理日志:
Server micro-service-backend/micro-service is DOWN, reason: Layer4 connection problem, info: "No route to host", check duration: 998ms. 0 active and 0 backup servers left. 1 sessions active, 0 requeued, 0 remaining in queue.
backend micro-service-backend has no server available!
HA 代理停止检查服务器并继续将其标记为 DOWN。但是,我能够成功地从 HA 代理框到内部负载均衡器进行 http 健康检查:
curl -i http://internal-micro-service:80/ping
HTTP/1.1 200 OK
Content-Type: text/plain;charset=UTF-8
Date: Fri, 12 Jun 2015 23:08:29 GMT
Server: Apache-Coyote/1.1
Content-Length: 2
Connection: keep-alive
UP
知道可能出了什么问题吗?我还应该调查什么?
答案1
经过一番谷歌搜索,我发现 HA 代理仅在启动时解析 DNS。EC2 ELB 可以随机更改 IP 地址,这会导致健康检查失败,因为 HA 代理在进行健康检查之前不会进行 DNS 解析。