2017-03-17 17:27:16 +00:00
# Tomcat Clustering Redis Session Manager
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
The Redis session manager is pluggable one. It stores session into Redis for easy distribution of HTTP Requests across a cluster of Tomcat servers.
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
Here the Sessions are implemented as non-sticky (means, each request can able to go to any server in the cluster, unlike the Apache provided Tomcat clustering setup.)
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
Request Sessions will be stored into Redis immediately (Session attributes must be Serializable), for the use of other servers. When tomcat receives a request from the client, Sessions are loaded directly from Redis.
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
Supports Redis default, sentinel and cluster mode, based on the configuration.
Going forward, we no need to enable sticky session (JSESSIONID) in Load Balancer.
2016-03-19 15:19:10 +00:00
## Supports:
2018-12-02 17:58:15 +00:00
- Apache Tomcat 7
- Apache Tomcat 8
- Apache Tomcat 9
2017-07-28 09:52:35 +00:00
## Downloads:
2019-06-04 17:13:28 +00:00
- [latest version (3.0.2) ](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/releases/tag/3.0.2 )
2018-12-02 17:58:15 +00:00
- [older versions ](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/wiki )
2016-03-19 15:19:10 +00:00
2019-07-03 20:58:23 +00:00
< p align = "center" >
< a href = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6M9A39423UMYS&source=https://github.com/ran-jit/tomcat-cluster-redis-session-manager" target = "_blank" > < img alt = "Donate" height = "20%" width = "20%" src = "https://github.com/ran-jit/tomcat-cluster-redis-session-manager/blob/master/src/main/resources/donate.png" > < / a >
< / p >
2017-07-28 09:17:22 +00:00
#### Pre-requisite:
2016-03-19 15:52:19 +00:00
1. jedis.jar
2. commons-pool2.jar
3. commons-logging.jar
2016-03-19 15:19:10 +00:00
2017-07-28 13:26:04 +00:00
more details.. https://github.com/ran-jit/tomcat-cluster-redis-session-manager/wiki
2016-03-19 15:51:23 +00:00
2016-03-19 15:19:10 +00:00
2017-03-17 17:24:47 +00:00
#### Steps to be done,
2019-04-27 12:20:15 +00:00
1. Copy the downloaded jars to your tomcat/lib directory.
2018-12-02 17:58:15 +00:00
- **tomcat/lib/**
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
2. Add tomcat system property "catalina.base".
2018-12-02 17:58:15 +00:00
- **catalina.base="TOMCAT_LOCATION"**
* example: export catalina.base=/opt/tomcat
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
3. Copy the redis-data-cache.properties file to your tomcat/conf directory and update your Redis server details.
2018-12-02 17:58:15 +00:00
- **tomcat/conf/redis-data-cache.properties**
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
4. Add the below two lines in your tomcat/conf/context.xml file.
2018-12-02 17:58:15 +00:00
- **< Valve className="tomcat.request.session.redis.SessionHandlerValve" /> **
- **< Manager className="tomcat.request.session.redis.SessionManager" /> **
2016-03-19 15:19:10 +00:00
2019-04-27 12:20:15 +00:00
5. Verify the session expiration time in tomcat/conf/web.xml file.
2018-12-02 17:58:15 +00:00
- **< session-config> **
- ** < session-timeout> 60</ session-timeout> **
- **</ session-config> **
2016-03-19 15:19:10 +00:00
2017-03-17 17:24:47 +00:00
### Note:
2018-12-02 17:58:15 +00:00
- **All your session attribute values must implement java.io.Serializable.**
2018-12-04 21:00:20 +00:00
### Configuration Properties:
< html >
< body >
< table border = "1px" style = "width: 80%;margin-left: 10%;margin-right: 10%;line-height: 1.5;" >
2018-12-04 21:08:01 +00:00
< tr > < th style = "width: 30%;" > Property< / th > < th style = "width: 50%;" > Description< / th > < / tr >
2018-12-04 21:10:45 +00:00
< tr > < td > redis.hosts< / td > < td > Redis server running instance IP address and port number< br / > - ex: 127.0.0.1:6379, 127.0.0.2:6379, 127.0.0.2:6380, ..< br / > - default: 127.0.0.1:6379< / td > < / tr >
2018-12-04 21:08:01 +00:00
< tr > < td > redis.password< / td > < td > Redis protected password< / td > < / tr >
2018-12-04 21:10:45 +00:00
< tr > < td > redis.database< / td > < td > Redis database selection. (Numeric value)< br / > - default: 0< / td > < / tr >
< tr > < td > redis.timeout< / td > < td > Redis connection timeout< br / > - default: 2000 ms< / td > < / tr >
< tr > < td > redis.cluster.enabled< / td > < td > To enable redis cluster mode< br / > - default: false< br > - supported values: true/false< / td > < / tr >
< tr > < td > redis.sentinel.enabled< / td > < td > To enable redis sentinel mode< br / > - default: false< br > - supported values: true/false< / td > < / tr >
< tr > < td > redis.sentinel.master< / td > < td > Redis sentinel master name< br / > - default: mymaster< / td > < / tr >
< tr > < td > lb.sticky-session.enabled< / td > < td > To enable redis and standard session mode< br > < br > If enabled,< ol > < li > Must be enabled sticky session in your load balancer configuration. Else this manager may not return the updated session values< / li > < li > Session values are stored in local jvm and redis< / li > < li > If redis is down/not responding, requests uses jvm stored session values to process user requests. Redis comes back the values will be synced< / li > < / ol > - default: false< / td > < / tr >
2018-12-04 21:00:20 +00:00
< / table >
< / body >
< / html >