在Tomcat+Nginx集群部署运行的过程发现个问题,假如集群配置两个Tomcat_A和Tomcat_B并且Tomcat_B作为backup模式运行, 假如Tomcat_B重启更新完版本,做完AB测试验证后。
此时关闭重新启动Tomcat_A,在关闭Tomcat的瞬间正在访问的用户请求会自然切换到Tomcat_B上面,但是继续启动如果是新用户访问请求,还是优先访问Tomcat_A,但是此时Tomcat_A还没有完全启动,用户的请求就一直挂起一直等到Tomcat_A启动完毕。
期望是:在Tomcat_A还没有启动完毕之前,不要请求Tomcat_A,而是持续访问集群的Tomcat_B
解决方案:
通过查阅Tomcat的官方文档,找到如下参数:
bindOnInit |
Controls when the socket used by the connector is bound. By default it is bound when the connector is initiated and unbound when the connector is destroyed. If set to |
据此修改tomcat的server.xml:
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" bindOnInit="false"/>
启动验证通过,在启动完毕之前用户请求直接返回找不到页面,而不再一直傻傻等待Tomcat启动到完毕。
以上配置以HTTP Connector为参考,如果是以AJP Connector作为请求分发,对应修改ajp connetor参数即可。