先安裝nginx再加健康模塊么

大家都知道,前段nginx做反向代理,如果后端服務(wù)器宕掉的話,nginx是不能把這臺realserver提出upstream的,所以還會有請求轉(zhuǎn)發(fā)到后端的這臺realserver上面去,雖然nginx可以在localtion中啟用proxy_next_upstream來解決返回給用戶的錯誤頁面。

先安裝nginx再加健康模塊么

但這個還是會把請求轉(zhuǎn)發(fā)給這臺服務(wù)器的,然后再轉(zhuǎn)發(fā)給別的服務(wù)器,這樣就浪費(fèi)了一次轉(zhuǎn)發(fā),這次借助與淘寶技術(shù)團(tuán)隊開發(fā)的nginx模塊,nginx_upstream_check_module來檢測后方realserver的健康狀態(tài),如果后端服務(wù)器不可用,則所有的請求不轉(zhuǎn)發(fā)到這臺服務(wù)器。

安裝配置

文件列表信息

[root@iZ233438q9fZ upload]# ll drwxr-xr-x 6 ftpuser ftp       4096 Aug 19 10:04 nginx_upstream_check_module drwxr-xr-x 8    1001 1001      4096 Jun 16  2015 nginx-1.9.2.tar.gz

解壓

[root@iZ233438q9fZ upload]# tar -zxvf nginx-1.9.2.tar.gz [root@iZ233438q9fZ upload]# cd nginx-1.9.2

nginx補(bǔ)丁安裝

[root@iZ233438q9fZ nginx-1.9.2]# patch -p0 < /var/ftp/upload/nginx_upstream_check_module/check_1.9.2+.patch patching file src/http/modules/ngx_http_upstream_hash_module.c 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

編譯配置

[root@iZ233438q9fZ nginx-1.9.2]# ./configure --add-module=/var/ftp/upload/nginx_upstream_check_module --prefix=/usr/local/server/nginx  [root@iZ233438q9fZ nginx-1.9.2]# make && make install

nginx.conf健康檢查配置樣例

先安裝nginx再加健康模塊么

參數(shù)說明:

– check_status:[html|csv|json],默認(rèn)html

– check_http_send:指定檢測的http訪問地址,默認(rèn)/

– type:[tcp|http|ssl_hello|mysql|ajp],默認(rèn)tcp

– interval:向后端發(fā)送的健康檢查包的間隔,單位(毫秒)

– fall(fall_count): 如果連續(xù)失敗次數(shù)達(dá)到fall_count,服務(wù)器就被認(rèn)為是down。

– rise(rise_count): 如果連續(xù)成功次數(shù)達(dá)到rise_count,服務(wù)器就被認(rèn)為是up。

– timeout: 后端健康請求的超時時間。

PS:如果一直顯示失敗,請檢查項目根目錄中是否有index.jsp或index.html

更多Nginx相關(guān)技術(shù)文章,請訪問Nginx使用教程欄目進(jìn)行學(xué)習(xí)!?

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊14 分享