单Tomcat多Service配置

      记得以前搭建项目时,遇到了多项目时,并不懂得怎么去分离开项目,一开始的做法,在一个Tomcat上使用项目名称区别的方法搭建项目。今天试了用多Service方式,记录下步骤,以备忘。

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 &quot;%r&quot; %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 &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

    修改完毕,只需要把项目部署到/srv/www/bbs即可,bbs项目内容如下:

   

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/

   

你可能感兴趣的:(tomcat)