关闭

JAVA基础应用——tomcat-redis-session-manager Redis共享Session

标签: sessionjava
2108人阅读 评论(0) 收藏 举报
分类:

Redis保存Java Session


下载gradle构建工具

网址:http://gradle.org/post-download-gradle/
设置环境变量path指向gradle安装目录

下载源码

https://github.com/jcoleman/tomcat-redis-session-manager

1、修改build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

group = 'com.orangefunction'
version = '2.0.0'

repositories {
  mavenCentral()
}

compileJava {
  sourceCompatibility = 1.7
  targetCompatibility = 1.7
}

dependencies {
  compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '7.0.27'
  compile group: 'redis.clients', name: 'jedis', version: '2.5.2'
  compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.2'
  //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.27'
}

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'
          }
        }
      }
    }
  }
}

2、执行命令构建

gradle build -x test copyJars

3、把下面jar放到tomcat lib目录

tomcat-redis-session-manager-VERSION.jar
jedis-2.5.2.jar
commons-pool2-2.2.jar

4、修改Tomcat的context.xml内容如下:

<?xml version='1.0' encoding='utf-8'?>
<!-- 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="192.10.200.225"
         port="6379" 
         database="3" 
         maxInactiveInterval="60" 
         password=""
  />
</Context>

参考:

http://doc.okbase.net/lengfo/archive/127059.html

0
0
查看评论

我的tomcat+redis实现session共享配置之路

tomcat集群通过redis实现session共享
  • lzc409973859
  • lzc409973859
  • 2016-07-21 11:25
  • 5439

使用tomcat-redis-session-manager实现session共享

测试环境: - Version ip Port nginx(可选) jdk 1.7.0_79 tomcat1 7.0.70 127.0.0.1 8082 tomcat2 7.0.70 127.0.0.1 8083...
  • javandroid
  • javandroid
  • 2016-10-28 19:27
  • 2096

Redis Session Manager for Apache Tomcat

Redis Session Manager for Apache TomcatTomcat使用Redis缓存Session,集中把Session缓存到Redis服务器中,而不是缓存到服务器的内存中,可以实现集群服务器共享Session。到目前为止,官方支持Tomcat6和Tomcat7,Tomcat...
  • linkw_92
  • linkw_92
  • 2016-08-24 11:20
  • 1699

tomcat共享session tomcat-redis-session-manager-2.0.0.jar包下载

  • 2015-07-23 16:08
  • 22KB
  • 下载

使用redis实现自己的tomcat session manager(java)

使用redis实现自己的tomcat session manager(java)最近业务扩展到了好几个tomcat,前端使用nginx,rewrite的规则设置为ip_hash,但这样如果有一个tomcat挂了,那这个用户就要重新登陆了,本来也可以忍受,但这说来说去总是一个问题,于是自己决定实现一个...
  • yao219
  • yao219
  • 2015-09-11 16:20
  • 1718

基于redis实现tomcat8及以上版本的tomcat集群的session持久化实现(tomcat-redis-session-manager二次开发)

前言: 本项目是基于jcoleman的tomcat-redis-session-manager二次开发版本 1、修改了小部分实现逻辑 2、去除对juni.jar包的依赖 3、去除无效代码和老版本tomcat操作API 4、支持tomcat 8 及以后的版本 感谢jcoleman的项目: h...
  • eguid_1
  • eguid_1
  • 2016-09-23 15:09
  • 3613

tomcat-redis-session-manager支持tomcat7

  • 2014-12-20 10:15
  • 20KB
  • 下载

基于nginx tomcat-redis-session-manager实现session共享

一、前言 nginx 作为目前最流行的开源反向代理HTTP Server,用于实现资源缓存、web server负载均衡等功能,由于其轻量级、高性能、高可靠等特点在互联网项目中有着非常普遍的应用,相关概念网上有丰富的介绍。分布式web server集群部署后需要实现session共享...
  • wang704987562
  • wang704987562
  • 2017-06-06 16:27
  • 678

分布式session分享tomcat-redis-session-manager-master

  • 2016-01-25 15:52
  • 14KB
  • 下载

利用tomcat-redis-session-manager解决tomcat的分布式session问题

[摘要:Redis+Tomcat完成session流程 1.客户端初次要求办事端 2.办事端发生session并set cookie相应给客户端 3.客户端再次要求办事端,会带上cookie 4.办事端依据cookie找到对应的session 完成思绪 若是我们] Redis+Tomcat实现se...
  • lipc_
  • lipc_
  • 2016-10-09 14:57
  • 4066
    个人资料
    • 访问:1357691次
    • 积分:18949
    • 等级:
    • 排名:第565名
    • 原创:728篇
    • 转载:20篇
    • 译文:5篇
    • 评论:193条
    博客专栏
    最新评论