標籤:session共用
本次測試使用的是tomcat7,使用tomcat7的話jdk就一定要使用1.7版本的。
使用組件版本nginx:1.8.0 tomcat兩個:7.0.67 redis:2.4.10 JDK:1.7.0_79
(1)將下面所有依賴的這些jar包放在$TOMCAT_HOME/lib中:
jedis-2.2.1.jar
tomcat-redis-session-manager-1.2-tomcat-7.jar
commons-pool-1.6.jar
2) 兩個tomcat分別配置conf/context.xml,增加:
<ValveclassName="com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<ManagerclassName="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60" />
nginx的配置如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
upstream cluster_redis{
server10.20.9.175:8080;
server10.20.9.176:8080;
}
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent"$http_referer" ‘
# ‘"$http_user_agent""$http_x_forwarded_for"‘;
#access_log logs/access.log main;
之後把nginx,tomcat,redis啟動之後進行測試
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/78/09/wKiom1Zz7haAMmMDAAJe6N2mO0c184.png" title="1.png" width="700" height="625" border="0" hspace="0" vspace="0" style="width:700px;height:625px;" alt="wKiom1Zz7haAMmMDAAJe6N2mO0c184.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/78/09/wKiom1Zz7jHy5AiVAAJjKW6wV2w468.png" title="2.png" width="700" height="636" border="0" hspace="0" vspace="0" style="width:700px;height:636px;" alt="wKiom1Zz7jHy5AiVAAJjKW6wV2w468.png" />
參考資料:
http://dinguangx.iteye.com/blog/2230980
http://xstarcd.github.io/wiki/Java/tomcat_cluster.html
http://www.cnblogs.com/lengfo/p/4260363.html
nginx+redis+tomcat實現session共用