您的位置:首页 > 运维架构 > Nginx

nginx模块nginx_upstream_check_module来检查后端服务器的健康情况

2014-09-20 15:41 507 查看
大家都知道,前端nginx做反代,如果后端服务器宕掉的话,nginx是不能把这台realserver剔出upstream的,所以还会有请求转发到后端的这台realserver上面去,虽然nginx可以在localtion中启用proxy_next_upstream来解决返回给用户的错误页面,方法在:http://www.linuxyan.com/web-server/67.html,大家可以参考一下,但这个还是会把请求转发给这台服务器的,然后再转发给别的服务器,这样就浪费了一次转发,这次借助与淘宝技术团队开发的nginx模快nginx_upstream_check_module来检测后方realserver的健康状态,如果后端服务器不可用,则所以的请求不转发到这台服务器。 减少一次转发。。

首先去这里下载nginx的模块https://github.com/yaoweibin/nginx_upstream_check_module
下面是nginx打上模块补丁的安装 ,但是现在tengine已经自带了这个模块,不再需要加这个第三方模块,直接配置就行了。【$ wget ‘http://nginx.org/download/nginx-1.0.14.tar.gz’
$ tar -xzvf nginx-1.0.14.tar.gz
$ cd nginx-1.0.14/
$ patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因nginx版本更新,1.2以上版本的nginx,补丁为check_1.2.1+.patch
$ ./configure –add-module=/path/to/nginx_http_upstream_check_module
$ make
$ make install】
之后在nginx.conf配置文件里面的upstream加入健康检查,如下:
upstream www_server_pool {
server 192.168.0.21:80;
server 192.168.0.22:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "GET / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}我觉得nginx_upstream_check_module 检查健康状态,结合--with-http_stub_status_module 显示realserver的状态现在tengine已经自动带了次模块,所以不需要再编译,直接配置即可
./configure  --with-http_stub_status_module
这里下面加的这句话我解释下:interval检测间隔时间,单位为毫秒,5分钟rsie请求2次正常的话,标记此realserver的状态为up,fall表示请求5次都失败的情况下,标记此realserver的状态为down,timeout为超时时间,单位为毫秒。
在server段里面可以加入查看realserver状态的页面
location /nstatus {
check_status;
access_log off;
#allow SOME.IP.ADD.RESS;
#deny all;
}这个时候打开nstatus这个页面就可以看到当前realserver的状态了,
如下图:HTTP://www.qq.com/status
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐