一、下载安装 Redis
-
安装过程非常简单,请自行下载安装,官网地址:https://redis.io/download/
-
下面windows下运行的方式
-
redis-server.exe redis.windows.conf
-
二、下载安装 Tomcat
- 请自行下载相应版测试,官网地址:https://tomcat.apache.org/download-80.cgi
- 我测试的版的是 7.0.88
三、下载 Tomcat 基于 Reids 的 Session 共享插件
- 开源地址:https://github.com/jcoleman/tomcat-redis-session-manager
- 自行git到本地编译,然将编译后的文件 “commons-pool2-2.2.jar、jedis-2.5.2.jar、tomcat-redis-session-manager-master-2.0.0.jar” 复到tomcat的lib目录下,如下图。
四、修改配置文件
- 修改tomcat的conf/context.xml配置文件
<Context>
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="127.0.0.1"
port="6379"
password="123456"
database="0"
maxInactiveInterval="60" />
</Context>
-
参数说明
- host为redis服务器的地址
- port为redis服务的端口号
完成后启动tomcat即可测试
五、注意事项
- 各服务器之间的时间要同步,如果时间差太大可能导致session失效。
- 我已经整理了一个可以直接使用的软件包,点击这里下载。