a6-recipe-health-check
概览
健康检查会监控上游后端节点,并自动 将不健康节点从负载均衡池中移除。APISIX 支持两种检查方式:
- 主动检查:APISIX 定期使用 HTTP、HTTPS 或 TCP 请求探测每个节点。
- 被动检查:APISIX 分析真实流量的响应来检测故障。
生产环境建议同时使用两种检查方式,以获得更可靠的故障检测和恢复能力。
适用场景
- 自动将故障后端节点移出负载均衡池
- 检测后端故障并从中恢复,无需人工干预
- 确保多个后端的可用性高
- 通过 a6 CLI 监控后端健康状态
健康检查配置参考
主动健康检查
| 字段 | 类型 | 默认 | 描述 |
|---|---|---|---|
checks.active.type | 字符串 | "http" | 检查类型:"http"、"https" 或 "tcp" |
checks.active.http_path | 字符串 | "/" | 探测的 HTTP 路径 |
checks.active.host | 字符串 | — | HTTP 探测器的主机头 |
checks.active.port | 整数 | — | 探测端口(默认使用节点端口) |
checks.active.timeout | 数字 | 1 | 探测超时时间(秒) |
checks.active.concurrency | 整数 | 10 | 同时进行的探测次数 |
checks.active.https_verify_certificate | 布尔 | true | 验证 HTTPS 探测器的 TLS 证书 |
checks.active.req_headers | 数组[字符串] | — | 探测器的额外请求头 |
checks.active.healthy.interval | 整数 | 1 | 健康节点的探测间隔(秒) |
checks.active.healthy.successes | 整数 | 2 | 将节点标记为健康所需的连续成功次数 |
checks.active.healthy.http_statuses | 数组[整数] | [200, 302] | 视为健康的 HTTP 状态码 |
checks.active.unhealthy.interval | 整数 | 1 | 不健康节点的探测间隔(秒) |
checks.active.unhealthy.http_failures | 整数 | 5 | 将节点标记为不健康所需的连续 HTTP 失败次数 |
checks.active.unhealthy.tcp_failures | 整数 | 2 | 将节点标记为不健康所需的连续 TCP 失败次数 |
checks.active.unhealthy.timeouts | 整数 | 3 | 将节点标记为不健康所需的连续超时次数 |
checks.active.unhealthy.http_statuses | 数组[整数] | [429, 404, 500, 501, 502, 503, 504, 505] | 视为不健康的 HTTP 状态码 |