日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

nginx-1.20*安裝check模塊

作者:三朝看客 更新時間: 2022-07-13 編程語言

主動地健康檢查,nignx定時主動地去ping后端的服務(wù)列表,當(dāng)發(fā)現(xiàn)某服務(wù)出現(xiàn)異常時,把該服務(wù)從健康列表中移除,當(dāng)發(fā)現(xiàn)某服務(wù)恢復(fù)時,又能夠?qū)⒃摲?wù)加回健康列表中。

使用第三訪模塊nginx_checkcheck模塊下載

1、若健康檢查包類型為http,在開啟健康檢查功能后,nginx會根據(jù)設(shè)置的間隔向指定的后端服務(wù)器端口發(fā)送健康檢查包,并根據(jù)期望的HTTP回復(fù)狀態(tài)碼來判斷服務(wù)是否健康。
2、后端真實(shí)節(jié)點(diǎn)不可用,則請求不會轉(zhuǎn)發(fā)到故障節(jié)點(diǎn)
3、故障節(jié)點(diǎn)恢復(fù)后,請求正常轉(zhuǎn)發(fā)

其他依賴,可以參考本地yum源

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

加載nginx_upstream_check_module模塊

進(jìn)去下載nginx解壓目錄下運(yùn)行如下打包命令,如果沒有patch就yum install patch -y

注:不管是1.20.············都加載check_1.20.1+.patch,只看主版本號
在這里插入圖片描述
編譯安裝nginx,注意各自模塊的存放位置

./configure --user=root --group=root --with-http_ssl_module --with-threads --with-file-aio --with-http_stub_status_module --add-module=/opt/check_nginx/nginx_upstream_check_module-master

在這里插入圖片描述

make && make install

在這里插入圖片描述

nginx配置

我nginx的配置一般是單獨(dú)

include conf.d/*.conf;

vim /usr/local/nginx/conf/nginx.conf新增/usr/local/nginx/conf/conf.d
在這里插入圖片描述
1、配置upstream.conf

項(xiàng)目部署目錄/opt/apache-tomcat-8.5.81/webapps/ROOT/WEB-INF/

探針文件放在/opt/apache-tomcat-8.5.81/webapps/ROOT/monitor/index.html
在這里插入圖片描述
當(dāng)檢測不到index.html存在會自動切換到另外一臺服務(wù)器。
在這里插入圖片描述

upstream tomcat
{
        ip_hash;
        server 127.0.0.1:8080;
        server 127.0.0.1:8081;
        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "GET /monitor/index.html HTTP/1.0";
        check_http_expect_alive http_2xx http_3xx;
}

interval檢測間隔時間,單位為毫秒,rsie請求2次正常的話,標(biāo)記此realserver的狀態(tài)為up,fall表示請求5次都失敗的情況下,標(biāo)記此realserver的狀態(tài)為down,timeout為超時時間,單位為毫秒。

server段里面可以加入查看realserver狀態(tài)的頁面

location / {       
	proxy_pass http://tomcat;       
	proxy_set_header Host $http_host;       
	proxy_set_header X-Real-IP $remote_addr;       
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
}

location  /status {     
	check_status;     
	access_log off;     
	charset utf-8; 
	}

啟動nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

在這里插入圖片描述

server number是后端服務(wù)器的數(shù)量
generation是Nginx reload的次數(shù)
Index是服務(wù)器的索引
Upstream是在配置中upstream的名稱
Name是服務(wù)器IP
Status是服務(wù)器的狀態(tài)
Rise是服務(wù)器連續(xù)檢查成功的次數(shù)
Fall是連續(xù)檢查失敗的次數(shù)
Check type是檢查的方式
Check port是后端專門為健康檢查設(shè)置的端口

原文鏈接:https://blog.csdn.net/xaiodang/article/details/125750660

欄目分類
最近更新