# ZK Tomcat 7 Cluster/Session Replication

asked 2013-02-12 20:44:45 +0800

HaraldS
21 2

This seems to be an age old question but I just can't get the desired behavior with my two tomcat instances (fronted by httpd as a load balancer). The issue is that whenever a node goes down I am told that the session has expired (redirect to timeout.zul), I'm not sure what I'm doing wrong and have read tons of articles about tomcat clustering/session replication and how to setup ZK.

I also added:

<system-config>
<ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-class>
</system-config>


to my zul.xml deployed in WEB-INF.

If anyone has experienced the same issue as well please let me know what you tried or how you solved it - also if you have suggestions I'm very happy to hear.

Thanks!

In order to keep this less cluttered I'm phrasing the question first, the following part a contains various configuration snippets:

My environment: Red Hat Enterprise 6.3, Apache HTTPD 2.2, Tomcat 7.0.35 (x2) I'm using modproxy and modproxy_balancer in httpd, here my configuration:

ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
ProxyPass / balancer://cluster/ stickysession=JSESSIONID|jsessionid nofailover=Off scolonpathdelim=On

<Proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8009 route=jvm1
BalancerMember ajp://127.0.0.1:8010 route=jvm2
</Proxy>


I then configured the cluster on tomcat 7 according to the standard rules (the cluster and session replication): NOTE: The worker name is different for both instances, this is just the config for one of them, the other one is equivalent. I can see the servers join and leave the cluster.

<host name="localhost" appbase="webapps" unpackwars="true" autodeploy="true">

    <!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html  (simple how to)
/docs/config/cluster.html (reference documentation) -->
<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="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="127.0.0.1"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<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=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/srv/armada-tc1/webapps"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>

<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>

delete retag edit

## 2 Answers

Sort by » oldest newest most voted

answered 2013-02-13 11:18:58 +0800

gekkio
899 1
http://gekkio.fi/blog

Since you seem to be running both Tomcats on the same machine, make sure you are using different Receiver ports for both nodes.

answered 2013-02-21 15:15:33 +0800

HaraldS
21 2

Thank you very much for your answer, I wanted to reply earlier but there is a time frame a new member has to wait before responding.

I ensured that what you suggested was in fact correct - the autoBind attribute defines a port range that can be bound to. So instance 1 was bound to port 4000 while instance 2 was bound to port 4001.

I figured out what the problem was - very odd and in conflict with some of the tutorials I've seen.

It appears as though the version of the XSD that's being used for web.xml (auto generated by the ZK Maven archetype) is causing the issue. The version that's referenced is 2.4, what is needed is a reference to the 3.0 XSD. Example (sorry links are shortened, insufficient karma :( ):

<web-app xmlns="...javaee"
xmlns:xsi="...XMLSchema-instance"
xsi:schemaLocation="...javaee
...web-app_3_0.xsd"
version="3.0"
metadata-complete="true">


Now of course the

<distributable/>


Tag is also required as a child of web-app.

Upon starting up you'll then notice in the catalina.out log that the DeltaManager communicates that it's waiting for session information <- and that is the key! After that everything works as expected.

There are tutorials out there that use the 2.5 XSD, which also doesn't work, and maybe this is a bug in Tomcat 7.0.35? Not quite sure - I'll have to check and log a bug over at the Apache JIRA if that's the case.

Thanks again and I hope my answer provides some help to others that have been stumbling :)

## Comments

"Thanks again and I hope my answer provides some help to others that have been stumbling :)" QFT you just saved my liver! i was struggling exactly at the same point... without a DeltaManager lines on the logs! Thanks you both! Giovanni

( 2013-05-16 08:17:30 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

## Stats

Asked: 2013-02-12 20:44:45 +0800

Seen: 66 times

Last updated: Feb 21 '13

Support Options
• Email Support
• Training
• Consulting
• Outsourcing
Learn More