在Apache Tomcat 7設置redis做爲session store

redis已經有組件支持直接在tomcat7中設置下將redis做爲tomcat默認的session存儲器,下面介紹下配置過程java

1.從http://redis.io/下載redis,按照redis服務端git

?github

1
2
3
4
wget http: //download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

2.啓動redisredis

?apache

1
2
cd RedisDirectory/src
./redis-server --port 6379

3.從http://tomcat.apache.org/download-70.cgi下載tomcat7,按照tomcat7tomcat

4.從https://github.com/xetorthio/jedis/downloads下載jedis做爲java的redis客戶 端,從https://github.com/jcoleman/tomcat-redis-session-manager/downloads下載 tomcat的redis session manager插件,從http://commons.apache.org/proper/commons-pool /download_pool.cgi下載apache的common pool包,將這幾個jar包拷貝到tomcat7的lib目錄下session

5.修改tomcat的conf下的context.xml文件,添加或者修改下面的配置spa

?.net

1
2
3
4
5
6
>Valve className= "com.radiadesign.catalina.session.RedisSessionHandlerValve" />
>Manager className= "com.radiadesign.catalina.session.RedisSessionManager"
host= "localhost" <!-- optional: defaults to "localhost" -->
port= "6379" <!-- optional: defaults to "6379" -->
database= "0" <!-- optional: defaults to "0" -->
maxInactiveInterval= "60" <!-- optional: defaults to "60" (in seconds) --> />

6.重啓tomcat後就能夠看到session存儲到redis上了。插件

相關文章
相關標籤/搜索