首页 > 解决方案 > 使用 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

标签: haproxygateway

解决方案


推荐阅读