环境:publicserver nginx服务器、redis服务器,test1、test2 tomcat7服务器。
1、在teat1、test2上安装tomcat7
2、将tomcat-redis-session-1.0-SNAPSHOT.jar、jedis-2.7.2.jar、commons-pool2-2.0.jar上传到/usr/local/tomcat/lib
3、修改文件/usr/local/tomcat/conf/context.xml,添加如下内容。
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.8.10" port="6379" database="0" maxInactiveInterval="60" />
4、在test1上创建测试页面/usr/local/tomcat/webapps/ROOT/test.jsp,内容如下。
<html> <body bgcolor="green"> <center> <%= request.getSession().getId() %> <h1>Test1:192.168.10.61</h1> <h1>port:8080</h1> </center> </body> </html>
5、在test2上创建测试页面/usr/local/tomcat/webapps/ROOT/test.jsp,内容如下。
<html> <body bgcolor="red"> <center> <%= request.getSession().getId() %> <h1>Test2:192.168.10.62</h1> <h1>port:8080</h1> </center> </body> </html>