Pivotal Knowledge Base

Follow

How to setup Redis Session Manager on tcServer/Tomcat

Environment

Product Version
Apache Tomcat  
Redis  

Purpose

Users can easily setup tcServer/Tomcat cluster to use a high-performance Redis Session Manager with a non-sticky store, instead of the bundled Tomcat session replication using delta or backup manager.

There is jcoleman Redis Session Manger for Apache Tomcat open-source project that developed a tomcat-redis-session-manager implementation to allow Tomcat to store the non-sticky sessions in Redis for requests distribution across the cluster instances. This is a third party library implementation, which is not bundled with tcServer for out-of-the-box support. Read the overview on Tomcat Redis Session Manager: https://github.com/jcoleman/tomcat-redis-session-manager

Presently, tomcat-redis-session-manager project only supports Tomcat 6 with Java 6 and Tomcat 7 with Java 7. Unfortunately, Tomcat 8 is not currently supported.

Procedure

For this demo setup, we are using a local Redis server version 3 and tcSever-Tomcat-7. If you are looking for instructions on how to install Redis, see How to install and use Redis on Linux KB article.

1) Download and install the following required jar files into TCS_Instance/lib folder

tomcat-redis-session-manager-2.0.0.jar - Tomcat session manager implementation library that stores sessions in Redis.
jedis-2.5.2.jar - Jedis is a blazinglysmall and sane redis java client library.
commons-pool2-2.2.jar - Apache commons object pooling library.

> cd TCS_Instance/lib
> wget -c https://github.com/rmohr/tomcat-redis-session-manager/releases/down...
> wget -c http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5...
> wget -c http://central.maven.org/maven2/org/apache/commons/commons-pool2/2....

2) Add following lines to TCS_Instance/conf/context.xml

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
         host="localhost"   <!-- The redis server name or ip -->
         port="6379"  <!-- The redis server port -->
  password="mypass" <!-- Add this if redis server require a password auth access -->
         database="0"
         maxInactiveInterval="30" <!-- Time  in seconds --> />

3)  Restart the tcServer and check Redis server to ensure that the Tomcat request sessions are getting stored.

Monitor the Redis server.

> redis-cli -p 6379 -a mypass monitor
OK


Access the tcServer examples application,  create a session name and value.

> http://localhost:8081/examples/servlets/servlet/SessionExample

And watch user session data getting set on Redis

 > redis-cli -p 6379 -a mypass monitor
OK
1431038650.026827 [0 127.0.0.1:36434] "AUTH" "mypass"
1431038650.027075 [0 127.0.0.1:36434] "info"
1431038893.190903 [0 127.0.0.1:37018] "AUTH" "kymeng"
1431038893.192301 [0 127.0.0.1:37018] "GET" "1B8AB24BC2B339EABB5AA4C9BAFC9384"
1431038893.192850 [0 127.0.0.1:37018] "GET" "1B8AB24BC2B339EABB5AA4C9BAFC9384"
1431038905.685080 [0 127.0.0.1:37018] "PING"
1431038935.681059 [0 127.0.0.1:37018] "PING"
...
1431039295.682350 [0 127.0.0.1:37670] "PING"
1431039316.602917 [0 127.0.0.1:37670] "GET" "09DE015D6704185FF1D9B9B4FACF60D8"
1431039316.607184 [0 127.0.0.1:37670] "SET" "09DE015D6704185FF1D9B9B4FACF60D8" "\xac\xed\x00\x05sr\x00Dcom.orangefunction.tomcat.redissessions.SessionSerializationMetadataB\xd9\xd9\xf7v\xa2\xdbL\x03\x00\x01[\x00\x15sessionAttributesHasht\x00\x02[Bxpw\x14\x00\x00\x00\x10\xe6#l\xd9h>\xc4\xd3\xd1\xe9t+H\xbb\xd3(xsr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01M0\x95\xaf;sq\x00~\x00\x03\x00\x00\x01M0\x95\xaf;sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexq\x00~\x00\x04\x00\x1bw@sr\x00\x11java.lang.Boolean\xcd r\x80\xd5\x9c\xfa\xee\x02\x00\x01Z\x00\x05valuexp\x00sq\x00~\x00\t\x01sq\x00~\x00\x03\x00\x00\x01M0\x97\x12{t\x00 09DE015D6704185FF1D9B9B4FACF60D8sq\x00~\x00\a\x00\x00\x00\x01t\x00\x06servert\x00\x05redisw\b\x00\x00\x01M0\x95\xaf;"
1431039316.607814 [0 127.0.0.1:37670] "EXPIRE" "09DE015D6704185FF1D9B9B4FACF60D8" "1800"
1431039325.682566 [0 127.0.0.1:37670] "PING"
...

Retrieve the user sessionid 09DE015D6704185FF1D9B9B4FACF60D8 value information

> redis-cli -a mypass get 09DE015D6704185FF1D9B9B4FACF60D8
"\xac\xed\x00\x05sr\x00Dcom.orangefunction.tomcat.redissessions.SessionSerializationMetadataB\xd9\xd9\xf7v\xa2\xdbL\x03\x00\x01[\x00\x15sessionAttributesHasht\x00\x02[Bxpw\x14\x00\x00\x00\x10\xe6#l\xd9h>\xc4\xd3\xd1\xe9t+H\xbb\xd3(xsr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01M0\x95\xaf;sq\x00~\x00\x03\x00\x00\x01M0\x95\xaf;sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexq\x00~\x00\x04\x00\x1bw@sr\x00\x11java.lang.Boolean\xcd r\x80\xd5\x9c\xfa\xee\x02\x00\x01Z\x00\x05valuexp\x00sq\x00~\x00\t\x01sq\x00~\x00\x03\x00\x00\x01M0\x97\x12{t\x00 09DE015D6704185FF1D9B9B4FACF60D8sq\x00~\x00\a\x00\x00\x00\x01t\x00\x06servert\x00\x05redisw\b\x00\x00\x01M0\x95\xaf;"

Are there any high-performance session manager for tcServer/Tomcat?

There are GemFire session management modules that bundle with tcServer and third party memcached-session-manager implementation project that currently support tcServer/Tomcat 6,7,8.

Additional Information

GemFire HTTP Session Management modules  https://pubs.vmware.com/vfabric5/topic/com.vmware.vfabric.gemfire.6...

Comments

  • Avatar
    Ky Lim

    Pivotal tcServer 3.0+ onwards are shipped with Pivotal Session Managers that can be deployed to Tomcat 7/8 with Java 7/8 using the "-t redis-session-manager" and optional "-t redis-session-manager-auth" template options.

    redis-session-manager - Enables you to configure tc Runtime instances to use a Redis server for session management and replication. Does not require a user to specify a password to connect to Redis.

    redis-session-manager-auth - Enables you to configure tc Runtime instances to use a Redis server for session management and replication. Requires a user to specify a password to connect to Redis.

    It appears that the Pivotal Session Managers can be use with older tcServer-Tomcat7 versions and ASF Tomcat 7/8 that are using Java 7/8, but are need to be tested to ensure they're working as expected and not officially supported by Pivotal.

    References:
    https://github.com/pivotalsoftware/session-managers
    http://tcserver.docs.pivotal.io/docs-tcserver/topics/postinstall-getting-started.html

Powered by Zendesk