Tomcat多实例运行配置

多实例运行配置

1、环境变量设置

设置tomcat环境变量如下

export JAVA_HOME=/usr/java/jdk1.7.0_80

export JRE_HOME=$JAVA_HOME/jre 

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH;

export CATALINA_HOME=/usr/tomcat7

仅设置CATALINA_HOME变量,CATALINA_BASE变量启动时进行指定。


2、实例目录配置

    多实例配置目录如下目录树结构。lib与bin目录位于CATALINA_HOME目录,在CATALINA_HOME目录下创建jason1、jason2实例目录。并拷贝conf logs temp webapps work至各实例目录中。

[root@jason1 tomcat7]# pwd

/usr/tomcat7 

[root@jason1 tomcat7]# tree -d -L 2

.

|-- bin

|-- jason1

|   |-- conf

|   |-- logs

|   |-- temp

|   |-- webapps

|   `-- work

|-- jason2

|   |-- conf

|   |-- logs

|   |-- temp

|   |-- webapps

|   `-- work

`-- lib

14 directories

[root@jason1 tomcat7]# 


3、配置实例server.xml文件

jason1实例

<?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" />

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- 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" />

  <GlobalNamingResources>

    <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>

  <Service name="Catalina">

    <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <Engine name="Catalina" defaultHost="www.jason2.com">

      <Realm className="org.apache.catalina.realm.LockOutRealm">      

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

               resourceName="UserDatabase"/>

      </Realm>

      <Host name="www.jason2.com"  appBase="/usr/tomcat7/jason2/webapps"

            unpackWARs="true" autoDeploy="true">

  <Context path="" docBase="/usr/tomcat7/jason2/webapps/jason2"  reloadable="true" />

        <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>

</Server>


jason2实例

<?xml version='1.0' encoding='utf-8'?>

<Server port="8006" 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" />

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- 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" />

  <GlobalNamingResources>

    <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>

  <Service name="Catalina">

    <Connector port="8081" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8444" />

    <Engine name="Catalina" defaultHost="www.jason2.com">

      <Realm className="org.apache.catalina.realm.LockOutRealm">      

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

               resourceName="UserDatabase"/>

      </Realm>

      <Host name="www.jason2.com"  appBase="/usr/tomcat7/jason2/webapps"

            unpackWARs="true" autoDeploy="true">

  <Context path="" docBase="/usr/tomcat7/jason2/webapps/jason2"  reloadable="true" />

        <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>

</Server>

备注:确保端口号不冲突


4、启动tomcat实例

启动实例jason1

[root@jason1 temp]# export CATALINA_BASE=/usr/tomcat7/jason1

[root@jason1 temp]# export CATALINA_TMPDIR=/usr/tomcat7/jason1/temp

[root@jason1 temp]# $CATALINA_HOME/bin/startup.sh

Using CATALINA_BASE:   /usr/tomcat7/jason1

Using CATALINA_HOME:   /usr/tomcat7

Using CATALINA_TMPDIR: /usr/tomcat7/jason1/temp

Using JRE_HOME:        /usr/java/jdk1.7.0_80/jre

Using CLASSPATH:       /usr/tomcat7/bin/bootstrap.jar:/usr/tomcat7/bin/tomcat-juli.jar

Tomcat started.

[root@jason1 temp]# 

启动实例jason2

[root@jason1 temp]# export CATALINA_BASE=/usr/tomcat7/jason2

[root@jason1 temp]# export CATALINA_TMPDIR=/usr/tomcat7/jason2/temp

[root@jason1 temp]# $CATALINA_HOME/bin/startup.sh

Using CATALINA_BASE:   /usr/tomcat7/jason2

Using CATALINA_HOME:   /usr/tomcat7

Using CATALINA_TMPDIR: /usr/tomcat7/jason2/temp

Using JRE_HOME:        /usr/java/jdk1.7.0_80/jre

Using CLASSPATH:       /usr/tomcat7/bin/bootstrap.jar:/usr/tomcat7/bin/tomcat-juli.jar

Tomcat started.

[root@jason1 temp]# 


5、访问测试

已经设置好DNS记录与测试页内容,如下为测试结果

jason1实例测试页显示如下

wKioL1ZmhsLAAjAFAACO4-hbMsQ599.jpg

jason2实例测试页显示如下

wKiom1ZmhmXhQtqNAACTsRV5KBw023.jpg

你可能感兴趣的:(tomcat,multiple,instances)