Tengine 健康检查模块,
Tengine 健康检查模块,
Tengine健康检查模块
doc :http://tengine.taobao.org/document_cn/http_upstream_check_cn.html
ngx_http_upstream_check_module
配置栗子
http {
upstream cluster1 {
# simple round-robin
server 192.168.0.1:80;
server 192.168.0.2:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
# 这里的请求头使用HEAD 目的是为了请求短 占用资源少
# HEAD后面的/代表检查根目录
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
# 健康检查标识的状态码 表示返回2xx 3xx表示正常
check_http_expect_alive http_2xx http_3xx;
}
upstream cluster2 {
# simple round-robin
server 192.168.0.3:80;
server 192.168.0.4:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_keepalive_requests 100;
check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
location /1 {
proxy_pass http://cluster1;
}
location /2 {
proxy_pass http://cluster2;
}
location /status {
check_status;
access_log off;
allow SOME.IP.ADD.RESS;
deny all;
}
}
}
名次解释
interval:向后端发送的健康检查包的间隔。
fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
timeout: 后端健康请求的超时时间。
default_down: 设定初始时服务器的状态,如果是true,就说明默认是down的,如果是false,就是up的。默认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。
type:健康检查包的类型,现在支持以下多种类型
tcp:简单的tcp连接,如果连接成功,就说明后端正常。
ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。
http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
port: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。默认是0,表示跟后端server提供真实服务的端口一样。该选项出现于Tengine-1.4.0。
我们自己的栗子
tengine新增健康检查模块
配置一个status的location
location /status {
check_status;
}
在upstream配置如下
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
- 完整配置
# 反向代理配置
44 upstream proxyconf {
45 server 192.168.1.63:8080;
46 server 192.168.1.62:8080;
47 check interval=3000 rise=2 fall=5 timeout=1000 type=http;
48 check_http_send "HEAD / HTTP/1.0\r\n\r\n";
49 check_http_expect_alive http_2xx http_3xx;
50 }
51 # 虚主机配置
52 server {
53 listen 80;
54 server_name localhost;
55 location / {
56 root html;
57 index index.html index.htm;
58 proxy_pass http://proxyconf;
59 }
65 location /status {
66 check_status;
67 }
68 }
状态监控图:
健康状态监控.png
图中红色的代表出问题的服务器
评论暂时关闭