【原创】Apache集群报Service Temporarily Unavailable的解决

Apache的集群突然时不时的报出以下错误:

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

直接访问Apache的Http服务发现可以正常访问,但是访问背后的应用就报错,直接访问应用,发现有的节点已经宕掉了,但是其他节点仍然存活,为什么会这样呢?检查了一下Apache的Connector的配置:

sticky_session=1
sticky_session_force=1

发现问题出在这里,对于sticky_session:

Specifies whether requests with SESSION ID's should be routed back to the same Tomcat worker. If sticky_session is set to True or 1 sessions are sticky, otherwise sticky_session is set to False. Set sticky_session to False when Tomcat is using a Session Manager which can persist session data across multiple instances of Tomcat. 
The sticky_session setting can be overwritten using the Apache httpd environment variable JK_STICKY_IGNORE and the worker map extension for sticky_ignore. This has been added in version 1.2.33. 

不用多讲,就是粘性session,如果第一次请求由某个节点服务,那后续的请求都会交予该节点服务。

sticky_session_force:

Specifies whether requests with SESSION ID's for workers that are in error state should be rejected. If sticky_session_force is set to True or 1 and the worker that matches that SESSION ID is in error state, client will receive 500 (Server Error). If set to False or 0 failover on another worker will be issued with loosing client session. This directive is used only when you set sticky_session=True. 

这个参数的意思是,决定对于处于错误状态的session是否该拒绝服务。如果开启了粘性session,开始请求由节点1服务,后来节点1 宕掉,再次请求时,该请求的session因为节点1宕掉而丢失,这个参数就决定对于这样的请求是否应该拒绝掉。参数为1或者true代表直接拒绝,客户端浏览器就会报上述错误。如果设为0或者false,则apache会将该请求lb至其他存活的节点,但是请求的session信息会丢失。对于一个普通的无状态的网站,session有没有都无所谓,所以将该参数改为0,重启apache即可。

转载于:https://www.cnblogs.com/zhangxsh/p/3510926.html

你可能感兴趣的:(java,php,操作系统)