ZK Tomcat 7 Cluster/Session Replication

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

HaraldS gravatar image HaraldS
21 2

updated 2013-02-12 20:46:09 +0800

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:


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.


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:// route=jvm1
  BalancerMember ajp:// route=jvm2

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"

        <Manager className="org.apache.catalina.ha.session.DeltaManager"

            <Channel className="org.apache.catalina.tribes.group.GroupChannel">
                <Membership className="org.apache.catalina.tribes.membership.McastService"
                <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"

                <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                    <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

            <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
            <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

            <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"

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

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

2 Answers

Sort by ยป oldest newest most voted

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

gekkio gravatar image gekkio flag of Finland
899 1

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

link publish delete flag offensive edit

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

HaraldS gravatar image HaraldS
21 2

updated 2013-02-21 15:17:55 +0800

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"

Now of course the


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 :)

link publish delete flag offensive edit


"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

gganassin ( 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]

Question tools




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