nginx+tomcat+redis完成session共享
2015-08-28 10:39
591 查看
本文记录nginx+redis+tomcat实现session共享的过程
nginx安装:/article/9080974.html
redis安装:/article/9080972.html
准备两个tomcat,修改相应的端口
修改nginx.conf加上:
启动nginx。
下载tomcat-redis-session-manager相应的jar包,主要有三个:
wget https://github.com/downloads/jcoleman/tomcat-redis-session-manager/tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
wget http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5.2.jar
wget http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar
下载完成后拷贝到$TOMCAT_HOME/lib中
修改两tomcat的context.xml:
在tomcat/webapps/test放一个index.jsp
启动tomcat,发现有异常:com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve 类找不到
分别打开三个jar包,确实没有这个类,解决可以参考:
/article/10459362.html
通过访问http://10.10.49.20/test/
刷新:
可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
nginx安装:/article/9080974.html
redis安装:/article/9080972.html
准备两个tomcat,修改相应的端口
名称 | IP | 端口 | tomcat版本 | JDK |
tomcat1 | 10.10.49.23 | 8080 | 7.0.40 | 1.7.0_25 |
tomcat2 | 10.10.49.15 | 8081 | 7.0.40 | 1.7.0_25 |
upstream backend { server 10.10.49.23:8080 max_fails=1 fail_timeout=10s; server 10.10.49.15:8081 max_fails=1 fail_timeout=10s; }修改nginx.conf的location成
location / { root html; index index.html index.htm; proxy_pass http://backend; }
启动nginx。
下载tomcat-redis-session-manager相应的jar包,主要有三个:
wget https://github.com/downloads/jcoleman/tomcat-redis-session-manager/tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
wget http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5.2.jar
wget http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar
下载完成后拷贝到$TOMCAT_HOME/lib中
修改两tomcat的context.xml:
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="10.10.49.20" port="6379" database="0" maxInactiveInterval="60" /> </Context>
在tomcat/webapps/test放一个index.jsp
<%@ page language="java" %> <html> <head><title>TomcatA</title></head> <body> <table align="centre" border="1"> <tr> <td>Session ID</td> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html> sessionID:<%=session.getId()%> <br> SessionIP:<%=request.getServerName()%> <br> SessionPort:<%=request.getServerPort()%> <% //为了区分,第二个可以是222 out.println("This is Tomcat Server 1111"); %>
启动tomcat,发现有异常:com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve 类找不到
分别打开三个jar包,确实没有这个类,解决可以参考:
/article/10459362.html
通过访问http://10.10.49.20/test/
刷新:
可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
相关文章推荐
- Redis管道(Pipelining)操作
- Jedis使用总结【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
- redis同时删除多个表
- Redis主从配置详细过程
- redis-有序集合
- maven构建项目实现对redis的操作(jedis)
- redis的数据类型 (一) 字符串
- redis常见命令
- zabbix针对redis监控
- php 与redis 结合 使用predis
- phpredis扩展安装
- yum 安装 redis php-redis
- java+redis;spring-data-redis+redis
- 利用redis实现tomcat session共享
- Windows 64位下安装Redis详细教程
- mysql redis 同步
- Redis简介与安装
- Java中使用Jedis操作Redis
- redis集群部署
- CentOS 7 下安装 Redis 2.8.7