该模块可以为Tengine提供主动式后端服务器健康检查的功能。可以通过补丁的方式来添加该模块到我们自己的nginx中。
下载nginx_upstream_check_module模块
1 | git clone https://github.com/yaoweibin/nginx_upstream_check_module.git |
编译补丁到nginx,必须使用最新的nginx_upstream_check_module才支持nginx 1.12.2版本1
2
3
4
5
6
7cd ~/nginx-1.12.2 ##进入nginx的源码目录
nginx-1.12.2]# patch -p1 < ../nginx_upstream_check_module/check_1.12.1+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
查看之前的nginx编译参数
1 | # /usr/local/nginx/sbin/nginx -V |
编译nginx参数,此处只make 不要make install,编译参数需要和之前的一样添加–add-module=1
2
3
4
5
6
7
8
9
10
11
12
13# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --add-module=../nginx_upstream_check_module/
make
.....
trueobjs/addon/nginx_upstream_check_module/ngx_http_upstream_check_module.o \
trueobjs/ngx_modules.o \
true-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz \
true-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
truetrue-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
truetrue-e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \
truetrue-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
truetrue< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-1.12.2'
1 | 备份旧版本nginx |
验证版本已经升级到1.12.2 添加了nginx_upstream_check_module模块
1 | nginx-1.12.2]# /usr/local/nginx/sbin/nginx -V |
健康检查模块配置:参照官网http://tengine.taobao.org/document_cn/http_upstream_check_cn.html1
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;
}