nginx负载均衡策略:配置一致性hash
1)github下载nginx⼀致性hash负载均衡模块 https://github.com/replay/ngx_http_consistent_hash
2)将下载的压缩包上传到nginx服务器,并解压
3)进入nginx的安装目录,执行./configure --prefix=/usr/local/nginx --add-module=/root/ngx_http_consistent_hash-master(等号后面是解压后的ngx_http_consistent_hash-master所在目录)
4)执行 make && make install
5)在nginx.conf⽂件中修改配置:
consistent_hash $remote_addr:可以根据客户端ip映射
consistent_hash $request_uri:根据客户端请求的uri映射
consistent_hash $args:根据客户端携带的参数进⾏映
upstream balanceServer{
consistent_hash $remote_addr;
server 198.13.58.102:8001
server 207.148.115.186:8001
}