How to achieve high availability with nginx load balancing
天蓬老师
天蓬老师 2017-06-10 09:49:33
0
2
758

Use nginx to implement simple load balancing, the configuration is as follows


...

http{
    ...
    
    upstream mytomcatscluster{
        #ip_hash 在同一台服务器部署了2个tomcat,使用不同的端口
        server 127.0.0.1:8080 weight=2;
        server 127.0.0.1:8180 weight=1;
    }
    
    ...
    
    server{
        ...
        
        # 将所有后端请求分发到我定义的集群服务器上
        location /service/fen/{
            proxy_pass http://mytomcatscluster;
        }
        
        ...
    }
}

...

The current problem is: If both tomcats are normal, nginx can distribute requests to the specified server normally. Using polling, the weight can also work, but if I give one of the tomcats If it is turned off, the request will be stuck, because there will be requests distributed by nginx to the failed server. How to deal with this situation? Does ngxin have a corresponding solution strategy? Is there a way for nginx to monitor the running status of cluster servers? How to configure?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
仅有的幸福

upstream has two parameters max_fails and fail_timeout. If a certain server has max_fails connection failures within the fail_timeout time, then Nginx will think that it has hung up and will not request it during the fail_timeout time.
fail_timeout defaults to 10s, max_fails defaults to 1.

In addition, there is a third-party module nginx_upstream_check_module specially used to detect the health of the backend server
.
yaoweibin/nginx_upstream_check_module: Health checks upstreams for nginx

https://github.com/yaoweibin/...

过去多啦不再A梦

No need to use ip_hash to store the session in redis

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template