TCP Health Checks
This chapter describes how to configure health checks for TCP.
Introduction
NGINX and NGINX Plus can continually test your TCP upstream servers, avoid the servers that have failed, and gracefully add the recovered servers into the load-balanced group.
Prerequisites
You have configured an upstream group of TCP servers in the
streamcontext, for example:stream {
...
upstream stream_backend {
server backend1.example.com:12345;
server backend2.example.com:12345;
server backend3.example.com:12345;
}
...
}You have configured a server that passes TCP connections to the server group:
stream {
...
server {
listen 12345;
proxy_pass stream_backend;
}
...
}
Passive TCP Health Checks
If an attempt to connect to an upstream server times out or results in an error, open source NGINX or NGINX Plus can mark the server as unavailable and stop sending requests to it for a defined amount of time. To define the conditions under which NGINX considers an upstream server unavailable, include the following parameters to the server directive
fail_timeout– The amount of time within which a specified number of connection attempts must fail for the server to be considered unavailable. Also, the amount of time that NGINX considers the server unavailable after marking it so.max_fails– The number of failed attempts that happen during the specified time for NGINX to consider the server unavailable.
意思就是:当upstream里的一个server失败次数达到max_fails,该server接下来的fail_timeout时间内停止服务(不会分发连接给它),过了这个时间继续根据负载算法往该server分配连接
The default values are 10 seconds and 1 attempt. So if a connection attempt times out or fails at least once in a 10-second period, NGINX marks the server as unavailable for 10 seconds. The example shows how to set these parameters to 2 failures within 30 seconds:
upstream stream_backend {
server backend1.example.com:12345 weight=5;
server backend2.example.com:12345 max_fails=2 fail_timeout=30s;
server backend3.example.com:12346 max_conns=3;
}
Active TCP Health Checks
Health checks can be configured to test a wide range of failure types. For example, NGINX Plus can continually test upstream servers for responsiveness and avoid servers that have failed.
NGINX Plus sends special health check requests to each upstream server and checks for a response that satisfies certain conditions. If a connection to the server cannot be established, the health check fails, and the server is considered unhealthy. NGINX Plus does not proxy client connections to unhealthy servers. If several health checks are defined for a group of servers, the failure of any one check is enough for the corresponding server be considered unhealthy.
To enable active health checks:
Specify a shared memory zone – a special area where the NGINX Plus worker processes share state information about counters and connections. Add the
zonedirective to the upstream server group and specify the zone name and the amount of memory:stream {
...
upstream stream_backend {
zone stream_backend 64k;
server backend1.example.com:12345;
server backend2.example.com:12345;
server backend3.example.com:12345;
}
...
}Enable health checks for servers in the upstream group. Add the
health_checkandhealth_check_timeoutdirectives to the server that proxies connections to the upstream group:stream {
...
server {
listen 12345;
proxy_pass stream_backend;
health_check;
health_check_timeout 5s;
}
...
}The
health_checkdirective enables the health check functionality, whilehealth_check_timeoutoverrides theproxy_timeoutvalue for health checks, as for health checks this timeout needs to be significantly shorter.
Fine-Tuning TCP Health Checks
By default, NGINX Plus tries to connect to each server in an upstream server group every 5 seconds. If the connection cannot be established, NGINX Plus considers the health check failed, marks the server as unhealthy, and stops forwarding client connections to the server.
To change the default behavior, include parameters to the health_check directive:
interval– How often (in seconds) NGINX Plus sends health check requests (default is 5 seconds)passes– Number of consecutive health checks the server must respond to to be considered healthy (default is 1)fails– Number of consecutive health checks the server must fail to respond to to be considered unhealthy (default is 1)
stream {
...
server {
listen 12345;
proxy_pass stream_backend;
health_check interval=10 passes=2 fails=3;
}
...
}
In the example, the time between TCP health checks is increased to 10 seconds, the server is considered unhealthy after 3 consecutive failed health checks, and the server needs to pass 2 consecutive checks to be considered healthy again.
By default, NGINX Plus sends health check messages to the port specified by the server directive in the upstream block. You can specify another port for health checks, which is particularly helpful when monitoring the health of many services on the same host. To override the port, specify the port parameter of the health_check directive:
stream {
...
server {
listen 12345;
proxy_pass stream_backend;
health_check port=8080;
}
...
}
The “match {}” Configuration Block
You can verify server responses to health checks by configuring a number of tests. These tests are defined with the match {} configuration block placed in the stream {}context. Specify the match {} block and set its name, for example, tcp_test:
stream {
...
match tcp_test {
...
}
}
Then refer to the block from the health_check directive by including the match parameter and the name of the match block:
stream {
...
server {
listen 12345;
health_check match=tcp_test;
proxy_pass stream_backend;
}
...
}
The conditions or tests under which a health check succeeds are set with send and expect parameters:
send– The text string or hexadecimal literals (“/x” followed by two hex digits) to send to the serverexpect– Literal string or regular expression that the data returned by the server needs to match
These parameters can be used in different combinations, but no more than one send and one expect parameter can be specified at a time:
If no
sendorexpectparameters are specified, the ability to connect to the server is tested.If the
expectparameter is specified, the server is expected to unconditionally send data first:match pop3 {
expect ~* "\+OK";
}If the
sendparameter is specified, it is expected that the connection will be successfully established and the specified string will be sent to the server:match pop_quit {
send QUIT;
}If both the
sendandexpectparameters are specified, then the string from thesendparameter must match the regular expression from theexpectparameter:stream {
...
upstream stream_backend {
zone upstream_backend 64k;
server backend1.example.com:12345;
}
match http {
send "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n";
expect ~* "200 OK";
}
server {
listen 12345;
health_check match=http;
proxy_pass stream_backend;
}
}The example shows that in order for a health check to pass, the HTTP request must be sent to the server, and the expected result from the server contains
200OKto indicate a successful HTTP response.
TCP Health Checks的更多相关文章
- Kong(V1.0.2) Health Checks and Circuit Breakers Reference
介绍 您可以让Kong代理的API使用ring-balancer,通过添加包含一个或多个目标实体的 upstream 实体进行配置,每个 target指向不同的IP地址(或主机名)和端口.ring-b ...
- UDP Health Checks
This chapter describes how to configure different types of health checks for UDP servers in a load-b ...
- HTTP Health Checks
This article describes how to configure and use HTTP health checks in NGINX Plus and open source NGI ...
- Service Discovery And Health Checks In ASP.NET Core With Consul
在这篇文章中,我们将快速了解一下服务发现是什么,使用Consul在ASP.NET Core MVC框架中,并结合DnsClient.NET实现基于Dns的客户端服务发现 这篇文章的所有源代码都可以在G ...
- Using HAProxy as an API Gateway, Part 3 [Health Checks]
转自:https://www.haproxy.com/blog/using-haproxy-as-an-api-gateway-part-3-health-checks/ Achieving high ...
- Zookeeper Health Checks
Short Description: The article talks about the basic health checks to be performed when working on i ...
- NGINX Load Balancing – TCP and UDP Load Balancer
This chapter describes how to use NGINX Plus and open source NGINX to proxy and load balance TCP and ...
- 11g新特性:Health Monitor Checks
一.什么是Health Monitor ChecksHealth Monitor Checks能够发现文件损坏,物理.逻辑块损坏,undo.redo损坏,数据字典损坏等等.Health Monitor ...
- About Health Monitor Checks
About Health Monitor Checks Health Monitor checks (also known as checkers, health checks, or checks) ...
随机推荐
- Element-UI 日期范围 date-picke
实际项目应用案例: <el-form-item label="开始日期:" prop="StartDate"> <el-date-picker ...
- 如何理解php的依赖注入
之前写过关于php依赖注入的文章..最近发现有的朋友对这个还是理解模糊,在这里我想写个简单的实例帮助朋友们理解下...传统的思路是应用程序用到一个A类,就会创建A类并调用A类的方法,假如这个方法内需要 ...
- Spring 中事务控制的API介绍
1.PlatformTransactionManager Spring所有事务代理类都是基于PlatformTransactionManager接口的实现. 此接口是spring的事务管理器,它里面提 ...
- Maven(六)Eclipse使用Maven插件创建项目
1. 创建Maven版Java工程 1.1 具体步骤 1.2 更改默认JDK版本 默认JDK版本过低 可以通过配置setting.xml来更改JDK版本 加入如下代码 <profile> ...
- Java win7或 xp下配置JDK环境变量
JAVA win7或 xp下配置JDK环境变量 by:授客 QQ:1033553122 1.安装JDK,安装过程中可以自定义安装目录等信息,例如我们选择安装目录为D:\java\jdk1.5.0_08 ...
- 腾讯云下的CentOS7 安装最新版Python3.7.0
第一步下载Python3.7.0 刚开始我是在windows上下载之后 传到FTP服务器上的 后来发现使用以下命令可以更快捷地下载到服务器 * wget https://www.python.org ...
- PS把图片P到老树干上,变成老树成精!
1,两张图片: 2,把人像图片拉到另一张图片上,Ctrl+T适当缩放,放到树干合适的地方. 3,人像--Ctrl+Shift+U 去色---复制树图片(背景)放第一张---正片叠底. 4,选中两张图片 ...
- 使用Gson将对象类转成Json对象时出现\u003d的问题
Gson将对象转成Json对象的方法 Gson gson=new Gson(); String json=gson.toJson(Student.class); 这种情况,如果Student属性中的某 ...
- GIS开发之计算四参数,七参数
一.四参数 想要通过控制点计算四参数,首先需要知道四参数的相关原理,推荐这篇文章: http://www.docin.com/p-1197326043.html 根据上面的计算公式,使用最小二乘法计算 ...
- 29.Odoo产品分析 (四) – 工具板块(2) – 搜索和仪表盘(1)
查看Odoo产品分析系列--目录 "项目管理"是一个用于管理你的项目,且将它们与其他应用关联起来的非常灵活的模块,他允许您的公司管理项目阶段,分配团队,甚至跟踪与项目相关的时间和工 ...