1. 在http节点下,加入upstream节点。
upstream tomcats {
server 47.107.151.74:8081;
server 47.107.151.74:8082;
}
2. 将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称,即“http://linuxidc”.
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcats;
}
轮询方式:
(1) 默认轮询
(2) weight=1; 指定轮询几率,weight和訪问比率成正比。用于后端服务器性能不均的情况
(3) ip_hash; 每一个请求按訪问ip的hash结果分配。这样每一个訪客固定訪问一个后端服务器,能够解决session的问题。
(4)fair; 按后端服务器的响应时间来分配请求。响应时间短的优先分配。
设备状态值:
(1)down 表示单前的server临时不參与负载.
(2)weight 默觉得1.weight越大,负载的权重就越大。
(3)max_fails :同意请求失败的次数默觉得1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误.
(4)fail_timeout : max_fails次失败后。暂停的时间。
(5)backup: 其他全部的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
原文:https://www.cnblogs.com/myck/p/10397379.html