一、子產品healthcheck_nginx_upstreams
<a href="http://wiki.nginx.org/HttpHealthcheckModule" target="_blank">http://wiki.nginx.org/HttpHealthcheckModule</a>
1、下載下傳安裝,
在https://github.com/liseen/healthcheck_nginx_upstreams下載下傳該子產品,沒有公布的版本,下載下傳時要輕按兩下打開後,将代碼另存的方式下載下傳,
2、進入nginx的源碼目錄 為nginx打更新檔 healthcheck.pathch #注意路徑
#patch –p1< ../cep21-healthcheck_nginx_upstreams/healthcheck.patch
編譯安裝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 clean
分别在兩個站點目錄下建立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;
}
網頁檢視運作結果:
<a href="http://blog.51cto.com/attachment/201311/203743197.png" target="_blank"></a>
注意:HttpHealthcheckModule與nginx_upstream_check_module安裝時更新檔包有一定沖突,不可同時安裝。
擷取該子產品版本包
<a href="https://github.com/yaoweibin/nginx_upstream_check_module/releases" target="_blank">https://github.com/yaoweibin/nginx_upstream_check_module/releases</a>
進入nginx的解壓目錄:
#patch -p1 < /path/to/nginx_http_upstream_check_module/check.patch
注:因nginx版本更新,1.2以上版本的nginx,更新檔為check_1.2.1+.patch
#./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;
allow 192.168.1.176;
注:無關配置項省略。
判斷文法,重載nginx服務
[root@master ~]# /usr/local/nginx/sbin/nginx -t
[root@master ~]# /usr/local/nginx/sbin/nginx -s reload
<a href="http://blog.51cto.com/attachment/201311/203708535.png" target="_blank"></a>
雖然上面兩個子產品都可以實作對後端的檢測,但總是有一種雞肋的感覺,對于有多個應用前端的生産環境而言,每個前端都需要安裝該子產品插件,當然也是單獨的頁面顯示,會給使用者傳回大量的資訊【包括很多正常的資訊,其實檢測後端的目的就是了解到錯誤連接配接,并實作告警】,并不理想,而且不能實作告警。繼續學習尋找中[手動寫腳本]……
本文轉自 劉園 51CTO部落格,原文連結:http://blog.51cto.com/colynn/1328863