一:结构图
二:环境
测试环境基于 Linux CentOS 7.X,请先安装 tomcat、redis、nginx 相关环境,不作详细描述,本文测试配置如下:
Version | IP_Port | |
nginx | 1.8.0 | 192.168.1.200:80 |
tomcat_1 | 7.0.67 | 192.168.1.200:8080 |
tomcat_2 | 7.0.67 | 192.168.1.200:9090 |
redis | 3.0.6 | 192.168.1.200:6379 |
三:依赖环境
Jdk:最好7以上;
gradle:简介与说明;
git:简介与说明;
redis:安装与说明
Nginx:参考安装地址(yum安装)
四:构建 tomcat-redis-session-manager-master
首先从git上clone下来到本地
git clone git@github.com:jcoleman/tomcat-redis-session-manager.git
cd tomcat-redis-session-manager.git
先不执行build,先修改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.67'
compile group: 'redis.clients', name: 'jedis', version: '2.8.0'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.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.67'
}
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
}
task copyJars(type: Copy) {
from configurations.runtime
into 'dist'
}
//signing {
// sign configurations.archives
//}
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'
}
}
}
}
}
}
PS:注意上面打注释和task copyJars 的地方 去除第三方仓库(sonatype),用了中央仓库,然后后面的copyJars是拷贝jar包到dist目录中
然后(window下cmd进入clone的目录下)进行编译
gradle build -x test copyJars
然后生成的jar如下(session-manager的那个在build\libs下)
![](http://static.oschina.net/uploads/space/2016/0121/120815_McGG_274186.png)
五:两台tomcat 调整
1.上述jar包如果tomcat\lib下没有,则放入lib下
2.修改tomcat conf下的context.xml,在Context间加入
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="127.0.0.1"
port="6379"
database="0"
maxInactiveInterval="60" />
4.放如sessionId JSP测试页面,输出SESSIONID
5.启动tomcat
六:Nginx 配置
修改默认的default.conf-->
upstream site {
server localhost:8080;
server localhost:9090;
}
server {
listen 80;
server_name localhost;
location / {
index index_tel.jsp index.jsp index.html index.htm ;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffers 32 4k;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://site;
}
}
七:测试效果
八:大功告成(强行8)