Nginx-负载均衡

25次阅读

共计 619 个字符,预计需要花费 2 分钟才能阅读完成。

轮询
配置语法:
Syntax: upstream name {…}
Default: –
Context http
Syntax: server address [parameters];
Default: –
Context: upstream
{
upstream imooc {
server 192.168.8.1:8081;
server 192.168.8.1:8082;
server 192.168.8.1:8083;
}
// 轮询使用 3 个 server。

server {
listen 80;
server_name localhost;
location / {
proxy_pass http://xxx;
include proxy_params;
}

}
}

upstream 参数
说明

down
当前的 erver 暂时不参与负载均衡

backup
预留的备份服务器

max_fails
允许请求失败的次数

fail_timeout
经过 max_fails 失败后,服务暂停时间

max_conns
限制最大的接收的连接数。

调度算法

方法
说明

轮询
按时间顺序注意分配到不同的后端服务器

加权轮询
weight 值越大,分配到的访问几率越高。

ip_hash
每个请求按访问 IP 的 hash 结果分配,这样来自同一个 IP 的固定访问一个后端服务器。

url_hash
每个请求按访问 URL 的 hash 结果分配,这样来自同一个 IP 的固定访问一个后端服务器。

least_conn
最少连接数,那个机器连接数少就分发

hash 关键数值
hash 自定义的 key

正文完
 0