nginx+redis+tomcat實現session共用

來源:互聯網
上載者:User

標籤: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共用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.