REDIS3.2+TOMCAT implementation of cluster session management--Tomcat-redis-session-manager compilation and development deployment environment construction

Source: Internet
Author: User
Tags redis version redis cluster






There are many articles about using Tomcat-redis-session-manager to realize the session of Redis storage Tomcat, and realize distributed session management. But now the officially compiled Tomcat-redis-session-manager jar package is already very old, and the Redis version is very low based. Here I introduce myself to the steps to recompile and deploy it.






1, first, download the source code of Tomcat-redis-session-manager project from GitHub on clone, the address is:



Https://github.com/jcoleman/tomcat-redis-session-manager.git



Make sure you are using the Master branch.






2, the downloaded project is not a way to directly import into eclipse compiled (although not necessary, but I tend to create an eclipse project for it.) This next step), but by Gradle to compile, so we need to download gradle, the address is:



https://gradle.org/gradle-download/



Download "Binary only distribution" is OK. I unzipped in the C:\gradle-2.13 directory, Gradle directly can be used. You can also put the path C:\gradle-2.13\bin in the PATH environment variable, it will be convenient. But I didn't do it.






3. Open the/tomcat-redis-session-manager/build.gradle. Modify the version of the dependent package to use the latest version as much as possible.


 
compileJava {
  sourceCompatibility = 1.7
  targetCompatibility = 1.7
}

dependencies {
  compile group: ‘org.apache.tomcat‘, name: ‘tomcat-catalina‘, version: ‘7.0.69‘
  compile group: ‘redis.clients‘, name: ‘jedis‘, version: ‘2.8.1‘
  compile group: ‘org.apache.commons‘, name: ‘commons-pool2‘, version: ‘2.4.2‘
  //compile group: ‘commons-codec‘, name: ‘commons-codec‘, version: ‘1.10‘

  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.69‘
}


Above is a fragment of Build.gradle, as shown in the highlighted place,



1) Change the Java version to your corresponding Java version



2) Change Tomcat-catalina dependent version to the Tomcat version you installed, I am 7.0.69



3) To change the Jedis version to the latest, the current is 2.8.1



4) Change the Commons-pool2 version to the latest 2.4.2



5) You can also change the references under Testcompile to the latest, but this should not matter.



Because Gradle also downloads the jar package from the MAVEN repository, it is best to check the http://mvnrepository.com/to see if the group,name,version referenced above can be found in the repository. Otherwise, the gradle will not download the jar package to error.






4, (optional) import as Eclipse project. Or to open the Build.gradle file. Add apply plugin to the first line: ' Eclipse '


 
‘
apply plugin: ‘java‘
apply plugin: ‘maven‘





Then execute the command.


CD [root]/tomcat-redis-session-managerc:\gradle-2.13\bin\gradle Eclipse


This way Gradle will create. Project,. classpath files, and you can import the project into eclipse.






5, you can compile with eclipse. or compile with Gradle.


C:\gradle-2.13\bin\gradle Build


Compilation succeeded:






But I compile the time actually encountered some problems, if you also have the same problem, see me below the trouble shooting.






6, troubleshooting



In step 4th, step 5th, if you use Gradle, you encounter the following error:


No such property:sonatypeusername for class: Org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer





In Build.gradle, comment out the highlighted line below.


Repository (URL: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { //authentication ( Username:sonatypeusername 
,
password:sonatypepassword) }


Reference: HTTPS://GITHUB.COM/WEALDTECH/HAWK/ISSUES/16






If you encounter the following error:


 
* What went wrong:
Execution failed for task ‘:signArchives‘.
> Cannot perform signing task ‘:signArchives‘ because it has no configured signatory





In Build.gradle, comment out the following 3 lines:


Signing {//sign  configurations.archives//}


Reference: Https://groups.google.com/forum/#!topic/gaelyk/WfdEDBOzIOM






7, in the Tomcat-redis-session-manager\build\libs directory, you can find the successful compilation jar file:



Tomcat-redis-session-manager-2.0.0.jar






In the C:\users\[user]\.gradle directory, you can find another 2 dependent jar files (or download from maven)



Commons-pool2-2.4.2.jar



Jedis-2.8.1.jar






Copy these 3 files to the \apache-tomcat-7.0.69\lib directory






8, open \apache-tomcat-7.0.69\conf\context.xml, add in <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" />


The host and port are the Redis addresses. (as to how Redis cluster is configured, update later)



If you are debugging with Tomcat in Eclipse, under your Dynamic Web project, in Project Explorer, find the Context.xml file to add the above configuration servers.









The above has been configured, now a simple test.



1, add a simple JSP page to the project.


 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
SessionID:<%=session.getId()%>
</body>
</html>





2, after starting to see









3, use the Redis python client redis-py to see if the corresponding key is created


>>> Import Redis
>>> r=redis.StrictRedis(host=‘127.0.0.1‘,port=6379)
>>> r.get(‘289B7B17C0609FE930617ED659272C60‘)











Reference



http://blog.csdn.net/chszs/article/details/42610365



Http://www.cnblogs.com/weixiaole/p/4431679.html



REDIS3.2+TOMCAT implementation of cluster session management--Tomcat-redis-session-manager compilation and development deployment environment construction


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.