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\r\n\r\n";
    #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,符合預期就算檢測成功

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM