• 设备
    • 今日
    • 0

    nginx健康检查部署

    nginx健康检查部署
    关键点:
    1. 安装nginx时,添加nginx_upstream_check_module
    2. 在nginx.conf 加入upstream节点
    3. 在server {} 中的 加入check_status;

    详细部署内容如下:
    yum list installed | grep nginx
    yum remove -y nginx.x86_64
    yum -y install patch
    yum -y install pcre-devel openssl openssl-devel

    cd /home/elsearch/app/
    下载安装nginx
    wget http://nginx.org/download/nginx-1.16.0.tar.gz
    tar -zxvf nginx-1.16.0.tar.gz
    mv /home/elsearch/app/nginx-1.16.0 /usr/local/
    cd /usr/local/nginx-1.16.0/

    下载nginx_upstream_check_module模块
    wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
    unzip master
    mv nginx_upstream_check_module-master nginx_http_upstream_check_module

    导入前提示:
    If you use nginx-1.2.1 or nginx-1.3.0, the nginx upstream round robin
    module changed greatly. You should use the patch named
    'check_1.2.1.patch'.
    If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream
    least_conn module. You should use the patch named 'check_1.2.2+.patch'.
    If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
    module. You should use the patch named 'check_1.2.6+.patch'.
    If you use nginx-1.5.12+, You should use the patch named
    'check_1.5.12+.patch'.
    If you use nginx-1.7.2+, You should use the patch named
    'check_1.7.2+.patch'.

    sed -i -e 's/1.6.2/2.0/g' -e 's/nginx\//LXS/g' -e 's/"NGINX"/"LXS"/g' src/core/nginx.h
    patch -p1 < ./nginx_http_upstream_check_module/check_1.12.1+.patch
    ------成功:输入信息,如果出现FAIL表示错误------
    patching file src/http/modules/ngx_http_upstream_hash_module.c
    Hunk #2 succeeded at 241 (offset 3 lines).
    Hunk #3 succeeded at 571 (offset 22 lines).
    patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
    Hunk #2 succeeded at 211 (offset 3 lines).
    patching file src/http/modules/ngx_http_upstream_least_conn_module.c
    patching file src/http/ngx_http_upstream_round_robin.c
    patching file src/http/ngx_http_upstream_round_robin.h
    ------

    ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=/usr/local/nginx-1.16.0/nginx_http_upstream_check_module/
    make & make install
    //查看版本
    nginx -v
    nginx version: nginx/1.16.0
    //查看版本以及已安装的模块
    nginx -V

    vim /etc/nginx/nginx.conf  //***在http节点下,加入upstream节点***
    worker_processes  1;
    pid        /var/run/nginx.pid;
    events {
    worker_connections  1024;
    }

    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;

    upstream Elastic-Head {
    server    192.168.1.78:9100;
    check interval=3000 rise=2 fall=5 timeout=1000;
    }

    upstream Elastic-master {
    server    192.168.1.78:9200;
    server    192.168.1.78:9201;
    check interval=3000 rise=2 fall=5 timeout=1000;
    }

    upstream kibana {
    server    192.168.1.78:5601;
    check interval=3000 rise=2 fall=5 timeout=1000;
    }

    server {
    listen 80;
    server_name kibana;
    #auth_basic "Restricted Access";
    #auth_basic_user_file /etc/nginx/kibana-user;

    location /ServStatus {
    check_status;
    access_log on;
    }

    location / {
    proxy_pass http://192.168.1.78:5601;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }
    }

    nginx端口映射
    server {
      listen  20050;
      server_name localhost;
       # 20050转发到10050端口
      location / {
          proxy_pass http://172.16.120.23:10050;
      }
    }

    检查配置文件路径
    cd /usr/local/nginx/sbin
    nginx -t -c /usr/local/nginx/conf/nginx.conf 或
    ./nginx -t

    首先利用配置文件启动nginx:
    nginx -c /usr/local/nginx/conf/nginx.conf
    /usr/local/nginx/sbin/nginx -s reload

    listen db_proxy_239 
    bind 0.0.0.0:30050
    maxconn 100
    mode tcp
    option tcplog
    option mysql-check user haproxy_check
    server yqy-rdb_238 172.16.120.239:10050


    问题:nginx -s reload 时出现 invalid PID number "" in "/var/run/nginx.pid"
    说明: :nginx -s reload 适用于nginx在运行中重新加载配置文件. 当nginx在关闭状态下,重新执行nginx的命令为:

    nginx -c /etc/nginx/nginx.conf


    来自:PC 广东省广州市
    上一篇: dataV如何获取某个省的地图(非全国地图)
    您可能还喜欢这些:

    亲,沙发正空着,还不快来抢?

    评论审核已开启 记住我的个人信息 回复后邮件通知我