後端服務配置,一臺116服務器用於nginx轉發請求,使用輪詢的負載均衡策略;兩臺後端API接口服務器57 和117,用於處理請求。
現象背景:當對指定接口進行壓力測試的時候,會出現絕大部分的請求都轉發到57服務器,而117服務器上只有少量的請求。
問題定位: 查看nginx的error日誌發現,出現大量報錯:2020/06/16 14:23:00 [error] 4950#4950: *4162133210 no live upstreams while connecting to upstream, client: xxx.xxx.xxx.xxx, server:
出現no live upstreams while connecting to upstream表示nginx檢測不到任何存活的後端服務。同時使用netstat命令查看117後端服務器,存在大量的TIME_WAIT連接
.解決問題:在nginx.conf文件中增加了keep-Alive配置,如:
upstream xxxxxxx {
server 172.17.192.57:8087 max_fails=3 fail_timeout=5s weight=1;
server 172.17.192.117:8087 max_fails=3 fail_timeout=5s weight=1;
keepalive 256;
}