nginx+tomcat+redis完成session共享(转载)
转载: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加上:
- 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包,确实没有这个类,解决可以参考:
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实现session共享
Nginx+tomcat+redis实现session共享 1,安装nginx,使用yum -y install nginx 这是epel源中的,需要安装epel源. 2,配置nginx. 在ngin ...
- nginx+tomcat+redis完成session共享
本文记录nginx+redis+tomcat实现session共享的过程 nginx安装:http://blog.csdn.net/grhlove123/article/details/4783467 ...
- nginx+tpmcat+redis实现session共享
nginx+tpmcat+redis实现session共享 版本:nginx nginx-1.8.0.tar.gztomcat apache-tomcat-7.0.78.tar.gzredis re ...
- Nginx+Tomcat集群+session共享
Nginx+Tomcat集群+session共享 1)安装Nginx 2)配置多个Tomcat,在server.xml中修改端口(端口不出现冲突即可) 3)在nginx.conf文件中配置负载均衡池, ...
- Nginx+Tomcat+Memcache 实现session共享
Nginx + Tomcat + Memcache 实现session共享 1. Nginx 部署 1.上传源码包到服务器,解压安装 下载地址:http://nginx.org/en/download ...
- 分布式Session共享(一):tomcat+redis实现session共享
一.前言 本文主要测试redis实现session共享的实现方式,不讨论如何让nginx参与实现负载均衡等. 二.环境配置 本测试在Window下进行 name version port Tomcat ...
- 160513、nginx+tomcat集群+session共享(linux)
第一步:linux中多个tomcat安装和jdk安装(略) 第二步:nginx安装,linux中安装nginx和windows上有点不同也容易出错,需要编译,这里做介绍 一.安装依赖 gcc open ...
- Nginx+IIS+Redis 处理Session共享问题 1
最近遇到一个棘手的问题,微信公众平台的前端站点session老是丢失,我们是走的微信网页授权,授权后获取用户openid,丢失后没有openid后续的操作全白搭了,因为没了openid只能判断为客户不 ...
- Nginx+Tomcat+Memcached实现session共享
实验环境: server1:nginx tomcat memcached server2:tomcat memcached Session是指一个终端用户与交互系统进行通信的时间间隔,通常指从注册进入 ...
随机推荐
- 【洛谷】4317:花神的数论题【数位DP】
P4317 花神的数论题 题目背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 题目描述 话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我 ...
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
A. Little Pony and Expected Maximum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- BZOJ 1029: [JSOI2007]建筑抢修 优先队列
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- MySQL从库com_insert无变化的原因
大家都知道com_insert等com_xxx参数可以用来监控数据库实例的访问量,也就是我们常说的QPS.并且基于MySQL的复制原理,所有主库执行的操作都会在从库重放一遍保证数据一致,那么主库的co ...
- 一个java高级工程师的进阶之路【转】
宏观方面 一. JAVA.要想成为JAVA(高级)工程师肯定要学习JAVA.一般的程序员或许只需知道一些JAVA的语法结构就可以应付了.但要成为JAVA(高级) 工程师,您要对JAVA做比较深入的研究 ...
- PostgreSQL控制台以竖行显示
\x select * from user; 这个和MySQL的有点区别,在查询之前使用\x进行显示的开启 注意:只需要用一次即可,以后的查询都是以竖行进行显示.
- 虚拟信用卡 全球付, 工商银行国际E卡, Bancore, Entropay, Payoneer
虚拟信用卡 海外网购.购买国外域名空间.ebay等一些国外网站账号的激活这些情况都需要用到国际信用卡, 如果没有信用卡或者有信用卡但是对于安全性有所顾虑怎么办? 其实有一种东西叫做虚拟信用卡,正规银行 ...
- Dictionary GetOrAdd
public static TValue GetOrAdd<TKey,TValue>( this Dictionary<TKey,TValue> dictionary, TKe ...
- UITableViewCell状态切换效果
UITableViewCell状态切换效果 效果图 源码 https://github.com/YouXianMing/Animations // // TableViewTapAnimationCo ...