【原創】Apache集羣報Service Temporarily Unavailable的解決

Apache的集羣忽然時不時的報出如下錯誤: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: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:spa

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便可。code

相關文章
相關標籤/搜索