码迷,mamicode.com
首页 > 其他好文 > 详细

配置 Nginx 负载均衡监测节点状态

时间:2017-06-03 12:41:04      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:pre   unzip   bmp   css   int   als   不可用   pes   分支   

淘宝技术团队开发了一个 Tengine ( Nginx 的分支 ) 模块 nginx_upstream_check_module ,用于提供主动式后端服务器健康检查,通过它可以检测后端 realserver 的健康状态,如果后端 realserver 不可用,则所有的请求就不会转发到该节点上,需要通过打补丁的方式将该模块添加到 Nginx 中。

1、安装 nginx_upstream_check_module 模块

cd /usr/local/src
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
yum install -y unzip patch
upzip master
cd nginx-1.6.3
patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/
make
mv /usr/local/nginx/sbin/nginx{,.ori}
cp ./objs/nginx /usr/local/nginx/sbin/
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -V

 

2、配置 Nginx 健康检查

[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;    
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    
upstream static_pools {
server 192.168.123.103:80 weight=1;
server 192.168.123.104:80 weight=1;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
}

# 上面配置的意思是:对 static_pools 这个负载均衡条目中的所有节点,每隔 3 秒检测一次,请求 2 次正常则标记 realserver 状态为 up ,如果检测 5 次都失败,则标记 realserver 状态为 down ,超时时间为 1 秒,检查的协议是 HTTP

upstream default_pools{ server 192.168.123.103:80 weight=1;
}
server { listen 80; server_name bbs.abc.com; location / { root html/bbs; index index.html index.htm;
proxy_pass http://default_pools;
include proxy.conf; }
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
proxy_pass http://static_pools;
include proxy.conf;
}

location /status {
check_status;
access_log off;
}
}
}
[root@localhost conf]# cat proxy.conf
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
# 重启 Nginx ,注意不是重新加载
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

 

3、查看结果

技术分享

 

 

 

 

    

配置 Nginx 负载均衡监测节点状态

标签:pre   unzip   bmp   css   int   als   不可用   pes   分支   

原文地址:http://www.cnblogs.com/pzk7788/p/6936667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!