Nginx上游节点健康检测

Nginx默认是没有支持上游节点健康检测的。

可以使用Tengine

文档 - The Tengine Web Server

或者自行下载nginx然后自己安装nginx_upstream_check_module 模块

在linux下载nginx

 wget http://nginx.org/download/nginx-1.25.1.tar.gz 

 下载插件 GitHub - yaoweibin/nginx_upstream_check_module: Health checks upstreams for nginx

 

在这里,我们可以将nginx上传解压到/opt/目录下,可以直接在/opt/目录下直接下载nginx在/opt/目录解压

tar -xf nginx-1.25.1.tar.gz

进入目录

cd nginx-1.25.1

给nginx打补丁

 patch -p1 </opt/nginx_upstream_check_module-master/check_1.20.1+.patch

安装,编译, 此时可能会缺少依赖,如openssl之类的,可以一直使用命令检查,然后缺什么补什么,我这里使用的是ubuntu系统,可以使用apt-get下载

 ./configure --add-module=/opt/nginx_upstream_check_module-master

编译安装,会报错的话就根据错误信息检查缺失的依赖,apt-get下载安装即可

make install

 可以看见nginx的产物在/usr/local/nginx目录下

进入目录

cd /usr/local/nginx/sbin/

确认配置,可以看见已经安装的模块

 /usr/local/nginx/sbin/nginx -V

 

接下来修改nginx.conf文件,这个配置可以参考ngx_http_upstream_check_module - The Tengine Web Server

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    upstream hello {

        server 192.168.2.1:8080;
        server 192.168.2.1:8081;

        check interval=3000 rise=2 fall=5 timeout=2000 type=http default_down=true ;
        check_keepalive_requests 1;
        #check_http_send "GET /hello HTTP/1.1\r\n\r\n";
	#一定要Host不然服务器没返回200
        check_http_send "GET /hello?appId=denglintao HTTP/1.1\r\nHost:hello\r\nConnection: keep-alive\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx  ;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://hello;
        }

        location /nstatus {
            check_status;
            access_log off;
        }
    }
}

 启动nginx,进入目录/usr/local/nginx/sbin/

./nginx

停止nginx

./nginx -s stop

访问nginx对上游节点的健康检测状态页面

 http://ip:prot/nstatus

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邓霖涛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值