1. 程式人生 > >apache+tomcat叢集遇到的問題

apache+tomcat叢集遇到的問題

問題1. 前提: web.xml下要加<distributable/> 或 在tomcat的context.xml的context標籤屬性加入distributable="true"(未嘗試) 遇見問題: 在登陸時發現如下異常:
Caused by: java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute memberAdmin
解決方法:找到對應key-value下的value的類進行序列化。

問題2. 在server.xml配置叢集指令時,加入如下:
<!-- 叢集配置 --> <!--<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Membership className="org.apache.catalina.tribes.membership.McastService" bind="127.0.0.1" address="228.0.0.4" port="45564" frequency="500" dropTime="3000"/> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4002" selectorTimeout="100" maxThreads="6"/> <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" timeout="60000"/> </Sender> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> </Cluster>-->
解決方法:

<!-- 經測試如下叢集配置本機生效, 如上註釋的配置叢集能生效但是ip定向且session不能共享,掛了一個伺服器後,session會清除需要重新登入 --> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/> </Cluster>
註釋的叢集配置可能是tomcat版本號的影響,沒有深入研究過,我目前使用的tomcat版本為apache-tomcat-7.0.69