1. 程式人生 > >NGINX 負載均衡監測節點狀態 之 十一

NGINX 負載均衡監測節點狀態 之 十一

圖片 ref erer oct ica figure 1.3 work app

1、監測負載均衡節點作用

用於提供主動式後端服務器健康檢查,通過它可以檢測後端realserver的健康狀態,如果後端realserver不可用,則所有的請求就不會轉發到該節點上。

2、依賴模塊nginx_upstream_check_module

編譯安裝方法:
./configure xxxxxxxxxxxxxxx --add-module=/app/software/nginx_upstream_check_module-master/
備註:可直接使用淘寶團隊開發的NGINX程序包
http://tengine.taobao.org/download_cn.html

3、nginx主要配置文件

worker_processes  1;
events {
    worker_connections  1024;
}
error_log  logs/error.log;
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  logs/access.log  main;

    upstream server_pools {
        server 10.3.151.34:81;
        server 10.3.151.246:81;
        check interval=3000 rise=2 fall=5 timeout=1000;
                #對server_pools這個負載均衡條目中的所有節點,每隔3秒檢測一次,請求2次正常則標記為realserver狀態為UP,如果檢查5次都失敗,則標記realserver的狀態為down,超時時間為1秒,檢查的協議是HTTP。
        }

server {
        listen       80;
        server_name  www.kang.com;
        location / {
            proxy_pass http://server_pools;
        }
        location /status {              #定義狀態路徑
            check_status ;
            access_log off;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       81;
        server_name  www.kang.com;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    #include vhost/*.conf;
}

4、展示效果

正常狀態:
技術分享圖片

異常狀態:
技術分享圖片

NGINX 負載均衡監測節點狀態 之 十一