nginx 平衡策略

2019-05-22  本文已影响0人  阿布多12

nginx 负载均衡有 (轮询策略<round-robin>,加权轮询)、最少链接数<Least-connected >、ip-hash

轮询策略

http {
    upstream myapp1 {
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

加权轮

upstream myapp1 {
        server srv1.example.com weight=3;
        server srv2.example.com;
        server srv3.example.com;
    }

最少链接数

upstream myapp1 {
        least_conn;
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

ip-hash

upstream myapp1 {
    ip_hash;
    server srv1.example.com;
    server srv2.example.com;
    server srv3.example.com;
}

但当有一个服务因为失败次数达到设置的阀值,会被nginx标记为错误的服务器,因而避免对他的访问
https://nginx.org/en/docs/http/load_balancing.html

上一篇 下一篇

猜你喜欢

热点阅读