我有两个Websocket服务器,与Zookeeper & Curator一起工作,如果一台服务器出现故障,那么第二个后端活起来。
我按照以下方式configuration它:
upstream backend { server 172.31.9.1:8080 max_fails=1 fail_timeout=5s; server 172.31.9.0:8080 max_fails=1 fail_timeout=5s; } server { listen 443; # host name to respond to server_name xxxxxx.compute.amazonaws.com; ssl on; ssl_certificate /etc/ssl/certs/wildcard.dev.xxxx.net.crt; ssl_certificate_key /etc/ssl/certs/wildcard.dev.xxxx.net.key; location / { # switch off logging access_log off; proxy_pass http://backend; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # WebSocket support (nginx 1.4) proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
我期望的是当主动和被动服务器交换位置时,Nginx会花费5秒来识别故障并将所有的stream量redirect到活动服务器。
实际发生的事情是,识别活动服务器并切换所有stream量需要长达25秒的时间。
在真实的情况下,我可以处理redirect之间10秒的停机时间。
我错过了什么?
来自NGINX文档的fail_timeout:
集:
所以5的设置将意味着总共10秒(5次超时,5次再次联系之前)
顺便说一下, max_fails的默认值已经是1,所以你不需要设置它。
如果你真的想要一个主动/被动设置,你应该使用这个configuration:
upstream backend { server 172.31.9.1:8080; server 172.31.9.0:8080 backup; }