3.3 TCP Health Checks

Problem

You need to check your upstream TCP server for health and remove

unhealthy servers from the pool.

问题

需要检测 TCP 服务器是否正常并从代理池中移除失效服务器。


Solution

Use the health_check directive in the server block for an active

health check:

stream {
    server {
        listen 3306;
        proxy_pass read_backend;
        health_check interval=10 passes=2 fails=3;
    }
}

The example monitors the upstream servers actively. The upstream

server will be considered unhealthy if it fails to respond to three or

more TCP connections initiated by NGINX. NGINX performs the

check every 10 seconds. The server will only be considered healthy

after passing two health checks.

解决方案

在 server 块级指令中 使用 health_check 简单指令,对被代理服务器进行

健康检测:

stream {
    server {
        listen 3306;
        proxy_pass read_backend;
        health_check interval=10 passes=2 fails=3;
    }
}

上面的配置会对代理池中的服务器进行主动监测。如果被代理服务器未能正常

响应 NGINX 服务器的 3 个以上 TCP 连接请求,则被认为是失效的服务。

之后,NGINX 服务器会每隔 10 秒进行一次健康检测。


Discussion

TCP health can be verified by NGINX Plus either passively or

actively. Passive health monitoring is done by noting the communi‐

cation between the client and the upstream server. If the upstream

server is timing out or rejecting connections, a passive health check

will deem that server unhealthy. Active health checks will initiate

their own configurable checks to determine health. Active health

checks not only test a connection to the upstream server, but can

expect a given response.

结论

在 NGINX PLUS 版本中同时提供被动检测和主动检测功能。被动检测是通过加之于

客户端与被代理服务器的请求响应检测实现的。如果一个请求超时或者连接失败,

被动检测则认为该被代理服务器失效。主动检测则是通过明确的 NGINX 指令配置

来检测服务器是否失效。主动检测途径可以是一个测试的连接,也可以是一个预期

的响应。


资料(译者补充)

这篇文章 「TCP Health Checks」 是 NGINX 服务器官网的管理员运维教程,主要讲解开源版本

和 NGINX PLUS(商业版) 的 TCP 健康检测配置处理

TODO 翻译 「TCP Health Checks」

results matching ""

    No results matching ""