系統(tǒng)總是頻繁更新,為了避免更新系統(tǒng)的時(shí)候領(lǐng)導(dǎo)看不到東西,打算用ngix做代理,后臺(tái)部署兩個(gè)tomcat做負(fù)載均衡,避免更新一臺(tái)就無(wú)法使用系統(tǒng)的問(wèn)題,這兩天看了寫資料,把幾個(gè)關(guān)鍵點(diǎn)記錄在這里以便備忘。
環(huán)境:jdk,1.7,tomcat7,nginx1.5.8; 基于64位的windows配置
第一步:更改tomcat三個(gè)端口,保證同一臺(tái)機(jī)器上可以運(yùn)行兩個(gè)tomcat,更改的端口包括server port,兩個(gè)connector port,xml配置參見(jiàn)下面,為了避免文件過(guò)大,刪除了注釋和無(wú)關(guān)的配置:
- <? 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(負(fù)載均衡):
http節(jié)點(diǎn)下增加如下配置:
- upstream?localhost?{??????
- ????????#針對(duì)不同ip的用戶請(qǐng)求分配固定的tomcat響應(yīng)其請(qǐng)求。??????
- ????????ip_hash;??
- ????????????????#配置tomcat服務(wù)器的ip:端口,處理請(qǐng)求權(quán)重??
- ????????server?localhost:8080?weight=5;???
- ????????server?localhost:8082?weight=5;??
- ????}??
?
?
http的節(jié)點(diǎn)下更改location/節(jié)點(diǎn)配置:
- location?/?{??
- ???????????#root???html;??
- ???????????#index??index.html?index.htm;??
- ????????proxy_connect_timeout???3;??
- ????????proxy_send_timeout??????30;??
- ????????proxy_read_timeout??????30;??
- ????????proxy_pass?http://localhost;??
- ???????}??
配置完畢后,啟動(dòng)兩個(gè)tomcat,再啟動(dòng)nginx,啟動(dòng)ngix方式:進(jìn)入dos命令窗口,切換至nginx主目錄,輸入命令nginx.exe即可,
?
停止nginx可以使用nginx.exe -s stop
?
了解更詳細(xì)的步驟參考下面兩個(gè)鏈接:
http://ari.iteye.com
http://www.blogjava.net/tunaic/archive/2009/11/30/304212.html
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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