Tengine 主動式後端伺服器健康檢查功能 ngx_http_upstream_check_module
阿新 • • 發佈:2022-11-30
本文使用的版本:Tengine-2.3.3
在 Tengine 2.3.3 中 ngx_http_upstream_check_module 預設是不包含的,所以編譯配置的時候需要手動新增上去
./configure --add-module=modules/ngx_http_upstream_check_module
make
make 過後就可以在 objs 目錄下找到 nginx 檔案
check
upstream cluster1 { # simple round-robin server 192.168.0.1:80; server 192.168.0.2:80; check interval=3000 rise=2 fall=5 timeout=1000 type=http; check_http_send "HEAD / HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; } upstream cluster2 { # simple round-robin server 192.168.0.3:80; server 192.168.0.4:80; check interval=3000 rise=2 fall=5 timeout=1000 type=http; check_keepalive_requests 100; check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; }
該模組生效範圍是 upstream 中,上面的配置檔案就是 每3s檢查一次,5次失敗->down 2次成功->up down後不再轉發請求
check_status
server {
listen 80;
location /1 {
proxy_pass http://cluster1;
}
location /status {
check_status;
}
}
通過 check_status 命令顯示伺服器的健康狀態頁面,支援的格式有: html、csv、 json。預設型別是html。
/status?format=html
/status?format=csv
/status?format=json