?Cloud現(xiàn)在是一個熱門的技術(shù),Tomcat是學(xué)習(xí)Java的人一般都會接觸的Web服務(wù)器,如果在Cloud環(huán)境下使用Tomcat,又當(dāng)如何呢?不可避免的,要安裝多個Tomcat了,這里稱之為Tomcat實(shí)例,進(jìn)而通過云平臺來多Tomcat進(jìn)行管理。
?
???????? 如何在一臺機(jī)器上安裝多個Tomcat實(shí)例呢?
這個問題想必使用過Tomcat的人都知道:
1)? 下載Tomcat.zip
2)? 解壓,后的Tomcat拷貝1份,每一份就稱之為一個實(shí)例,并修改Tomcat實(shí)例的tomcat_home/conf/server.xml中的端口就OK了。
3)? 創(chuàng)建其實(shí)實(shí)例,只需要重復(fù)步驟2)。
?
不錯,的確是這樣,這樣可以說是簡單又容易操作。但是,還有另外的處理方式,是一種類似于WebLogic、Glassfish的處理方式。
?
Glassfish的處理方式可以總結(jié)為:
1)? 安裝Glassfish,(這個過程就將Glassfish通用的jar包放在一個共用的地方)
2)? 創(chuàng)建每個實(shí)例,只要添加相應(yīng)的配置,work dir即可。
?
仿照這種處理思路來安裝多個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目錄,用于作為兩個實(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)訪問測試:訪問ins1、ins2:
?
?
分別執(zhí)行ins1、ins2下的startup.bat文件啟動ins1、ins2。
在瀏覽器上輸入 http://localhost:8080 、 http://localhost:9080 都可以訪問到Tomcat的首頁。
?
?
Cloud相關(guān)的設(shè)計(jì),其實(shí)就是利用這個原理來實(shí)現(xiàn)的。
?
=============================================================
下面是Tomcat 官方文檔中的說法:
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í)例安裝的情況下,一般對于同一個Tomcat集群,會使用共享webapps目錄的。也就是在同一個集群下的Tomcat實(shí)例的server.xml中<Host appBase=“設(shè)置為同一個目錄”/>
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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