記得之前搭建項目時,遇到了多項目時,並不懂得怎麼去分離開項目,一開始的作法,在一個Tomcat上使用項目名稱區別的方法搭建項目。今天試了用多Service方式,記錄下步驟,以備忘。html
soi@soi:/opt/apache/tomcat/8.0.27$sudo cp conf/server.xml conf/server.xml.bk soi@soi:/opt/apache/tomcat/8.0.27$sudo vi conf/server.xml
<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> --> <!--APR library loader. Documentation at /docs/apr.html --> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!-- 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" /> <!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html --> <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <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> <!-- <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/> --> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <!-- <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> --> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine name="Catalina" defaultHost="localhost"> <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> <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.authenticator.SingleSignOn" /> --> <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配置--> <Service name="bbs"> <Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="bbs" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="" unpackWARs="true" autoDeploy="true"> <!-- debug=「0」指定debug的等級 docBase指定項目路徑 path指定項目的訪問路徑,空表示根路徑 reloadable="true"表示支持部署 --> <Context debug="0" docBase="/srv/www/bbs" path="" privileged="true" reloadable="true"/> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="bbs_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
修改完畢,只須要把項目部署到/srv/www/bbs便可,bbs項目內容以下:java
soi@soi:/srv/www/bbs$ ll drwxrwxr-x 6 root root 4096 10月 17 21:28 ./ drwxr-xr-x 3 root root 4096 10月 17 21:54 ../ -rw-rw-r-- 1 root root 4286 10月 15 20:32 favicon.ico drwxrwxr-x 5 root root 4096 10月 17 21:28 ftl/ drwxrwxr-x 2 root root 4096 10月 17 21:28 META-INF/ drwxrwxr-x 8 root root 4096 10月 17 21:28 static/ drwxrwxr-x 4 root root 4096 10月 17 21:28 WEB-INF/