负载均衡 ip_hash、url_hash 与 least_conn

 

负载均衡 url_hash 与 least_conn

●    url_hash

●    least_conn

●    url_hash

    ◆    每次请求的url地址,hash后访问到固定的服务器节点

    ◆    配置

upstream tomcats { 

    # url hash 

    hash $request_uri; 

    # 最少连接数 

    # least_conn 

    server 192.168.1.173:8080; 

    server 192.168.1.174:8080; 

    server 192.168.1.175:8080; 

server { 

    listen 80; 

    server_name www.tomcats.com; 

    location / { 

        proxy_pass http://tomcats; 

    } 

}

●    least_conn

负载均衡 ip_hash

ip_hash 可以保证用户访问可以请求到上游服务中的固定的服务器,前提是用户ip没有发生更改。
使用ip_hash的注意点:
不能把后台服务器直接移除,只能标记down.

If one of the servers needs to be temporarily removed, it should be marked with the down parameter in order to preserve the current hashing of client IP addresses.

upstream tomcats {
       ip_hash;

       server 192.168.1.173:8080;
       server 192.168.1.174:8080 down;
       server 192.168.1.175:8080;
}

附:Keepalive提高吞吐量

●    Kepepalive    含义

●    其他配置参数

●    Kepepalive    含义

    ◆    设置长连接的数量

●    其他配置参数

    ◆    proxy_http_version    设置长连接http版本 1.1  (1.0不是http)

    ◆    proxy_set_header    清除connection header信息

upstream tomcats { 

    # server 192.168.1.173:8080 max_fails=2 fail_timeout=1s; 

    server 192.168.1.190:8080; # server 192.168.1.174:8080 weight=1; 

    # server 192.168.1.175:8080 weight=1; keepalive 32; 

server { 

    listen 80; 

    server_name www.tomcats.com; 

    location / { 

        proxy_pass http://tomcats; 

        proxy_http_version 1.1; 

        proxy_set_header Connection ""; 

    } 

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值