nginx+tomcat+redis完成session共享(转载)
2017-02-16 16:16
393 查看
转载:http://blog.csdn.net/grhlove123/article/details/48047735
tomcat7下基于redis的session共享所需jar包:
http://download.csdn.net/detail/xiaoxiaosasasa/9403043
本文记录nginx+Redis+tomcat实现session共享的过程
nginx安装:http://blog.csdn.net/grhlove123/article/details/47834673
redis安装:http://blog.csdn.net/grhlove123/article/details/47783471
准备两个tomcat,修改相应的端口
修改nginx.conf加上:
[html] view plain copy
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成
[html] view plain copy
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- href="http://lib.csdn.net/base/javase" target=_blank>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:
[html] view plain copy
<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
[html] view plain copy
<%@ 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包,确实没有这个类,解决可以参考:
http://blog.csdn.net/qinxcb/article/details/42041023
通过访问http://10.10.49.20/test/
刷新:
可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
tomcat7下基于redis的session共享所需jar包:
http://download.csdn.net/detail/xiaoxiaosasasa/9403043
本文记录nginx+Redis+tomcat实现session共享的过程
nginx安装:http://blog.csdn.net/grhlove123/article/details/47834673
redis安装:http://blog.csdn.net/grhlove123/article/details/47783471
准备两个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 |
[html] view plain copy
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成
[html] view plain copy
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- href="http://lib.csdn.net/base/javase" target=_blank>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:
[html] view plain copy
<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
[html] view plain copy
<%@ 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包,确实没有这个类,解决可以参考:
http://blog.csdn.net/qinxcb/article/details/42041023
通过访问http://10.10.49.20/test/
刷新:
可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
相关文章推荐
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis/Memcached集群完成session共享
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis/memcached完成session共享
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis完成session共享
- CentOS7 Nginx+Redis+Tomcat集群实现session保持和共享
- 搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- 【原创】搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
- tomcat+nginx+redis实现均衡负载、session共享(一)
- 分布式高并发服务器做请求分发,session共享(nginx+tomcat+redis)
- Nginx+Tomcat+Redis实现应用服务器集群负载均衡和Session共享
- Redis学习笔记(六)Nginx+Tomcat+Redis实现负载均衡、资源分离、session共享
- Linux+Nginx+Tomcat+Redis实现负载均衡,应用集群及session共享
- tomcat+nginx+redis实现均衡负载、session共享(一)
- 负载均衡之Nginx+tomcat+redis实现session共享的负载均衡
- linux-tomcat+nginx+redis:分布式session共享(redis配置说明)