nginx负载均衡检测节点状态

版权声明:silly8543 https://blog.csdn.net/cen50958/article/details/89715875

 nginx需要打补丁的方式将该模块添加到nginx中,原生不支持.

1.官方地址

https://github.com/yaoweibin/nginx_upstream_check_module

2.安装nginx_upstream_check_module模块

 系统如果已经安装nginx,则需要采取打补丁的方式安装该模块

  • 查看安装版本

    /application/nginx/sbin/nginx -v
    
  • 下载补丁包

    wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
    
  • 解压下载的补丁包

     unzip master
    
  • 重新编译nginx
    因为是对nginx打补丁,需要对应安装版本的软件包

     cd nginx-1.15.12
     patch -p1 < ../nginx_upstream_check_module-master/check_1.14.0+.patch 
    

    编译参数要和以前一样,最后加上 --add-module=…/nginx_upstream_check_module-master/

     ./configure  --user=www  --group=www  --prefix=/application/nginx-1.15.2  --with-http_ssl_module  --with-http_gzip_static_module  --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/
    
  • 安装

    make
    

    如果是新增的nginx则继续执行make install,给已经安装的nginx系统打监控补丁则不需要执行make install。
    将打过补丁的nginx二进制程序复制到sbin目录下

     //备份
     mv /application/nginx/sbin/nginx{,.ori}
     //拷贝
     cp ./objs/nginx /application/nginx/sbin/
    
  • 检查是否正常

     /application/nginx/sbin/nginx -t
    

    在这里插入图片描述

     /application/nginx/sbin/nginx -V
    

    在这里插入图片描述

3.配置健康检查
  • 开启检查
      location /check{
          check_status;
          access_log  off;
       }
    
  • 完整nginx配置
    http {
    include       mime.types;
    default_type  application/octet-stream;
    
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
    #access_log  logs/access.log  main;
    
    sendfile        on;
    #tcp_nopush     on;
    
    #keepalive_timeout  0;
    keepalive_timeout  65;
    
    #gzip  on;
    
    server {
        listen       80;
        server_name  localhost;
    
        location / {
            auth_basic           "study site";
            auth_basic_user_file /application/nginx/conf/htpasswd;
            root   html;
            index  index.html index.htm;
        }
    
        location /url {
           proxy_pass http://cluster;
        }
    
         
        location /status {
           stub_status on;
           access_log off;
        }
       
       location /check{
          check_status;
          access_log  off;
       }
      }
     upstream cluster {
    	server 192.168.0.1:80;
    	server 192.168.0.2:80;
    	check interval=5000 rise=1 fall=3 timeout=4000;
    	}
    }
    
4.效果图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/cen50958/article/details/89715875
今日推荐