入口SLB,挂在两个nginx,nginx下upstream下有多个后端节点,用户访问网站只有某几个后端节点被使用,导致此问题的原因是SLB到nginx的ip为固定IP,根据nginx的ip_hash算法,某个客户端ip也就SLB内网ip轮询给某个后端节点后,将持续保持在这个节点,所以后续所有的访问都认为是同一个ip。。。
解决方法:
nginx.conf
http下增加
map $http_x_forwarded_for $clientRealIp {
"" $remote_addr;
~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
}
upstearm.conf
upstream socket_api {
#ip_hash;
hash $clientRealIp;
server 172.17.18.145:9090 max_fails=2 fail_timeout=10s;
server 172.17.18.145:9091 max_fails=2 fail_timeout=10s;
server 172.17.18.145:9092 max_fails=2 fail_timeout=10s;
server 172.17.18.146:9093 max_fails=2 fail_timeout=10s;
server 172.17.18.146:9094 max_fails=2 fail_timeout=10s;
server 172.17.18.146:9095 max_fails=2 fail_timeout=10s;
server 172.17.18.147:9096 max_fails=2 fail_timeout=10s;
server 172.17.18.147:9097 max_fails=2 fail_timeout=10s;
server 172.17.18.147:9098 max_fails=2 fail_timeout=10s;
}