tomcat redis session共享
编译redis所需要的序列化包
安装 gradle
Linux & MacOS users
Configure your PATH environment variable to include the bin directory of the unzipped distribution, e.g.:
$ export PATH=$PATH:/opt/gradle/gradle-5.3/bin
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-5.3-bin.zip
$ ls /opt/gradle/gradle-5.3
拉源码包
git clone https://github.com/jcoleman/tomcat-redis-session-manager.git
编译
[root@oldboy tomcat-redis-session-manager]# cat build.gradle
tomcat 版本 7.0.78
jdk版本 1.8
[root@oldboy ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
[root@oldboy tomcat-redis-session-manager]# cat build.gradle
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing' group = 'com.orangefunction'
version = '2.0.0' repositories {
mavenCentral()
} compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
} dependencies {
compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '7.0.78'
compile group: 'redis.clients', name: 'jedis', version: '2.5.2'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.6.0'
//compile group: 'commons-codec', name: 'commons-codec', version: '1.9' testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile group: 'org.apache.tomcat', name: 'tomcat-coyote', version: '7.0.78'
} task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
} task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
} artifacts {
archives jar archives javadocJar
archives sourcesJar
} //signing {
// sign configurations.archives
//}
task copyJars(type: Copy) {
from configurations.runtime
into 'dist'
} uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } //repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
//authentication(userName: sonatypeUsername, password: sonatypePassword)
//}
//repository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
//authentication(userName: sonatypeUsername, password: sonatypePassword)
//} pom.project {
name 'tomcat-redis-session-manager'
packaging 'jar'
description 'Tomcat Redis Session Manager is a Tomcat extension to store sessions in Redis'
url 'https://github.com/jcoleman/tomcat-redis-session-manager' issueManagement {
url 'https://github.com:jcoleman/tomcat-redis-session-manager/issues'
system 'GitHub Issues'
} scm {
url 'https://github.com:jcoleman/tomcat-redis-session-manager'
connection 'scm:git:git://github.com/jcoleman/tomcat-redis-session-manager.git'
developerConnection 'scm:git:git@github.com:jcoleman/tomcat-redis-session-manager.git'
} licenses {
license {
name 'MIT'
url 'http://opensource.org/licenses/MIT'
distribution 'repo'
}
} developers {
developer {
id 'jcoleman'
name 'James Coleman'
email 'jtc331@gmail.com'
url 'https://github.com/jcoleman'
}
}
}
}
}
}
[root@oldboy tomcat-redis-session-manager]# gradle build -x test copyJars
在tomcat-redis-session-manager/build/libs/目录下生成以下几个包
在tomcat-redis-session-manager/dist/下生成以下几个包
复制3个文件到tomcat/lib目录下
[root@oldboy dist]# cp jedis-2.5.2.jar tomcat-redis-session-manager-2.0.0.jar commons-pool2-2.6.0.jar /usr/local/tomcat/lib/
编写tomcat context.xml文件添加redis信息
[root@oldboy ~]# vim /usr/local/tomcat/conf/context.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<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.0.0.51"
port="6379"
password='123'
database="0"
maxInactiveInterval="60" />
</Context>
测试结果.随便刷新 seisson不变
存到redis的session数据
- jdk安装
rpm -ivh jdk-8u151-linux-x64.rpm
如图:
2、tomcat下载、解压
tomcat 下载地址:http://tomcat.apache.org/
tar xf apache-tomcat-7.0.78.tar.gz -C /usr/local/
ln -s apache-tomcat-7.0.78 tomcat
3、配置path环境变量
vi /etc/profile.d/tomcat.sh
export CATALINA_BASE=/usr/local/tomcat
export PATH=$CATALINA_BASE/bin:$PATH
chmod +x /etc/profile.d/tomcat.sh # 赋予可执行权限
source /etc/profile.d/tomcat.sh
4、创建测试网页的发布目录
mkdir /usr/local/tomcat/webapps/test/
[root@oldboy dist]# cat /usr/local/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<body>
<h1><font color="red">TomcatA.linuxinfo.top</font></h1>
<tablealign="centre" border="1">
<tr>
<td>SessionID</td>
<% session.setAttribute("linuxinfo.top","linuxinfo.top");%>
<td><%=session.getId() %></td>
</tr>
<tr>
<td>Createdon</td>
<td><%=session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
6、分别启动tomcat
catalina.sh start #可也用全路径/usr/local/tomcat/bin/startup.sh
7、访问192.168.2.197,测试如下,查看session ID
1下载五个jar包,将jar包放在/usr/local/tomcat/lib:
mgetjavolution-5.4.3.1.jar
memcached-session-manager-1.8.0jar
memcached-session-manager-tc7-1.8.0.jar
msm-javolution-serializer-1.8.0.jar
spymemcached-1.8.0.jar
- 在contest.xml段定义一个用于测试的context容器,并在其中创建一个会话管理器。
添加如下信息
vim /usr/local/tomcat/conf/context.xml" - <?xml version='1.0' encoding='utf-8'?>
- <!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <!-- The contents of this file will be loaded for each web application -->
- <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" />
- -->
- <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
- memcachedNodes="m1:192.168.2.37:11211,m2:192.168.2.27:11211"
- failoverNodes="m2"
- requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
- transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"/>
- </Context>
- 重启服务:
catalina.sh stop
catalina.sh start
3、下载memcached,启动服务
yum install memcached -y
systemctl start memcached
tomcat redis session共享的更多相关文章
- nginx tomcat负载均衡 使用redis session共享
环境准备 1.准备一台nginx服务器 ip192.168.1.133 端口81 安装过程: #首先安装依赖: yum -y install gcc-c++ yum -y install pcre p ...
- 配置tomcat的session共享
可通过下面方法限制一个用户访问一个服务器之后就只在该服务器上操作. 请求负载过程中会话信息不能丢失.那么在多个tomcat中session需要共享. 配置tomcat的session共享可以有三种解决 ...
- 高级运维(五):构建memcached服务、LNMP+memcached、使用Tomcat设置Session、Tomcat实现session共享
一.构建memcached服务 目标: 本案例要求先快速搭建好一台memcached服务器,并对memcached进行简单的添.删.改.查操作: 1> 安装memcached软件,并启动服务d ...
- Tomcat 集群 + Redis Session 共享出现 Session 瞬间失效问题
写在前面的话 写这篇博客出于公司最近要迁移到新的云上面且对之前的资源,架构做一个升级. 本来是一个不大的项目,旧环境旧一个 TOMCAT 跑起来,不过出于高可用考虑,新环境决定使用 TOMCAT 集群 ...
- Nginx反向代理,负载均衡,redis session共享,keepalived高可用
相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此 ...
- (转)tomcat架构&session共享
(二期)16.tomcat的整体架构与session共享方案 [课程16]tomcat...共享.xmind47.6KB [课程16]tomcat...流程.xmind0.6MB [课程16]tomc ...
- Tomcat中session共享问题的简单解决办法
tomcat-redis-session-manager 使用redis配置tomcat共享session 结构图: 分析: 分布式web server集群部署后需要实现session共享,针对 to ...
- Memcached做Tomcat的session共享
基于cache DB缓存的session共享 基于memcache/redis缓存的session共享.即使用cacheDB存取session信息,应用服务器接受新请求将session信息保存在cac ...
- Apache代理Tomcat实现session共享构建网上商城系统
一.环境介绍 二.安装配置后端服务器 三.安装配置前端服务器 四.配置Tomcat服务器实现session共享 五.构建网上商城系统 一.环境介绍 系统版本:CentOS 6.4_x86_64 Mys ...
随机推荐
- EasyNVR摄像机网页无插件直播方案H5前端构建之:bootstrap弹窗功能的实现方案与代码
前言介绍 在web前端的网页设计中,为了展示出简洁的网页风格和美观的效果,往往会使用弹窗效果在EasyNVR前端页面录像检索功能时,必然会播放录像,如果单独为播放录像文件排一个界面,用户在使用上会更加 ...
- python1-变量和简单的数据类型
变量和简单的数据类型 1 Hello World程序 1.1 执行py文件 linux下编辑一个文件,hello.py print("Hello world") 执行 # pyth ...
- python入门和杂识
1需要理解的一些概念 1.C语言编译完就是机器码,机器码可以直接在处理器上执行. 2.CPU可以直接读取机器码. 3.Python是用C写的. 4.Python解释器会把代码内容读到内存里,通过Pyt ...
- B+树比B树更适合实际应用中操作系统的文件索引和数据库索引
B+树比B树更适合实际应用中操作系统的文件索引和数据库索引 为什么选择B+树作为数据库索引结构? 背景 首先,来谈谈B树.为什么要使用B树?我们需要明白以下两个事实: [事实1]不同容量的存储器, ...
- docker安装ES,Kibana
docker安装ES 1.docker pull elasticsearch:6.8.2 2.docker run -it --name elasticsearch -d -p 9200:9200 ...
- 第三节:一些指令总结(Nuget、)
一. NuGet 1. 获取当前项目已经安装的类库:Get-Package 2. 安装指定版本:install-package <程序包名> -version <版本号> 3. ...
- AtCoder-abc147 (题解)
A - Blackjack (水题) 题目链接 大致思路: 水题 B - Palindrome-philia (水题) 题目链接 大致思路: 由于整个串是回文串,只要判断前一半和后一半有多少个不同即可 ...
- PHP 去一定范围随机小数 随机浮点数
例如取2到3中的 随机小数(一位)或整数 mt_rand(20,30)/10 mt_rand()是随机取整函数 先扩大一定倍数,再缩小相应倍数,倍数代表精确到哪一位
- Django-05-视图函数
http请求中产生两个核心对象: http请求:HttpRequest对象 http响应:HttpResponse对象 所在位置:django.http 之前我们用到的参数request就是HttpR ...
- AGC037
Contest page A Tag:贪心 猜想段的长度只会有$1$和$2$(感性理解,应该可以反证--),然后就可以DP/贪心了 B Tag:贪心.组合 考虑如何构造合法方案.从右往左考虑球,因为当 ...