之前有一篇文章記錄nginx負載均衡后端檢查,鏈接為 https://www.cnblogs.com/minseo/p/9511456.html
但是只包含http健康檢查不包含tcp下面安裝nginx可以實現http及tcp健康檢查
參考 https://github.com/zhouchangxun/ngx_healthcheck_module/
安裝
git clone https://github.com/nginx/nginx.git git clone https://github.com/zhouchangxun/ngx_healthcheck_module.git cd nginx/; git checkout branches/stable-1.12 git apply ../ngx_healthcheck_module/nginx_healthcheck_for_nginx_1.12+.patch ./auto/configure --with-stream --add-module=../ngx_healthcheck_module/ make && make install
git下載nginx及健康檢查模板安裝nginx
配置http的upstream配置樣式如下
upstream www.xxx.net{ server 172.16.90.232:81; check interval=3000 rise=2 fall=5 timeout=5000 type=http; check_http_send "GET / HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; }
配置tcp的upstream的配置樣式如下
upstream device5000{ server 172.16.90.52:5000; server 172.16.90.53:5000; check interval=3000 rise=2 fall=5 timeout=5000 default_down=true type=tcp; }
在主配置文件新加一個location
location /upstream_status{ healthcheck_status html; }
web頁面訪問
http://ip/upstream_status
頁面顯示如下