利用tengine的nginx_upstream_check_module来检测后端服务状态

nginx_upstream_check_module 是专门提供负载均衡器内节点的健康检查的外部模块,由淘宝的姚伟斌大神开发,通过它可以用来检测后端 realserver 的健康状态。如果后端 realserver 不可用,则后面的请求就不会转发到该节点上,并持续检查几点的状态。在淘宝自己的 tengine 上是自带了该模块。项目地址:https://github.com/yaoweibin/nginx_upstream_check_module
参考文档:https://www.cnblogs.com/paul8339/p/8124739.html

(1)源码编译安装tengine2.1.2版本

yum install pcre pcre-devel openssl openssl-devel gcc make zlib-devel wget -y
mkdir /tools
cd /tools/
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
useradd nginx -s /sbin/nologin 
tar xf tengine-2.1.2.tar.gz
cd tengine-2.1.2
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx2.1.2 --with-http_stub_status_module --with-http_ssl_module --with-http_upstream_check_module --with-http_gzip_static_module
make && make install
ln -sv /usr/local/nginx2.1.2/ /usr/local/nginx
echo "export PATH=/usr/local/nginx/sbin:$PATH" >>/etc/profile
source /etc/profile
echo "/usr/local/nginx/sbin/nginx"  >>/etc/rc.local
nginx
cd /usr/local/nginx/conf
egrep -v "#|^$" nginx.conf.default >nginx.conf

(2)nginx配置

#vim /usr/local/nginx/conf.d/www.test.com.conf 
upstream node {
    ip_hash;
    server 192.9.191.31:8001;
    server 192.9.191.31:8002;
    server 192.9.191.31:8003;
    check interval=1000 rise=1 fall=1 timeout=1000 type=http;   
    check_http_send "GET /index.html HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
        }
server {
    listen       80;
     server_name  www.test.com;
        location / {
                proxy_pass http://node;
            }
        location /status {                                  //开启状态页面
            check_status;
            access_log   off;
            allow 192.9.191.0/24;
            deny all;
            }
       }

参数详解

check interval=1000 rise=1 fall=1 timeout=1000 type=http;   
        interval检测间隔时间,单位毫秒
        rise请求1次正常的话,标记此realserver的状态为up
        fall表示请求1次都失败的请求,标记此realserver的状态为down
        timeout超时时间,单位毫秒
        type是http类型
check_http_send "GET /index.html HTTP/1.0\r\n\r\n";
        可以使用GET方法,POST,HEAD等方法获取资源  /index.html表示请求的资源,
check_http_expect_alive http_2xx http_3xx;
        状态码是2xx和3xx就认为后端服务是正常的

(3)验证

http://www.test.com/status
1195071-20180520003909227-583612599.png
断开1个服务
1195071-20180520003945440-1967004762.png

转载于:https://www.cnblogs.com/lovelinux199075/p/9062256.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值