|
1、目的:在服务器上安装一个tomcat实现多个应用的服务
2、步骤:修改$TOMCAT_HOME/conf/server.xml,其中service部分就是配置的一个应用服务,复制多个service,则就建立多个应用服务。
3、内容:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<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>
<!-- 第一个应用服务 :采用tomcat默认配置-->
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
<!-- 第二个应用服务 :需要修改一些端口和目录-->
<Service name="Catalina2"> <!-- 1:需要修改name名称和上面service的不一样-->
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" /> <!-- 2:需要修改port端口号和上面service的不同,防止端口冲突,这里改为8088,这样访问该应用的url: http://localhost:8088/ -->
<Connector port="8019" protocol="AJP/1.3" redirectPort="8443" /> <!-- 3:需要修改port端口号和上面service的不同,防止端口冲突,这里改为8019-->
<Engine name="Catalina2" defaultHost="localhost"> <!-- 4:需要修改engine的名字和上面的不同-->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="c:/test/webapps"
unpackWARs="true" autoDeploy="true"> <!-- 5:需要修改appBase的目录为新的应用的目录,这里改为c:/test/webapps,也就是新应用程序部署的新目录-->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
想实现更多的应用服务添加相应的service即可,注意service name不能相同,端口不能相同
4、实验:
默认目录的部署:
首先是tomcat的默认应用中,我们在tomcat/webapps下部署一个web应用为jcyy.war,那么启动tomcat后,就应该是这么访问: http://localhost:8080/jcyy/index.jsp
新应用目录的部署:
在上面server.xml中配置第二个service时,指定的appBase="c:/test/webapps",那么,我们部署一个web应用srie.war到该目录下,启动tomcat,则访问路径为:http://localhost:8088/srie/index.html
【注】:其实启动一次tomcat后,两个应用服务就都启动了,只需部署到不同目录后,浏览器直接对应不同的端口访问不同的应用即可。
http://www.iyunv.com/os/201203/122237.html |
|
|
|
|
|
|