用nginx转发请求,分发至子节点,以达到多台服务共同承压的目的,首先要准备一台负载均衡服务器,这台服务器只做转发没有其他业务,转发规则有轮询、ip哈希等
轮询
按访问时间,一个接一个分发,如某一个挂掉则跳过
# 子节点定义
upstream server_list{
server 43.139.180.197:96;
server 43.139.180.197:97;
server 43.139.180.197:9501;
}
server
{
listen 99;
server_name 43.139.180.197;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/fzjh;
location / {
# 设置转发
proxy_pass http://server_list;
}
}
ip_hash
按照ip地址hash结果分配请求,同一个ip地址固定分发到同一子节点,如果这个子节点挂掉,会分发给其他子节点
# 子节点定义
upstream server_list{
ip_hash;
server 43.139.180.197:96;
server 43.139.180.197:97;
server 43.139.180.197:9501;
}
server
{
listen 99;
server_name 43.139.180.197;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/fzjh;
location / {
# 设置转发
proxy_pass http://server_list;
}
}
权重分配
按照一定权重比分配请求
# 子节点定义
upstream server_list{
server 43.139.180.197:96 weight=1;
server 43.139.180.197:97 weight=2;
server 43.139.180.197:9501 weight=3;
}
server
{
listen 99;
server_name 43.139.180.197;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/fzjh;
location / {
# 设置转发
proxy_pass http://server_list;
}
}
最少链接
优先分配给处理请求最少得一个节点
# 子节点定义
upstream server_list{
least_conn;
server 43.139.180.197:96;
server 43.139.180.197:97;
server 43.139.180.197:9501;
}
server
{
listen 99;
server_name 43.139.180.197;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/fzjh;
location / {
# 设置转发
proxy_pass http://server_list;
}
}
标签:index,负载,180.197,default,htm,43.139,server,nginx,均衡
From: https://www.cnblogs.com/gltt/p/17909134.html