windows nginx tomcat redis 叢集

來源:互聯網
上載者:User

對之前的nginx+tomcat的負載平衡機制,因為會出現session丟失的問題,特研究了下redis的session共用;(如果想搭建本環境可從上一篇開始,涉及到nginx的環境搭建http://blog.csdn.net/qq584852076/article/details/46469141)

下載JDK7、tomcat7以備後續測試;

一、下載tomcat-redis-session的源碼自行打包:https://github.com/jcoleman/tomcat-redis-session-manager

這裡要對tomcat-redis-session打包做一下特殊記錄:

由於我們的環境都是基於7系列來啟動並執行,所以必須保持一致;

二、下載redis安裝並運行 http://redis.io/download

下載後進入redis-windows-master\src\msopentech\redis-64.2.8.17 目錄

在CMD中執行 redis-server.exe redis.windows.conf 如圖

三、打包產生tomcat-redis-session.jar包,從網上下載jedis-2.7.2.jar   commons-pool2-2.4.1.jar;將這3個包放入tomcat\lib目錄下;

 

四、配置tomcat\conf下的context.xml檔案 [html]  view plain  copy <?xml version='1.0' encoding='utf-8'?>   <Context>       <WatchedResource>WEB-INF/web.xml</WatchedResource>              <!-- tomcat-redis-session共用配置 -->       <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />           <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"            host="localhost"             port="6379"             database="0"             maxInactiveInterval="60" />   <!----------------------------- -->      </Context>  

 

五、多個tomcat的配置都一致,所以把配置都copy到對應的其他tomcat下;如果在一台機器上進行測試,記得對各個tomcat的連接埠進行修改;個人的部署環境如下:

六、測試整個環境:(需要提前在tomcat放置一個簡單的web項目)

啟動redis

啟動nginx

啟動3個tomcat
訪問:http://localhost/ 不停的F5重新整理頁面 發現頁面的sessionid不變;關閉某個tomcat繼續F5,sessionid也不變,說明環境搭建成功; 個人資產庫中放置需要用到的設定檔以及相關jar包,redis伺服器等資源;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.