Tengine主动监测后端服务器状态

in note-timknip •  4 years ago  (edited)

Tengine附带了nginx_upstream_check_module模块,用于主动监测后端服务器状态进行宕机切换。
先编译nginx时带上参数
1

--add-module=modules/ngx_http_upstream_check_module

官方文档的编译参数有误,最新版编译的时候会出错:
1

./configure --with-http_upstream_check_module

后端配置代码如下,具体参数参考官方文档.

upstream backend {
        server   192.168.99.2:8888;
        server   192.168.99.3:8888;
        server   192.168.99.4:8888;
        check interval=10000 rise=2 fall=3 timeout=1000 default_down=true type=http;
        check_http_send "GET / HTTP/1.0\r\n HOST test.com\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx http_4xx;
}

也可以在原生的nginx配置中增加proxy_connect_timeout配置:

server {
listen 80;
server_name urbantest.com
location / {
proxy_pass http://test_upstream; // 笔记本上此处设置为http://127.0.0.1:3300
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 1;
}

}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!