Nginx+tomcat集群redis共享session应用方案
部署环境
主机 | 软件版本 |
192.168.88.1 | nginx-1.12.2+redis-3.2.11 |
192.168.88.2 | apache-tomcat-7.0.79 + jdk1.8 |
192.168.88.3 | apache-tomcat-7.0.79 + jdk1.8 |
所需tomcat jar包,下载
- commons-pool-1.5.4.jar
- commons-pool2-2.4.1.jar
- jedis-2.6.2.jar
- tomcat-juli-adapters.jar
- tomcat-juli.jar
- tomcat-redis-session-manager1.2.jar
Tomcat配置
- 把tomcat jar包复制到$TOMCAT_BASE 下的lib目录
- 修改tomcat的配置文件conf/comtext.xml
#单点redis配置(我已经配置成功)
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="192.168.88.1"
port="6379"
database="0"
maxInactiveInterval="60"/>
</Context> #基于redis集群配置(我还没测试)
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
maxInactiveInterval="60"
sentinelMaster="mymaster"
sentinels="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381"/>
</Context>
3、添加一个tomcat测试页index.jsp
# cat /opt/tomcat/webapps/ROOT/index.jsp
<html>
<head>
<title>nginx tomcat session test</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <h1>tomcat88.2</h1> #这里192.168.88.3机器改为tomcat88.3
session: <%=session.getId()%>
</html>
4、启动tomcat
nginx配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream tomcat {
server 192.168.88.2:8080 weight=1;
server 192.168.88.3:8080 weight=1;
} server {
listen 80;
server_name localhost;
location / {
proxy_pass http://tomcat;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
redis安装请看教程
各个组件下载
- Redis: http://redis.io
- JRedis: https://github.com/xetorthio/jedis
- https://github.com/jcoleman/tomcat-redis-session-manager/do
- http://commons.apache.org/proper/commons-pool/download_pool.cgi
Nginx+tomcat集群redis共享session应用方案的更多相关文章
- nginx+tomcat集群+redis(memcache)session共享!
常用保持session的方式: 1.一些代理(比如nginxIP_hash) 1.使用数据库来存储Session 2.使用Cookie来存储Session ...
- Nginx+tomcat集群中,session的共享
nginx,tomcat集群后多个session分配到同一个应用 单节点低负荷的情况下,我们通常把一个WEB应用打成WAR包放WEB应用服务器,如TOMCAT下运行就行了(如图1).但随着用户量的增加 ...
- 【nginx+tomcat集群】Nginx1.12.2+Tomcat7集群+负载均衡+Session共享
今天想着将项目优化一下,就想的实现集群分布,在本机测试:利用nginx+tomcat实现 通过上一篇博客(http://www.cnblogs.com/qlqwjy/p/8535235.html),N ...
- 160513、nginx+tomcat集群+session共享(linux)
第一步:linux中多个tomcat安装和jdk安装(略) 第二步:nginx安装,linux中安装nginx和windows上有点不同也容易出错,需要编译,这里做介绍 一.安装依赖 gcc open ...
- Nginx+Tomcat集群+session共享
Nginx+Tomcat集群+session共享 1)安装Nginx 2)配置多个Tomcat,在server.xml中修改端口(端口不出现冲突即可) 3)在nginx.conf文件中配置负载均衡池, ...
- Nginx+Tomcat集群配置
Nginx+Tomcat集群配置 一台虚拟机作为Nginx服务 两太虚拟机配置Tomcat+jdk环境 Nginx测试 启动: cd usr/local/nginx/sbin ./nginx ---& ...
- nginx+tomcat集群配置(4)--rewrite规则和多应用根目录设定思路
前言: nginx中有一块很重要的概念, 就是rewrite规则. 它会对URL进行修改, 然后进行内部的重定向. rewrite授予了nginx更多的自由, 使得后级服务的接入更加地方便. 本文将简 ...
- nginx+tomcat集群配置(1)---根目录设定和多后端分发配置
前言: 对于javaer而言, nginx+tomcat集群配置, 已然成了web应用部署的主流. 大公司如此, 小公司亦然. 对于个人开发者而言, 资源有限, 往往多个web应用混部于一台服务器(云 ...
- nginx+ tomcat集群+动静资源分离
不知道为什么这个随便删不掉,写了也值显示一半一半不显示, 我把重新写了一遍: nginx + tomcat集群和动静资源分离
随机推荐
- 【莫比乌斯反演】51nod1594 Gcd and Phi
题解 显然可以O(nlogn)计算 代码 //by 减维 #include<set> #include<map> #include<queue> #include& ...
- BZOJ 题解continue
1041 圆上的整点 暴力枚举 会超时 这道题很像之前一次noip模拟题(当时的我还太水了(虽然现在也很水)) x2+y2=R2 考虑变型 x2=(R+y)(R-y) int d=gcd(R,y) i ...
- 【NOIP 模拟赛】区间第K大(kth) 乱搞
biubiu~~~ 这道题就是预处理,我们就是枚举每一个数,找到左边比他大的数的个数以及其对应的区间,右边也如此,我们把左边的和右边的相乘就得到了我们的答案,我们发现这是O(n^3)的,但是实际证明他 ...
- 线程--promise furture 同步
http://www.cnblogs.com/haippy/p/3279565.html std::promise 类介绍 promise 对象可以保存某一类型 T 的值,该值可被 future 对象 ...
- bzoj 2304 [Apio2011]寻路 Dij+模拟+恶心建图
[Apio2011]寻路 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 624 Solved: 193[Submit][Status][Discus ...
- idea 将工程项目打包成war
1.File--Project structure ---- Artifacts ----- + -----web Application :Archive ---for ' **:war explo ...
- 【2016-09-27-DP小练】
得分250..我真是个250... 犯了一些很搞笑的错.. f[i][j][k]表示第i个苹果,现在在j这个位置,还能用k次转移. 用i去更新i+1. 时间复杂度1000*2*30: 转移方程有个地方 ...
- 【20160815】noip模拟(未完)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- bzoj4839 [Neerc2016]Abbreviation
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4839 [题解] pkusc怎么出bzoj原题啊 字符串随便处理一下就行了,大模拟 pkusc ...
- [bzoj1251]序列终结者——splay
题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技 ...