nginx后端服务器状态检测
2013-11-19 20:46
766 查看
一、模块healthcheck_nginx_upstreamshttp://wiki.nginx.org/HttpHealthcheckModule1、下载安装,
在https://github.com/liseen/healthcheck_nginx_upstreams下载该模块,没有公布的版本,下载时要双击打开后,将代码另存的方式下载,
也可以去这里下载: http://download.csdn.net/detail/ly_stu/5976009
2、进入nginx的源码目录 为nginx打补丁 healthcheck.pathch #注意路径
#patch –p1< ../cep21-healthcheck_nginx_upstreams/healthcheck.patch
编译安装nginx
./configure --user=www --group=www--prefix=/usr/local/nginx/ --with- pcre=/usr/local/src/pcre-8.31--with-http_stub_status_module --with-http_ssl_module --add-module=../cep21-healthcheck_nginx_upstreams-b33a846/ && make && make install&& make clean
3、配置nginx.conf healthcheck_nginx_upstreams的context为upstream
分别在两个站点目录下创建error.jsp探测页面,注意防火墙的阻挡,touch error.jsp
http{
……
upstream backend {
server 192.168.15.65:80;
server 192.168.15.183:8080;
#开启
healthcheck_enabled;
#检测每一端的延迟,单位为毫秒
healthcheck_delay 1000;
#超过2000毫秒为超时
healthcheck_timeout 2000;
#失败尝试
healthcheck_failcount 3;
#实际检测
healthcheck_send "GET /error.jspHTTP/1.0";
}
server{
……
location ~ /health {
healthcheck_status;
access_log off;
allow 192.168.15.65/20;
deny all;
}
……
}
}
网页查看运行结果:
注意:HttpHealthcheckModule与nginx_upstream_check_module安装时补丁包有一定冲突,不可同时安装。
二、模块nginx_upstream_check_module
获取该模块版本包
https://github.com/yaoweibin/nginx_upstream_check_module/releases
进入nginx的解压目录:
#patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因nginx版本更新,1.2以上版本的nginx,补丁为check_1.2.1+.patch
编译安装nginx
#./configure --prefix=/usr/local/nginx/ \
--with-pcre=/usr/local/src/pcre-8.31\
--with-http_stub_status_module \
--with-http_ssl_module \
--add-module=/path/to/nginx_http_upstream_check_module
#make && makeinstall && make clean
在nginx.conf配置文件里面的upstream加入健康检查,如下:http{
……
upstreamwww.example.com {
server 192.168.15.187:80;
server 192.168.15.188:80;
#追加下面行就ok了
check interval=1500 rise=2 fall=2 timeout=1000;
}
server{
……
location ~ /nstatus {
check_status;
access_log off;
allow 192.168.1.176;
}
}
}
注:无关配置项省略。
判断语法,重载nginx服务
[root@master ~]# /usr/local/nginx/sbin/nginx -t
[root@master ~]# /usr/local/nginx/sbin/nginx -s reload
网页查看运行结果:
虽然上面两个模块都可以实现对后端的检测,但总是有一种鸡肋的感觉,对于有多个应用前端的生产环境而言,每个前端都需要安装该模块插件,当然也是单独的页面显示,会给用户返回大量的信息【包括很多正常的信息,其实检测后端的目的就是了解到错误连接,并实现告警】,并不理想,而且不能实现告警。继续学习寻找中[手动写脚本]……
本文出自 “刘园的博客” 博客,请务必保留此出处http://colynn.blog.51cto.com/5971950/1328863
在https://github.com/liseen/healthcheck_nginx_upstreams下载该模块,没有公布的版本,下载时要双击打开后,将代码另存的方式下载,
也可以去这里下载: http://download.csdn.net/detail/ly_stu/5976009
2、进入nginx的源码目录 为nginx打补丁 healthcheck.pathch #注意路径
#patch –p1< ../cep21-healthcheck_nginx_upstreams/healthcheck.patch
编译安装nginx
./configure --user=www --group=www--prefix=/usr/local/nginx/ --with- pcre=/usr/local/src/pcre-8.31--with-http_stub_status_module --with-http_ssl_module --add-module=../cep21-healthcheck_nginx_upstreams-b33a846/ && make && make install&& make clean
3、配置nginx.conf healthcheck_nginx_upstreams的context为upstream
分别在两个站点目录下创建error.jsp探测页面,注意防火墙的阻挡,touch error.jsp
http{
……
upstream backend {
server 192.168.15.65:80;
server 192.168.15.183:8080;
#开启
healthcheck_enabled;
#检测每一端的延迟,单位为毫秒
healthcheck_delay 1000;
#超过2000毫秒为超时
healthcheck_timeout 2000;
#失败尝试
healthcheck_failcount 3;
#实际检测
healthcheck_send "GET /error.jspHTTP/1.0";
}
server{
……
location ~ /health {
healthcheck_status;
access_log off;
allow 192.168.15.65/20;
deny all;
}
……
}
}
网页查看运行结果:
注意:HttpHealthcheckModule与nginx_upstream_check_module安装时补丁包有一定冲突,不可同时安装。
二、模块nginx_upstream_check_module
获取该模块版本包
https://github.com/yaoweibin/nginx_upstream_check_module/releases
进入nginx的解压目录:
#patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因nginx版本更新,1.2以上版本的nginx,补丁为check_1.2.1+.patch
编译安装nginx
#./configure --prefix=/usr/local/nginx/ \
--with-pcre=/usr/local/src/pcre-8.31\
--with-http_stub_status_module \
--with-http_ssl_module \
--add-module=/path/to/nginx_http_upstream_check_module
#make && makeinstall && make clean
在nginx.conf配置文件里面的upstream加入健康检查,如下:http{
……
upstreamwww.example.com {
server 192.168.15.187:80;
server 192.168.15.188:80;
#追加下面行就ok了
check interval=1500 rise=2 fall=2 timeout=1000;
}
server{
……
location ~ /nstatus {
check_status;
access_log off;
allow 192.168.1.176;
}
}
}
注:无关配置项省略。
判断语法,重载nginx服务
[root@master ~]# /usr/local/nginx/sbin/nginx -t
[root@master ~]# /usr/local/nginx/sbin/nginx -s reload
网页查看运行结果:
虽然上面两个模块都可以实现对后端的检测,但总是有一种鸡肋的感觉,对于有多个应用前端的生产环境而言,每个前端都需要安装该模块插件,当然也是单独的页面显示,会给用户返回大量的信息【包括很多正常的信息,其实检测后端的目的就是了解到错误连接,并实现告警】,并不理想,而且不能实现告警。继续学习寻找中[手动写脚本]……
本文出自 “刘园的博客” 博客,请务必保留此出处http://colynn.blog.51cto.com/5971950/1328863
相关文章推荐
- nginx安装healthcheck_nginx_upstreams检测后端服务器状态
- nginx自动检测后台服务器健康状态
- Nginx 服务器开启status页面检测服务状态
- nginx后端服务器返回给nginx502、504、404、执行超时等错误状态的解决方法
- LVS自动化添加及删除ipvsadm和后端服务器健康状态检测脚本
- nginx 前端调度 对后端的app的生存状态的检测
- nginx后端服务器返回给nginx502、504、404、执行超时等错误状态的解决方法
- nginx自动检测后台服务器健康状态
- ipvsadm-2 DR模式及自动检测后端服务器状态
- nginx后端服务器返回给nginx502、504、404、执行超时等错误状态的解决方法
- Nginx 服务器开启status页面检测服务状态
- nginx做反向负载均衡,后端服务器获取真实客户端ip
- nginx负载均衡向后台传递参数方法(后端也是nginx服务器)
- nginx 后端服务器配置端口 request.getserverPort
- nginx_upstream_check_module-master对nginx的后端机器进行健康状态检查报403错误【转】
- 带健康状态监测的nginx做反向代理多台服务器实现负载均衡
- 解决nginx到后端服务器Connection: close问题
- nginx利用第三方模块nginx_upstream_check_module来检查后端服务器的健康情况
- Nginx反向代理检测集群节点状态
- 利用nginx-status监控nginx服务器状态