tomcat session 共享

代码层:
1、web.xml 增加
  <filter>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSessionRepositoryFilter</filter-name>
    <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>ERROR</dispatcher>
  </filter-mapping>

2、porm.xml 增加
        <dependency>
		   <groupId>org.springframework.session</groupId>
		   <artifactId>spring-session</artifactId>
		   <version>1.2.2.RELEASE</version>
		</dependency>

tomcat:
3、tomcat目录下的 lib 文件夹增加 redisson-all-3.2.0.jar 和 redisson-tomcat-7-3.2.0.jar 
  (
 redis客户端的wiki https://github.com/redisson/redisson/wiki/%E7%9B%AE%E5%BD%95 https://github.com/redisson/redisson/wiki/14.-%E7%AC%AC%E4%B8%89%E6%96%B9%E6%A1%86%E6%9E%B6%E6%95%B4%E5%90%88#144-tomcat%E4%BC%9A%E8%AF%9D%E7%AE%A1%E7%90%86%E5%99%A8tomcat-session-manager)
  
4、conf 文件夹下的 context.xml 增加
  <Manager className="org.redisson.tomcat.RedissonSessionManager" configPath="${catalina.base}/conf/redis.yaml" />

5、bin 文件夹下的 setenv.sh 增加
   
   arr=${JAVA_OPTS}
   for key in ${arr}
   do
       x="$(echo ${key} | awk -F '=' '{ print $1 "=" $2}')"
       for i in ${x};
       do
           if [[ ${i} == *"Ddisconf"* ]] ;then
               if [[ ${i} == *"Ddisconf.conf_server"* ]] ;then
                   disconf_server=`echo $i | awk -F '=' '{print $2}'`
               fi
               if [[ ${i} == *"Ddisconf.app"* ]] ;then
                   disconf_app=`echo $i | awk -F '=' '{print $2}'`
               fi
               if [[ ${i} == *"Ddisconf.version"* ]] ;then
                   disconf_version=`echo $i | awk -F '=' '{print $2}'`
               fi
               if [[ ${i} == *"Ddisconf.env"* ]] ;then
                   disconf_env=`echo $i | awk -F '=' '{print $2}'`
               fi
           fi
       done
   done
   
   echo "准备下载redis.yaml。。。" 
   redisConfig="/usr/local/tomcat8080/conf/redis.yaml"
   echo $redisConfig
   wget  -q "http://disconf.frontpay.cn/api/config/file?version=${disconf_version}&app=${disconf_app}&env=${disconf_env}&key=redis.yaml"   -O "${redisConfig}"
   if [ -f "$redisConfig"  -a -s "$redisConfig" ]; then
       echo "下载redis.yaml完成" 
   else
       echo "${redisConfig} 文件不存在" 
       rm -rf "$redisConfig"
   fi






redis.yaml 配置

---
clusterServersConfig:
idleConnectionTimeout: 10000
pingTimeout: 1000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
reconnectionTimeout: 3000
failedAttempts: 3
password: null
subscriptionsPerConnection: 5
clientName: null
slaveSubscriptionConnectionMinimumIdleSize: 1
slaveSubscriptionConnectionPoolSize: 50
slaveConnectionMinimumIdleSize: 10
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 10
masterConnectionPoolSize: 64
readMode: "SLAVE"
nodeAddresses:
- "redis://10.1.20.159:7000"
- "redis://10.1.20.159:7001"
- "redis://10.1.20.159:7002"
- "redis://10.1.21.2:7001"
- "redis://10.1.21.2:7002"
scanInterval: 1000
threads: 0
nettyThreads: 0
useLinuxNativeEpoll: false


 

posted on 2017-03-08 10:17  Error503  阅读(435)  评论(0编辑  收藏  举报

导航