haproxy - 使用 haproxy 对后端服务器执行 http 健康检查
问题描述
是否可以在单个后端服务器上执行 HTTP 健康检查并在活动后端服务器之间进行负载平衡。当我们在 httpchk 中提到主机名时,这适用于单个后端服务器(选项 httpchk GET /info HTTP/1.1 Host:\ abc.mysrv1.com)
但是,我无法使用多个后端服务器成功配置它,因为我无法在 httpchk 命令上提供单个主机名,并且以下后端配置出现 http 400 错误 -
backend svc.op
balance roundrobin
mode http
http-send-name-header Host
option httpchk GET /info HTTP/1.1
http-check send-state
http-request set-uri /test/abcService
server abc.mysrv1.com abc.mysrv1.com:80 check
server abc.mysrv2.com abc.mysrv2.com:80 check
[WARNING] 115/162226 (4788) : Server svc.op/abc.mysrv1.com is DOWN, reason: Layer7 wrong status, code: 400, info: "Bad Request: missing required Host header", check duration: 1ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[WARNING] 115/162227 (4788) : Server svc.op/abc.mysrv2.com is DOWN, reason: Layer7 wrong status, code: 400, info: "Bad Request: missing required Host header", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 115/162227 (4788) : backend ' svc.op' has no server available!
$ ./haproxy -version HA-Proxy 版本 1.6.7 2016/07/13
更新:我没有追求这个,但有人建议遵循 -
backend h_a01
mode http
option httpchk GET /health HTTP/1.1\r\nHost:\ a01\r\n
http-check expect rstatus ^200
http-request set-uri /hello/world
http-request set-header Host a01
server a01 a01 check
backend h_a02
mode http
option httpchk GET /health HTTP/1.1\r\nHost:\ a02\r\n
http-check expect rstatus ^200
http-request set-uri /hello/world
http-request set-header Host a02
server a02 a02 check
backend a
mode http
option forwardfor
http-send-name-header Host
http-request set-uri /hello/world
server a1 a1 track h_a01/a01
server a2 a2 track h_a02/a02
解决方案
推荐阅读
- json - Druid parquet 摄取性能不佳
- vue.js - 组件可以在 vue-router 中知道它的子路由吗
- javascript - Invariant Violation:Invariant Violation:文本字符串必须在
零件 - django - Django 信号 - kwargs['update_fields'] 在通过 django admin 更新模型时始终为 None
- google-chrome - 为什么隐身标签加载网站的速度比打开正常标签的网站快得多?
- python - 在 python 代码中替换数组的值时遇到问题
- typescript - 仅当可以使用 Exclude<> 未定义参数时,如何在返回类型中包含未定义?
- r - 从最小值开始 y 轴,从 0 开始 x 轴,并使用 R 中的 matplot() 使它们相交
- javascript - 如何在可访问性检查器网站 https://webaccessibility.com 中获得 100% 的 ADA 合规性结果?
- azure-devops - 如何配置 Azure DevOps 发布管道以使用 Azure Artifacts 中的通用包?