1、模塊healthcheck_nginx_upstreams前端
http://wiki.nginx.org/HttpHealthcheckModulenginx
一、下載安裝,git
在https://github.com/liseen/healthcheck_nginx_upstreams下載該模塊,沒有公佈的版本,下載時要雙擊打開後,將代碼另存的方式下載,github
也能夠去這裏下載: http://download.csdn.net/detail/ly_stu/5976009後端
二、進入nginx的源碼目錄 爲nginx打補丁 healthcheck.pathch #注意路徑jsp
#patch –p1< ../cep21-healthcheck_nginx_upstreams/healthcheck.patchide
編譯安裝nginx學習
./configure --user=www --group=www--prefix=/usr/local/nginx/ --with- pcre=/usr/local/src/pcre-8.31--with-http_stub_status_module --with-http_ssl_module --add-module=../cep21-healthcheck_nginx_upstreams-b33a846/ && make && make install&& make cleanspa
三、配置nginx.conf healthcheck_nginx_upstreams的context爲upstream .net
分別在兩個站點目錄下建立error.jsp探測頁面,注意防火牆的阻擋,touch error.jsp
http{
……
upstream backend {
server 192.168.15.65:80;
server 192.168.15.183:8080;
#開啓
healthcheck_enabled;
#檢測每一端的延遲,單位爲毫秒
healthcheck_delay 1000;
#超過2000毫秒爲超時
healthcheck_timeout 2000;
#失敗嘗試
healthcheck_failcount 3;
#實際檢測
healthcheck_send "GET /error.jspHTTP/1.0";
}
server{
……
location ~ /health {
healthcheck_status;
access_log off;
allow 192.168.15.65/20;
deny all;
}
……
}
}
網頁查看運行結果:
注意:HttpHealthcheckModule與nginx_upstream_check_module安裝時補丁包有必定衝突,不可同時安裝。
2、模塊nginx_upstream_check_module
獲取該模塊版本包
https://github.com/yaoweibin/nginx_upstream_check_module/releases
進入nginx的解壓目錄:
#patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因nginx版本更新,1.2以上版本的nginx,補丁爲check_1.2.1+.patch
編譯安裝nginx
#./configure --prefix=/usr/local/nginx/ \
--with-pcre=/usr/local/src/pcre-8.31\
--with-http_stub_status_module \
--with-http_ssl_module \
--add-module=/path/to/nginx_http_upstream_check_module
#make && makeinstall && make clean
在nginx.conf配置文件裏面的upstream加入健康檢查,以下:
http{
……
upstreamwww.example.com {
server 192.168.15.187:80;
server 192.168.15.188:80;
#追加下面行就ok了
check interval=1500 rise=2 fall=2 timeout=1000;
}
server{
……
location ~ /nstatus {
check_status;
access_log off;
allow 192.168.1.176;
}
}
}
注:無關配置項省略。
判斷語法,重載nginx服務
[root@master ~]# /usr/local/nginx/sbin/nginx -t
[root@master ~]# /usr/local/nginx/sbin/nginx -s reload
網頁查看運行結果:
雖然上面兩個模塊均可以實現對後端的檢測,但老是有一種雞肋的感受,對於有多個應用前端的生產環境而言,每一個前端都須要安裝該模塊插件,固然也是單獨的頁面顯示,會給用戶返回大量的信息【包括不少正常的信息,其實檢測後端的目的就是了解到錯誤鏈接,並實現告警】,並不理想,並且不能實現告警。繼續學習尋找中[手動寫腳本]……