?Cloud現(xiàn)在是一個(gè)熱門(mén)的技術(shù),Tomcat是學(xué)習(xí)Java的人一般都會(huì)接觸的Web服務(wù)器,如果在Cloud環(huán)境下使用Tomcat,又當(dāng)如何呢?不可避免的,要安裝多個(gè)Tomcat了,這里稱(chēng)之為T(mén)omcat實(shí)例,進(jìn)而通過(guò)云平臺(tái)來(lái)多Tomcat進(jìn)行管理。
?
???????? 如何在一臺(tái)機(jī)器上安裝多個(gè)Tomcat實(shí)例呢?
這個(gè)問(wèn)題想必使用過(guò)Tomcat的人都知道:
1)? 下載Tomcat.zip
2)? 解壓,后的Tomcat拷貝1份,每一份就稱(chēng)之為一個(gè)實(shí)例,并修改Tomcat實(shí)例的tomcat_home/conf/server.xml中的端口就OK了。
3)? 創(chuàng)建其實(shí)實(shí)例,只需要重復(fù)步驟2)。
?
不錯(cuò),的確是這樣,這樣可以說(shuō)是簡(jiǎn)單又容易操作。但是,還有另外的處理方式,是一種類(lèi)似于WebLogic、Glassfish的處理方式。
?
Glassfish的處理方式可以總結(jié)為:
1)? 安裝Glassfish,(這個(gè)過(guò)程就將Glassfish通用的jar包放在一個(gè)共用的地方)
2)? 創(chuàng)建每個(gè)實(shí)例,只要添加相應(yīng)的配置,work dir即可。
?
仿照這種處理思路來(lái)安裝多個(gè)Tomcat:
1)? 解壓到安裝目錄
2)? 創(chuàng)建Tomcat實(shí)例:拷貝config、logs、tmp、webapps、work目錄,然后修改config/server.xml中的端口即可。
3)創(chuàng)建其它實(shí)例,只需要重復(fù)步驟2)。
?
示例:
?
1)解壓apache-tomcat-6.0.41,
2)安裝Tomcat實(shí)例:創(chuàng)建實(shí)例目錄apache-tomcat-6.0.41-instances,并在該目錄創(chuàng)建ins1、inst2目錄,用于作為兩個(gè)實(shí)例的目錄。拷貝conf、logs、temp、webapps、work到ins1、ins2目錄下。
3)修改實(shí)例port:ins1使用默認(rèn)端口,修改ins2中的端口,即:
Ins2端口為:8005 –>9005 、8080--à9080 、8443--à9443
?
?
4)創(chuàng)建startup.bat文件,并copy到ins1、ins2目錄下:
?
代碼如下:

@echo on @echo delete work directory ... rmdir /S/Q % CD %\ work @echo set env ... SET JAVA_HOME=E:\Program Files \Java\jdk1.8. 0_20 SET PATH =%JAVA_HOME%\bin;% PATH % @echo instance root directory SET CATALINA_BASE=% CD % @echo start instance cd ../../apache-tomcat-6.0.41/ bin catalina .bat start
?
5)訪(fǎng)問(wèn)測(cè)試:訪(fǎng)問(wèn)ins1、ins2:
?
?
分別執(zhí)行ins1、ins2下的startup.bat文件啟動(dòng)ins1、ins2。
在瀏覽器上輸入 http://localhost:8080 、 http://localhost:9080 都可以訪(fǎng)問(wèn)到Tomcat的首頁(yè)。
?
?
Cloud相關(guān)的設(shè)計(jì),其實(shí)就是利用這個(gè)原理來(lái)實(shí)現(xiàn)的。
?
=============================================================
下面是Tomcat 官方文檔中的說(shuō)法:
Tomcat supports installation of multiple instances. You can have a single installation of Tomcat with multiple instances running on different IP/port combinations, or multiple Tomcat versions, each running one or more instances on different IP/ports.
Each instance folder will need the following structure:
- conf
- logs
- temp
- webapps
- work
At a minimum, conf should contain a copy of the following files from CATALINA_HOME\conf\. Any files not copied and edited, will be picked up by default from CATALINA_HOME\conf, i.e. CATALINA_BASE\conf files override defaults from CATALINA_HOME\conf.
- server.xml
- web.xml
You must edit CATALINA_BASE\conf\server.xml to specify a unique IP/port for the instance to listen on. Find the line that contains?
<Connector port="8080" ...
?and add an address attribute and/or update the port number so as to specify a unique IP/port combination.
To install an instance, first set the CATALINA_HOME environment variable to the name of the Tomcat installation directory. Then create a second environment variable CATALINA_BASE and point this to the instance folder. Then run "service install" command specifying a service name.
set CATALINA_HOME=c:\tomcat_8
set CATALINA_BASE=c:\tomcat_8\instances\instance1
service install instance1
====================================================================?
在多實(shí)例安裝的情況下,一般對(duì)于同一個(gè)Tomcat集群,會(huì)使用共享webapps目錄的。也就是在同一個(gè)集群下的Tomcat實(shí)例的server.xml中<Host appBase=“設(shè)置為同一個(gè)目錄”/>
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(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ì)您有幫助就好】元
