使用 Redis 來存儲 Apache Tomcat 7 的 Session

jopen 11年前發布 | 74K 次閱讀 Redis Tomcat 應用服務器

unknown.jpg

使用 Redis 服務器來存儲Session非常有優勢。首先它是一個NOSQL數據,第二它很容易擴展使用。 This kind of setup would lead to a clear understanding of how Redis can behave as cache as well as a session storing system. In order to do this the instructions are as follows :-

  1. Download Redis and build by the following commands (This includes downloading it too)
    wget http://download.redis.io/redis-stable.tar.gz
    tar xvzf redis-stable.tar.gz
    cd redis-stable
    make
  2. Start Redis using command(Redis Directory refers to the directory where Redis is built)
    cd RedisDirectory/src
    ./redis-server --port 6379
  3. Get the latest version of Apache Tomcat 7
  4. Download the latest version for JEDIS (A Redis Java Client), Tomcat Redis Session Manager (Redis-backed non-sticky session store for Apache Tomcat) and Apache Commons Pool .
  5. Copy all the above files into the lib folder of the Apache Tomcat 7 installation directory.
  6. Add the lines mentioned below in the context.xml of your Apache Tomcat 7 (Or on the context block of server.xml if applicable).Edit the Configurations as your settings. In out case the port number to be configured is 6279.
    <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) --> />
  7. Now restart your Apache Tomcat 7 normally and now you would see that the sessions are being created in the Redis Rather than on Tomcat.

Thats it. Now you have your Apache Tomcat 7 storing all the sessions in Redis and it also takes care about the different aspects of sessions.

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!