• Nginx第三方模块nginx_upstream_check_module实现http检测


    1. 故障现象

    架构如下:
    在这里插入图片描述
    当时servera的容器oom了,开始不停重启,造成80端口是活着的,但没法正常提供http服务
    原先的配置如下:

    upstream aaa {
    	server 192.168.31.17;
    	server 192.168.31.27;
    }
    server {
    	listen 192.168.31.67:80;
            server_name aa.qiuqin.com 192.168.31.67;
            location / {
                proxy_pass http://aaa;
            }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    2. 安装和配置Nginx第三方模块

    2.1 下载nginx_upstream_check_module

    https://github.com/yaoweibin/nginx_upstream_check_module
    在这里插入图片描述

    2.2 下载nginx

    https://nginx.org/en/download.html
    在这里插入图片描述

    2.3 安装依赖

    yum install -y gcc‐c++ pcre pcre‐devel zlib zlib‐devel openssl openssl‐devel patch pcre-devel zlib unzip
    
    • 1

    2.4 上传nginx和nginx_upstream_check_module

    mkdir -p /apps/install/
    cd /apps/install/
    unzip nginx_upstream_check_module-master.zip
    tar xf nginx-1.20.2.tar.gz
    
    • 1
    • 2
    • 3
    • 4

    2.5 为nginx更新模块补丁

    cd /apps/install/nginx-1.20.2
    patch -p1 < /apps/install/nginx_upstream_check_module-master/check_1.20.1+.patch
    
    • 1
    • 2

    2.6 编辑安装nginx

    由于是测试环境新装就直接configure了

    ./configure --with-http_stub_status_module \
                --add-module=/apps/install/nginx_upstream_check_module-master
                make -j 4 && make install
                ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    如果是原来的升级先执行

    nginx -V
    
    • 1

    把原来的配置复制出来,再追加–with-http_stub_status_module --add-module=/apps/install/nginx_upstream_check_module-master

    3. 配置文件修改

    我单独配置了个conf,也可以直接写在nginx.conf里
    /usr/local/nginx/conf/conf.d/aa.conf

    参数含义
    interval检测间隔时间,单位为毫秒
    rsie请求2次正常的话,标记此realserver的状态为up
    fall表示请求5次都失败的情况下,标记此realserver的状态为down
    timeout为超时时间,单位为毫秒。
    upstream aaa {
    	server 192.168.31.17;
    	server 192.168.31.27;
            check interval=3000 rise=2 fall=5 timeout=1000 type=http;
            check_http_send "HEAD / HTTP/1.0\r\n\r\n";
            check_http_expect_alive http_2xx http_3xx;
    }
    server {
    	listen 192.168.31.67:80;
            server_name aa.qiuqin.com 192.168.31.67;
            location / {
                proxy_pass http://aaa;
            }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    3.1 测试效果

    两台web都正常启动
    在这里插入图片描述
    关闭27的nginx,并启动80的监听
    在这里插入图片描述
    此时27上80端口可以被telnet到,但nginx已经不会再转发请求了
    在这里插入图片描述

  • 相关阅读:
    前后端接口调用传参方式总结
    举个栗子~ Minitab 技巧(1):快速安装和激活 Minitab 统计软件
    驱动开发--自动创建设备节点udev机制的实现过程
    在线程中使用Spring的Bean的方法、不推荐把“线程”注入到Spring
    【红队】ATT&CK - 自启动 - 利用LSA身份验证包自启动机制
    Spring 中如何为Bean注入集合呢?
    Java的JDBC编程
    JS正则表达式
    this 指向问题
    Redis 消息队列:构建消息代理的 4 个简单步骤
  • 原文地址:https://blog.csdn.net/qq_29974229/article/details/126100045