LoginSignup
7
6

More than 5 years have passed since last update.

TomcatのSessionをRedisに外部永続化する方法

Last updated at Posted at 2017-03-07

Sessionの外部永続化(Not Sticky Session)のためにどうしたら良いか? というのがこのポストです。

環境

  • Java 1.6.0_45
  • Apache Tomcat 6.0.48
  • Redis 3.2.7
$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

$ sh version.sh
Using CATALINA_BASE:   /opt/apache-tomcat-6.0.48
Using CATALINA_HOME:   /opt/apache-tomcat-6.0.48
Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.48/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/apache-tomcat-6.0.48/bin/bootstrap.jar
Server version: Apache Tomcat/6.0.48
Server built:   Nov 7 2016 20:05:27 UTC
Server number:  6.0.48.0
OS Name:        Linux
OS Version:     4.9.12-moby
Architecture:   amd64
JVM Version:    1.6.0_45-b06
JVM Vendor:     Sun Microsystems Inc.

$ redis-server --version
Redis server v=3.2.7 sha=00000000:0 malloc=jemalloc-4.4.0 bits=64 build=4b4d638eb6ec5175

対応

jcoleman/tomcat-redis-session-manager: Redis-backed non-sticky session store for Apache Tomcatを利用します。

Jar取得

Jar配置

${CATALINA_HOME}/bin配下に取得したJarを配置します。

Config変更

${CATALINA_HOME}/conf配下にあるcontext.xmlに以下を追記します。

    <Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
    <Manager className="com.radiadesign.catalina.session.RedisSessionManager"
         host="${redis host}"
         port="${redis port}"
    />

${redis host}: RedisのHost
${redis port}: RedisのPort

これでSessionをRedisに永続化できるようになります。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6