【學習Nginx-06】Tengine實現健康檢查

Tengine實現健康檢查

編輯配置文件

user  root;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
	
	# =============BEGIN 健康檢查 =============
	# 配置負載均衡要使用 upstream
	upstream myServers-hc{
		server 192.168.1.20:9090
		server 192.168.1.20:9091
		
		# 加入健康檢查
		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;
	}
		
	server {
		listen 86;
		server_name localhost;
		
		location / {
			proxy_pass myServers-hc;
		}
		
		location /status {
            check_status;

        }

    }
	
	# =============END 健康檢查 =============

}

這段代碼就是在負載均衡的基礎上加入健康檢查的代碼

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;

重新加載配置

sbin/nginx -s reload

訪問測試

輸入http://192.168.1.20:86/status,進入監控檢查頁面

image-20200424225356444

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章