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

學無先后,達者為師

網站首頁 編程語言 正文

nginx-1.20*安裝check模塊

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

主動地健康檢查,nignx定時主動地去ping后端的服務列表,當發現某服務出現異常時,把該服務從健康列表中移除,當發現某服務恢復時,又能夠將該服務加回健康列表中。

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

1、若健康檢查包類型為http,在開啟健康檢查功能后,nginx會根據設置的間隔向指定的后端服務器端口發送健康檢查包,并根據期望的HTTP回復狀態碼來判斷服務是否健康。
2、后端真實節點不可用,則請求不會轉發到故障節點
3、故障節點恢復后,請求正常轉發

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

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

加載nginx_upstream_check_module模塊

進去下載nginx解壓目錄下運行如下打包命令,如果沒有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的配置一般是單獨

include conf.d/*.conf;

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

項目部署目錄/opt/apache-tomcat-8.5.81/webapps/ROOT/WEB-INF/

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

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次正常的話,標記此realserver的狀態為up,fall表示請求5次都失敗的情況下,標記此realserver的狀態為down,timeout為超時時間,單位為毫秒。

server段里面可以加入查看realserver狀態的頁面

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是后端服務器的數量
generation是Nginx reload的次數
Index是服務器的索引
Upstream是在配置中upstream的名稱
Name是服務器IP
Status是服務器的狀態
Rise是服務器連續檢查成功的次數
Fall是連續檢查失敗的次數
Check type是檢查的方式
Check port是后端專門為健康檢查設置的端口

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

欄目分類
最近更新