Nginx使用upstream_check_module模块实现后端节点健康检查功能
1、下载nginx_upstream_check_module模块
#下载nginx_upstream_check_module模块
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master unzip -q master
本博客下载:
nginx_upstream_check_module-master.zip
#进入nginx安装目录
cd /root/soft/nginx/ tar xf nginx-1.15.0.tar.gz cd nginx-1.15.0 patch -p1 < ../nginx_upstream_check_module-master/check_1.11.5+.patch
# -p0,是“当前路径” -p1,是“上一级路径”
#check版本和Nginx版本要求有限制 1.12以上版本的nginx,补丁为check_1.11.5+.patch
因为已经安装了nginx,所以平滑升级nginx
./configure --prefix=/opt/nginx --user=www --group=www --without-http_memcached_module --without-http_map_module --without-http_geo_module --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_realip_module --add-module=../nginx_upstream_check_module-master
make
mv /opt/nginx/sbin/nginx{,.old}
cd objs/
cp nginx /opt/nginx/sbin/
ll /opt/nginx/sbin/
/opt/nginx/sbin/nginx -t
/opt/nginx/sbin/nginx -s reload
/opt/nginx/sbin/nginx -V
cd /opt/nginx/conf/
vi lt_www.conf
添加下面内容
#upstream static_pool {
# server 192.168.206.101;
#}
#
#upstream upload_pool {
# server 192.168.206.102:8080;
#}
upstream default_pool {
server 192.168.206.101:80;
server 192.168.206.102:8080;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
}
server {
listen 80;
server_name www.ceshi.com;
access_log logs/access_www.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://default_pool;
}
location /status {
check_status;
access_log off;
}
# location /upload/ {
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://upload_pool;
# }
#
# location ~* \.(jpg|png)$ {
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://static_pool;
# }
#请求判断转发
# location / {
# if ($http_user_agent ~* "MSIE") {
# proxy_pass http://upload_pool;
# }
#
# if ($http_user_agent ~* "Chrome") {
# proxy_pass http://static_pool;
# }
#
# proxy_pass http://default_pool;
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# }
}
nginx -t
nginx -s reload
http://www.ceshi.com/nstatus#可以查看状态<< 上一篇
下一篇 >>
网友留言(0 条)