- A+
1. Nginx负载均衡检测节点状态
下载地址:https://github.com/yaoweibin/nginx_upstream_check_module
(1) 下载解压nginx_upstream_check_module-master模块
cd /home/soft unzip nginx_upstream_check_module-master.zip cd nginx-1.6.3
(2) 因为是对源程序打补丁,所以还需要nginx软件包
cd /home/soft/nginx-1.6.3 patch -p1 < /home/soft/nginx_upstream_check_module-master/check_1.5.12+.patch
上面的命令会生成以下文件
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 [root@lb01 nginx-1.6.3]# cd /home/oldboy/tools/nginx-1.6.3
编译之前最好将nginx的配置文件备份一份,防止覆盖
tar zcf /opt/lb_nginx_conf.tar.gz /application/nginx/conf/* ll /opt/
(3)开始编译安装Nginx软件,添加nginx_upstream_check_module-master模块
cd /home/soft/nginx-1.6.3 ./configure \ --prefix=/application/nginx-1.6.3 \ --user=nginx \ --group=nignx \ --with-http_stub_status_module \ --with-http_ssl_module \ --add-module=/home/oldboy/tools/nginx_upstream_check_module-master/ echo $?
(4)对于新安装的nginx则继续执行下面的make install,如果已经安装则不用,make的作用就是重新生成nginx二进制的启动命令而已
make echo $?
(5)将打过补丁的二进制命令复制到/application/nginx/sbin/目录下
mv /application/nginx/sbin/nginx{,.ori} cd /home/soft/nginx-1.6.3 cp ./objs/nginx /application/nginx/sbin/ ll /application/nginx/sbin/
(6)检查是否正常
/application/nginx/sbin/nginx -t
(7)查看Nginx的编译参数,是否有nginx_upstream_check_module-master模块
/application/nginx/sbin/nginx -V
(8)配置Nginx支持健康检查
## vim /application/nginx/conf/nginx.conf upstream www_server_pools{ server 10.0.0.7:80; server 10.0.0.8:80; check interval=3000 rise=2 fall=5 timeout=1000 type=http; }
将下面的内容放在第一个虚拟主机的server标签里
location /status { check_status; access_log off; }
(9)重启nginx服务其实生效,一定要重启哦
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx -s stop /application/nginx/sbin/nginx
(10)打开浏览器输入“ http://IP/status ”即可查看后端节点的状态
2. 检测后端节点故障测试
(1)将web01的nginx服务关闭,查看是否报故障
/application/nginx/sbin/nginx -s stop
(2)Nginx的监控检查会将故障的web服务剔除,当服务器正常是将会自动加入,解决了负载均衡器节点处故障的问题。