系統總是頻繁更新,為了避免更新系統的時候領導看不到東西,打算用ngix做代理,后臺部署兩個tomcat做負載均衡,避免更新一臺就無法使用系統的問題,這兩天看了寫資料,把幾個關鍵點記錄在這里以便備忘。
環境:jdk,1.7,tomcat7,nginx1.5.8; 基于64位的windows配置
第一步:更改tomcat三個端口,保證同一臺機器上可以運行兩個tomcat,更改的端口包括server port,兩個connector port,xml配置參見下面,為了避免文件過大,刪除了注釋和無關的配置:
- <? xml? version= '1.0'? encoding= 'utf-8' ?>??
- ???
- < Server? port= "18005"? shutdown= "SHUTDOWN" >???
- ?? < Listener? className= "org.apache.catalina.core.AprLifecycleListener"? SSLEngine= "on"? />??
- ?? <!--Initialize?Jasper?prior?to?webapps?are?loaded.?Documentation?at?/docs/jasper-howto.html?-->??
- ?? < Listener? className= "org.apache.catalina.core.JasperListener"? />??
- ?? <!--?Prevent?memory?leaks?due?to?use?of?particular?java/javax?APIs-->??
- ?? < Listener? className= "org.apache.catalina.core.JreMemoryLeakPreventionListener"? />??
- ?? < Listener? className= "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"? />??
- ?? < Listener? className= "org.apache.catalina.core.ThreadLocalLeakPreventionListener"? />??
- ??
- ????
- ?? < GlobalNamingResources >??
- ????
- ???? < Resource? name= "UserDatabase"? auth= "Container"??
- ?????????????? type= "org.apache.catalina.UserDatabase"??
- ?????????????? description= "User?database?that?can?be?updated?and?saved"??
- ?????????????? factory= "org.apache.catalina.users.MemoryUserDatabaseFactory"??
- ?????????????? pathname= "conf/tomcat-users.xml"? />??
- ?? </ GlobalNamingResources >??
- ??
- ???
- ?? < Service? name= "Catalina" >??
- ??
- ???
- ???? < Connector? port= "8082"? protocol= "HTTP/1.1"??
- ??????????????? connectionTimeout= "20000"??
- ??????????????? redirectPort= "8443"? />??
- ?????
- ???? < Connector? port= "18009"? protocol= "AJP/1.3"? redirectPort= "8443"? />??
- ??
- ???
- ?????。。。。。??
- ?? </ Service >??
- </ Server >??
?
?
第二部,配置nginx(負載均衡):
http節點下增加如下配置:
- upstream?localhost?{??????
- ????????#針對不同ip的用戶請求分配固定的tomcat響應其請求。??????
- ????????ip_hash;??
- ????????????????#配置tomcat服務器的ip:端口,處理請求權重??
- ????????server?localhost:8080?weight=5;???
- ????????server?localhost:8082?weight=5;??
- ????}??
?
?
http的節點下更改location/節點配置:
- location?/?{??
- ???????????#root???html;??
- ???????????#index??index.html?index.htm;??
- ????????proxy_connect_timeout???3;??
- ????????proxy_send_timeout??????30;??
- ????????proxy_read_timeout??????30;??
- ????????proxy_pass?http://localhost;??
- ???????}??
配置完畢后,啟動兩個tomcat,再啟動nginx,啟動ngix方式:進入dos命令窗口,切換至nginx主目錄,輸入命令nginx.exe即可,
?
停止nginx可以使用nginx.exe -s stop
?
了解更詳細的步驟參考下面兩個鏈接:
http://ari.iteye.com
http://www.blogjava.net/tunaic/archive/2009/11/30/304212.html
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
