转载: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,修改相应的端口

名称 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

修改nginx.conf加上:

  1. upstream backend {
  2. server 10.10.49.23:8080 max_fails=1 fail_timeout=10s;
  3. server 10.10.49.15:8081 max_fails=1 fail_timeout=10s;
  4. }

修改nginx.conf的location成

  1. location / {
  2. root   html;
  3. index  index.html index.htm;
  4. proxy_pass http://backend;
  5. }

启动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:

  1. <Context>
  2. <!-- Default set of monitored resources -->
  3. <WatchedResource>WEB-INF/web.xml</WatchedResource>
  4. <!-- Uncomment this to disable session persistence across Tomcat restarts -->
  5. <!--
  6. <Manager pathname="" />
  7. -->
  8. <!-- Uncomment this to enable Comet connection tacking (provides events
  9. on session expiration as well as webapp lifecycle) -->
  10. <!--
  11. <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
  12. -->
  13. <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
  14. <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
  15. host="10.10.49.20"
  16. port="6379"
  17. database="0"
  18. maxInactiveInterval="60" />
  19. </Context>

在tomcat/webapps/test放一个index.jsp

  1. <%@ page language="java" %>
  2. <html>
  3. <head><title>TomcatA</title></head>
  4. <body>
  5. <table align="centre" border="1">
  6. <tr>
  7. <td>Session ID</td>
  8. <td><%= session.getId() %></td>
  9. </tr>
  10. <tr>
  11. <td>Created on</td>
  12. <td><%= session.getCreationTime() %></td>
  13. </tr>
  14. </table>
  15. </body>
  16. </html>
  17. sessionID:<%=session.getId()%>
  18. <br>
  19. SessionIP:<%=request.getServerName()%>
  20. <br>
  21. SessionPort:<%=request.getServerPort()%>
  22. <%
  23. //为了区分,第二个可以是222
  24. out.println("This is Tomcat Server 1111");
  25. %>

启动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共享(转载)的更多相关文章

  1. Nginx+tomcat+redis实现session共享

    Nginx+tomcat+redis实现session共享 1,安装nginx,使用yum -y install nginx 这是epel源中的,需要安装epel源. 2,配置nginx. 在ngin ...

  2. nginx+tomcat+redis完成session共享

    本文记录nginx+redis+tomcat实现session共享的过程 nginx安装:http://blog.csdn.net/grhlove123/article/details/4783467 ...

  3. nginx+tpmcat+redis实现session共享

    nginx+tpmcat+redis实现session共享 版本:nginx nginx-1.8.0.tar.gztomcat apache-tomcat-7.0.78.tar.gzredis  re ...

  4. Nginx+Tomcat集群+session共享

    Nginx+Tomcat集群+session共享 1)安装Nginx 2)配置多个Tomcat,在server.xml中修改端口(端口不出现冲突即可) 3)在nginx.conf文件中配置负载均衡池, ...

  5. Nginx+Tomcat+Memcache 实现session共享

    Nginx + Tomcat + Memcache 实现session共享 1. Nginx 部署 1.上传源码包到服务器,解压安装 下载地址:http://nginx.org/en/download ...

  6. 分布式Session共享(一):tomcat+redis实现session共享

    一.前言 本文主要测试redis实现session共享的实现方式,不讨论如何让nginx参与实现负载均衡等. 二.环境配置 本测试在Window下进行 name version port Tomcat ...

  7. 160513、nginx+tomcat集群+session共享(linux)

    第一步:linux中多个tomcat安装和jdk安装(略) 第二步:nginx安装,linux中安装nginx和windows上有点不同也容易出错,需要编译,这里做介绍 一.安装依赖 gcc open ...

  8. Nginx+IIS+Redis 处理Session共享问题 1

    最近遇到一个棘手的问题,微信公众平台的前端站点session老是丢失,我们是走的微信网页授权,授权后获取用户openid,丢失后没有openid后续的操作全白搭了,因为没了openid只能判断为客户不 ...

  9. Nginx+Tomcat+Memcached实现session共享

    实验环境: server1:nginx tomcat memcached server2:tomcat memcached Session是指一个终端用户与交互系统进行通信的时间间隔,通常指从注册进入 ...

随机推荐

  1. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

  2. UVA 2474 - Balloons in a Box 爆搜

    2474 - Balloons in a Box 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...

  3. PCI DSS合规建设ASV扫描介绍

    最近查一些Nessus.Nexpose漏洞扫描工具相关资料,工具介绍都会提到一些审计功能,其中最常见的就是PCI DSS合规性审计.从网上找到一篇介绍较详尽的文章,与大家分享. 原文摘自:http:/ ...

  4. PHP自学之路---雇员管理系统(1)

    前面已经介绍了Zend studio工具的使用以及软件开发的基本阶段,下面就是我们第一个练习,雇员管理系统,从设计到实现来简单介绍下: 开发环境: 服务器:基于Linux 2.618环境下配置PHP服 ...

  5. 安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内。

    安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内. [1404:0090][2015-06-12T08:00:53]: Error 0x800b0101: Failed ...

  6. 解决win8内置管理员无法激活此应用

    解决win8内置管理员无法激活此应用 方法/步骤   在运行中输入:“gpedit.msc”,就会启动组策略编辑器.   依次展开“计算机配置”里面的 “Windows设置” “安全设置” “本地策略 ...

  7. 比較两个 List 的值是否相等

    public static <T extends Comparable<T>> boolean compare(List<T> a, List<T> b ...

  8. UILabel的缩放动画效果

    UILabel的缩放动画效果 效果图 源码 https://github.com/YouXianMing/Animations // // ScaleLabel.h // Animations // ...

  9. 使用线程安全的 MSWeakTimer ,它不会对目标进行retain操作,避免循环引用

    MSWeakTimer 简易翻译:该timer没有runloop概念,线程安全,没有循环引用现象. https://github.com/mindsnacks/MSWeakTimer Descript ...

  10. MySql_34道经典Sql试题

    MySql_34道经典Sql试题   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/xiaouncle/article/details/799390 ...