zoukankan      html  css  js  c++  java
  • nginx与tengine添加check模块(nginx_upstream_check_module)

    1 nginx 在未安装nginx上编译安装check模块

    [root@localhost ~]# wget  https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
    [root@localhost ~]# tar xf v0.3.0
    [root@localhost ~]# cd nginx_upstream_check_module-0.3.0
    [root@localhost nginx_upstream_check_module-0.3.0]# ls -l
    total 260
    -rw-rw-r-- 1 root root      0 Oct  2  2014 CHANGES
    -rw-rw-r-- 1 root root   5483 Oct  2  2014 check_1.2.1.patch
    -rw-rw-r-- 1 root root   7130 Oct  2  2014 check_1.2.2+.patch
    -rw-rw-r-- 1 root root   7094 Oct  2  2014 check_1.2.6+.patch
    -rw-rw-r-- 1 root root   6791 Oct  2  2014 check_1.5.12+.patch
    -rw-rw-r-- 1 root root   6701 Oct  2  2014 check_1.7.2+.patch
    -rw-rw-r-- 1 root root   6943 Oct  2  2014 check.patch
    -rw-rw-r-- 1 root root    749 Oct  2  2014 config
    drwxrwxr-x 2 root root   4096 Oct  2  2014 doc
    -rw-rw-r-- 1 root root   1709 Oct  2  2014 nginx-sticky-module.patch
    drwxrwxr-x 2 root root   4096 Oct  2  2014 nginx-tests
    -rw-rw-r-- 1 root root  46860 Oct  2  2014 ngx_http_upstream_check_handler.c
    -rw-rw-r-- 1 root root   3718 Oct  2  2014 ngx_http_upstream_check_handler.h
    -rw-rw-r-- 1 root root 112230 Oct  2  2014 ngx_http_upstream_check_module.c
    -rw-rw-r-- 1 root root    529 Oct  2  2014 ngx_http_upstream_check_module.h
    -rw-rw-r-- 1 root root   2848 Oct  2  2014 ngx_http_upstream_jvm_route_module.patch
    -rw-rw-r-- 1 root root  11384 Oct  2  2014 README
    drwxrwxr-x 6 root root   4096 Oct  2  2014 test
    -rw-rw-r-- 1 root root   3342 Oct  2  2014 upstream_fair.patch
    drwxrwxr-x 2 root root   4096 Oct  2  2014 util
    [root@localhost nginx-1.8.1]# patch -p1 < ../nginx_upstream_check_module-0.3.0/check_1.7.2+.patch 
    patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
    patching file src/http/modules/ngx_http_upstream_least_conn_module.c
    patching file src/http/ngx_http_upstream_round_robin.c
    Hunk #1 succeeded at 9 with fuzz 2.
    Hunk #2 succeeded at 95 (offset 4 lines).
    Hunk #3 succeeded at 159 (offset 4 lines).
    Hunk #4 succeeded at 227 (offset 4 lines).
    Hunk #5 succeeded at 339 (offset 4 lines).
    Hunk #6 succeeded at 381 (offset 4 lines).
    Hunk #7 succeeded at 443 (offset 4 lines).
    Hunk #8 succeeded at 541 (offset -1 lines).
    patching file src/http/ngx_http_upstream_round_robin.h
    [root@localhost nginx-1.8.1]# ./configure  --add-module=../nginx_upstream_check_module-0.3.0/
    [root@localhost nginx-1.8.1]# make && make install    
    make[1]: Leaving directory `/home/ceiec/nginx-1.8.1'
    [root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    [root@localhost conf]# head -n 50 nginx.conf
        upstream 8080 {
             server 10.11.1.11:8080 weight=1;
             server 10.11.1.17:8080 weight=1;
    check interval=3000 rise=2 fall=2 timeout=1000 type=http;

    2 编译安装tengine

    [root@localhost ~]# tar -zxvf tengine-2.3.1.tar.gz 
    [root@localhost tengine-2.3.1]# mkdir -p /opt/tengine
    [root@localhost tengine-2.3.1]# ./configure --prefix=/opt/tengine --without-http_upstream_keepalive_module 
     --add-module=modules/ngx_backtrace_module 
     --add-module=modules/ngx_debug_pool 
     --add-module=modules/ngx_debug_timer 
     --add-module=modules/ngx_http_concat_module 
     --add-module=modules/ngx_http_footer_filter_module 
     --add-module=modules/ngx_http_proxy_connect_module 
     --add-module=modules/ngx_http_reqstat_module 
     --add-module=modules/ngx_http_slice_module 
     --add-module=modules/ngx_http_sysguard_module 
     --add-module=modules/ngx_http_trim_filter_module 
     --add-module=modules/ngx_http_upstream_check_module 
     --add-module=modules/ngx_http_upstream_consistent_hash_module 
     --add-module=modules/ngx_http_upstream_dynamic_module 
     --add-module=modules/ngx_http_upstream_dyups_module 
     --add-module=modules/ngx_http_upstream_keepalive_module 
     --add-module=modules/ngx_http_upstream_session_sticky_module 
     --add-module=modules/ngx_http_user_agent_module
    [root@localhost tengine-2.3.1]# make && make install
    [root@localhost conf]# /opt/tengine/sbin/nginx -V
    Tengine version: Tengine/2.3.1
    nginx version: nginx/1.16.0
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 
    built with OpenSSL 1.0.1e-fips 11 Feb 2013
    TLS SNI support enabled
    configure arguments: --prefix=/opt/tengine --without-http_upstream_keepalive_module --add-module=modules/ngx_backtrace_module --add-module=modules/ngx_debug_pool --add-module=modules/ngx_debug_timer --add-module=modules/ngx_http_concat_module --add-module=modules/ngx_http_footer_filter_module --add-module=modules/ngx_http_proxy_connect_module --add-module=modules/ngx_http_reqstat_module --add-module=modules/ngx_http_slice_module --add-module=modules/ngx_http_sysguard_module --add-module=modules/ngx_http_trim_filter_module --add-module=modules/ngx_http_upstream_check_module --add-module=modules/ngx_http_upstream_consistent_hash_module --add-module=modules/ngx_http_upstream_dynamic_module --add-module=modules/ngx_http_upstream_dyups_module --add-module=modules/ngx_http_upstream_keepalive_module --add-module=modules/ngx_http_upstream_session_sticky_module --add-module=modules/ngx_http_user_agent_module
    [root@localhost conf]# /opt/tengine/sbin/nginx -c /opt/tengine/conf/nginx.conf
    [root@localhost conf]# ps -ef|grep nginx
    root      8000     1  0 09:00 ?        00:00:00 nginx: master process /opt/tengine/sbin/nginx -c /opt/tengine/conf/nginx.conf
    root      8001  8000  0 09:00 ?        00:00:00 nginx: worker process                                  
    root      8002  8000  0 09:00 ?        00:00:00 nginx: worker process                                  
    root      8003  8000  0 09:00 ?        00:00:00 nginx: worker process                                  
    root      8004  8000  0 09:00 ?        00:00:00 nginx: worker process                                  
    root      8010 26644  0 09:00 pts/0    00:00:00 grep nginx
    [root@localhost keepalived]# /opt/tengine/sbin/nginx -c /opt/tengine/conf/nginx.conf -t
    nginx: the configuration file /opt/tengine/conf/nginx.conf syntax is ok
    nginx: configuration file /opt/tengine/conf/nginx.conf test is successful
    [root@localhost keepalived]# /etc/init.d/keepalived start
    [root@localhost keepalived]# ip a

    3 在已经存在的nginx上面,添加check模块

    [root@localhost nginx_upstream_check_module-0.3.0]# /usr/local/nginx/sbin/nginx -V
    nginx version: nginx/1.8.1
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 
    configure arguments:
    [root@localhost nginx_upstream_check_module-0.3.0]# cd /home/ceiec/nginx-1.8.1
    [root@localhost nginx-1.8.1]# patch -p1 < /home/test/nginx_upstream_check_module-0.3.0/check_1.7.2+.patch 
    patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
    patching file src/http/modules/ngx_http_upstream_least_conn_module.c
    patching file src/http/ngx_http_upstream_round_robin.c
    Hunk #1 succeeded at 9 with fuzz 2.
    Hunk #2 succeeded at 95 (offset 4 lines).
    Hunk #3 succeeded at 159 (offset 4 lines).
    Hunk #4 succeeded at 227 (offset 4 lines).
    Hunk #5 succeeded at 339 (offset 4 lines).
    Hunk #6 succeeded at 381 (offset 4 lines).
    Hunk #7 succeeded at 443 (offset 4 lines).
    Hunk #8 succeeded at 541 (offset -1 lines).
    patching file src/http/ngx_http_upstream_round_robin.h
    [root@localhost nginx-1.8.1]# ./configure --add-module=../nginx_upstream_check_module-0.3.0
    [root@localhost nginx-1.8.1]# make  ##注意:此处只make,编译参数需要和之前的一样,不要执行make install,否则就会覆盖正在使用的nginx)
    make[1]: Leaving directory `/home/test/nginx-1.8.1'
    make -f objs/Makefile manpage
    make[1]: Entering directory `/home/test/nginx-1.8.1'
    sed -e "s|%%PREFIX%%|/usr/local/nginx|" 
            -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" 
            -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" 
            -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" 
            < man/nginx.8 > objs/nginx.8
    make[1]: Leaving directory `/home/ceiec/nginx-1.8.1'
    [root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx -t
    nginx: [emerg] unknown directive "check" in /usr/local/nginx/conf/nginx.conf:24
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    [root@localhost nginx-1.8.1]# /usr/local/nginx/sbin/nginx
    nginx: [emerg] unknown directive "check" in /usr/local/nginx/conf/nginx.conf:24

    上面显示添加patch的时候,是添加成功,但是编译还是提示check错误

    check模块语法

    check interval=milliseconds [fall=count] [rise=count][timeout=milliseconds] [default_down=true|false][type=tcp|http|ssl_hello|mysql|ajp|fastcgi]
    check interval=5000 rise=1 fall=3 timeout=4000;
        #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
        #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        #check_http_send "HEAD / HTTP/1.0
    
    ";
        #check_http_expect_alive http_2xx http_3xx;
    默认配置:interval=3000 fall=5 rise=2 timeout=1000 default_down=true type=tcp*
    interval: 检测间隔3秒
    fall: 连续检测失败次数5次时,认定relaserver is down
    rise: 连续检测成功2次时,认定relaserver is up
    timeout: 超时1秒
    default_down: 初始状态为down,只有检测通过后才为up
    type: 检测类型方式 tcp
    1. tcp :tcp 套接字,不建议使用,后端业务未100%启动完成,前端已经放开访问的情况
    2. ssl_hello: 发送hello报文并接收relaserver 返回的hello报文
    3. http: 自定义发送一个请求,判断上游relaserver 接收并处理
    4. mysql: 连接到mysql服务器,判断上游relaserver是否还存在
    5. ajp: 发送AJP Cping数据包,接收并解析AJP Cpong响应以诊断上游relaserver是否还存活(AJP tomcat内置的一种协议)
    6. fastcgi: php程序是否存活
    check_http_send 指令    
    该指令可以让负载均衡器模拟向后端realserver发送,监控检测的http包,模拟LVS的检测。
    check_http_expect_alive 指令
    check_http_expect_alive [ http_2xx | http_3xx | http_4xx | http_5xx ]
    返回指定HTTP code,符合预期就算检测成功
  • 相关阅读:
    rsync+crontab 企业实战 全量备份
    添加共享文件盘,切换用户访问共享
    一天电你千百回,这样做远离静电你造么~
    Network Password Recovery工具查看windows凭据密码
    su 和su
    运维面试 怎么实现程序自启
    在tomcat中配置域名的方法
    使用windows update blocker工具关闭windows系统自动更新
    CVM 母机透传,什么是透传模块?为什么要透传?
    硬盘接口类型
  • 原文地址:https://www.cnblogs.com/yhq1314/p/12753719.html
Copyright © 2011-2022 走看看