Apache / Tomcat设置:
Apache
|
/ \
/ \
C1 C2 Clusters
| |
/ \ / \
/ \ / \
T1 T2 T3 T4 Tomcats
我在C1和C2上有负载均衡。 T1和T2是一组,T3和T4是另一组。 C1和C2是独立的。
workers.properties :
worker.list=jkstatus,Cluster1,Cluster2,C1T1,C1T2,C2T1,C2T2
worker.jkstatus.type=status
# Configuration Cluster 1
worker.Cluster1.type=lb
worker.Cluster1.balance_workers=C1T1,C1T2
worker.C1T1.port=8119
worker.C1T1.host=localhost
worker.C1T1.type=ajp13
worker.C1T1.lbfactor=1
worker.C1T1.redirect=C1T2
worker.C1T2.port=8129
worker.C1T2.host=localhost
worker.C1T2.type=ajp13
worker.C1T2.lbfactor=1
worker.C1T2.redirect=C1T1
# Configuration Cluster 2
worker.Cluster2.type=lb
worker.Cluster2.balance_workers=C2T1,C2T2
worker.C2T1.port=8219
worker.C2T1.host=localhost
worker.C2T1.type=ajp13
worker.C2T1.lbfactor=1
worker.C2T1.redirect=C2T2
worker.C2T2.port=8229
worker.C2T2.host=localhost
worker.C2T2.type=ajp13
worker.C2T2.lbfactor=1
worker.C2T2.redirect=C2T1
Apache将每个请求重定向到 Cluster1 或 Cluster2 :
JkMount /MyApp/* Cluster1
server.xml中:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="C1T1">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45562" frequency="500" dropTime="3000"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4001" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
T1 / T2具有相同的地址/端口,T3 / T4具有相同的地址/端口(与T1 / T2不同)。
我遵循了这一点:http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html而且:http://tomcat.apache.org/connectors-doc/reference/workers.html
加载balacing工作正常。如果我在群集上关闭一个Tomcat,Apache会将所有请求重定向到另一个Tomcat。会话也被复制(我使用JConsole跟踪两个Tomcat上的活动会话数)。
现在,这是我的问题:
每次点击F5,都会创建一个新会话(我在Tomcat上使用@SessionBean
)。如果我通过使用HTTP端口直接访问Tomcat来绕过群集,则会创建一个新会话,但是当我按F5时不会创建新会话。
我想知道为什么在使用Apache访问时,会在每个请求上创建一个新会话(以及如何修复它!)。
答案 0 :(得分:0)
终于明白了。
群集不会导致此问题。它是JSF的JSESSIONID cookie:它的路径是/MyApp/
而不是/
(apache forward /
到/MyApp/
)。
编辑:必须在tomcats的sessionCookiePath="/"
文件(<Context ...></Context>
)上设置conf/context.xml
,如下所示:
<Context sessionCookiePath="/">
...
</Context>