6

I have a setup of several Tomcat servers distributed between a few servers, all running the same thing. Apache is on top of Apache and a loadbalancer in front of the Apache servers. I want to cluster the Tomcats using Shared Session to minimize downtime and user interruption while deploying apps.

I know clustering works within the same server but is it possible to setup Tomcat in a way that it shares sessions between servers on different machines?

=> Server 1
==> Apache 1
===> Tomcat 1

=> Server 2
==> Apache 2
===> Tomcat 2

When Server/Tomcat 1 would be taken down, users and their sessions would transfer over to Server/Tomcat 2 and vice versa.

1
  • Apache is on top of Apache? – mr.zog May 5 '16 at 0:14
2

Take a look at Teracotta for web sessions.

Use Terracotta's fast, reliable web sessions plugin to get the scalability benefits of a stateless web architecture without overloading your database or rewriting your application. Terracotta for Sessions works with your favorite web framework and your own custom session objects.

The web sessions tutorial lists five simple steps for you to make in order to evaluate the product ( FOSS ).

3
  • 1
    Last time I looked.. Terracotta was damn expensive.. At least memcached is free. – Tom O'Connor Aug 1 '10 at 22:55
  • @Tom : as stated in my answer, there is a FOSS version of Teracotta. If that does not suite your needs, you might want to look into the commercial version. But it's not mandatory. – Robert Munteanu Aug 2 '10 at 20:28
  • I've looked into Terracotta before, Last time, the FOSS version didn't have the required product. – Tom O'Connor Aug 2 '10 at 22:03
2

I am working on setting up the same thing, the below link from Apache gives on overview of how to achieve this :

http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html

There are basically two parts to this :

1) Making your session objects serializable

2) Setting up the clustering config in tomcat (server.xml).

Depending on which tomcat manager you use, you may have to enable multicast on your nodes, to enable communication between the nodes. The session replication is handled by tomcat via these multicast pings.I have seen many people using this approach, and it has worked for them (Seems to be a standard/simple way of doing it).

Also here is a detailed blog post about the same - there are 5 parts, with some videos.

http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html

P.S :

I am using the same approach, for the the same problem with 2 tomcat nodes. I am facing a small issue, which is documented below, if you do succeed/run into similar issue, please have a look at this

Tomcat session replication issue

0

You can save sessions in database, so they are accesible from both tomcats. Or store them over a shared directory between tomcats.

0

You can save sessions in memcached, which is shared between both servers. This should give better performance and scalability than using shared sessions in a database, or a shared directory between n servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.