您的位置:首页 > 运维架构 > Tomcat

集群环境配置Tomcat的bindOnInit参数控制在完全启动后才接受Request请求

2014-05-16 10:20 1076 查看
在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
false
, the socket will be bound when the connector is started and unbound when it is stopped.
据此修改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参数即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐