tomcat使用redis共享session并实现单点登录

来源:互联网 发布:linux做windows系统盘 编辑:程序博客网 时间:2024/04/30 11:47

下载依赖
tomcat-redis-manager https://github.com/jcoleman/tomcat-redis-session-manager/downloads
commons-pool http://commons.apache.org/proper/commons-pool/download_pool.cgi
jedis http://mvnrepository.com/artifact/redis.clients/jedis

将这几个jar包放入所有tomcat的lib中

下载并安装redis
windows https://github.com/MSOpenTech/redis/releases
linux http://download.redis.io/releases/
具体安装和配置方法见百度
修改每个tomcat的context.xml文件

<Context  sessionCookiePath="/"><!-- sessionCookiePath设置session cookie的域为根域名 -->    <WatchedResource>WEB-INF/web.xml</WatchedResource>    <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />      <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"               host="localhost"               port="6379"               database="0"               maxInactiveInterval="60"             password="这里写redis的密码(如果有)"/>   </Context>

配置完毕,启动tomcat
注意:要放入session中的类要实现序列化接口,序列号相同

0 0