1. 程式人生 > >Nginx負載均衡監控節點狀態

Nginx負載均衡監控節點狀態

server 解壓縮 androi 配置文件 round ref 配置 engine get

  利用第三方插件監控(淘寶開發的Tengine)

模塊:nginx_upstream_check_module

實現web界面

下載補丁包

wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

解壓縮

unzip master

drwxr-xr-x 6 root root 4096 11月 10 18:58 nginx_upstream_check_module-master

cd nginx-1.6.3

打補丁

patch -p1 <../nginx_upstream_check_module-master/check_1.5.12+.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
patching file src/http/ngx_http_upstream_round_robin.h

重新編譯(最好先備份一下之間的配置文件)

./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/

make

(如果新的nginx就makeinstall 如果不是新的nginx,就不用makeinstall了)

把之前nginx啟動文件裏的文件備份一下

mv /application/nginx/sbin/nginx{,.bak}

將補丁的nginx二進制文件復制到/application/nginx/sbin/

cp ./objs/nginx /application/nginx/sbin/

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

檢查模塊

/application/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx_upstream_check_module-master/

添加一個參數

vim /application/nginx/conf/nginx.conf

在每一個upstream裏添加一行

upstream android_pools {
server 192.168.70.127:80 weight=1; #apache
check interval=3000 rise=2 fall=5 timeout=1000 type=http;

#interval 3秒檢查

#rise 宕機請求2次,好了加進來

#fall 宕機壞了 請求5次,還不行提出

#timeout 超時一秒
}

在server裏添加

location /status {
check_status;
access_log off;
}

訪問網址

192.168.70.131

技術分享圖片

Name 節點

status 狀態

Rise 宕機啟動次數

fall 宕機次數

check type 檢查類型

check prot 端口

Nginx負載均衡監控節點狀態