Windows部署多个tomcat实例

前提本机先安装tomcat 8应用

1. 在tomcat路径下创建Domains文件夹用于存放需要创建的tomcat实例,如:bizWorkflowManager

2. 创建实例相应所需的目录文件结构,包含:bin、conf、logs、temp、webapps、work等,具体结构如下:

Windows部署多个tomcat实例

 3. 将tomcat路径下的conf中的文件拷贝至bizWorkflowManager实例下的conf文件夹中,修改server.xml文件,内容如下,并进行保存:

<?xml version='1.0' encoding='utf-8'?>
 <Server port="-1" shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <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="8011" maxParameterCount="1000" protocol="AJP/1.3" redirectPort="8443"  maxSpareThreads="750" maxThreads="1000" minSpareTHreads="50" acceptCount="1000" URIEncoding="gbk" useBodyEncodingForURI="true"/>
    -->
    <Connector port="9083" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443"  URIEncoding="utf-8" useBodyEncodingForURI="true"/>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="s1">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="false" autoDeploy="false"
            xmlValidation="false" xmlNamespaceAware="false">

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

4. 检查bizWorkflowManager文件下Catalina\localhost路径下是否有ROOT.xml文件,若有可修改其中的docBase使其指向具体的war包部署路径,如指向:D:\tools\apache-tomcat-8.5.41\Domains\bizWorkflowManager\webapps\ROOT

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" docBase="D:\tools\apache-tomcat-8.5.41\Domains\bizWorkflowManager\webapps\ROOT" >
</Context>

若无ROOT.xml,可不用处理,默认执行实例路径下的webapps\ROOT路径

5. 实例bizWorkflowManager bin路径下创建start.bat、stop.bat用于启动、停止tomcat实例,脚本具体内容如下:

start.bat

@echo off
:: if "%1" == "h" goto begin 
:: start mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit 
:: :begin

rem ---------------------------------------------------------------------------
rem Start script for the CATALINA Server
rem ---------------------------------------------------------------------------

set "CATALINA_HOME=D:\tools\apache-tomcat-8.5.41"
set "CATALINA_BASE=D:\tools\apache-tomcat-8.5.41\Domains\bizWorkflowManager"
::JAVA
rem export JAVA_HOME=/export/servers/jdk1.6.0_25
rem export JAVA_BIN=${JAVA_HOME}/bin
rem export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/bin
rem export CLASSPATH=.:/lib/dt.jar:/lib/tools.jar
rem -Djava.library.path=%CLASSPATH% 
set "JAVA_OPTS=-server -Xms1024m -Xmx1024m -Djava.awt.headless=true -Dsun.net.client.defaultConnectTimeout=60000 -Dsun.net.client.defaultReadTimeout=60000 -Djmagick.systemclassloader=no -Dnetworkaddress.cache.ttl=300 -Dsun.net.inetaddr.ttl=300 -Dfile.encoding=GBK -Dsun.jnu.encoding=GBK -Duser.timezone=GMT+08"
%CATALINA_HOME%/bin/startup.bat "-config %CATALINA_BASE%/conf/server.xml"

stop.bat

@echo off
rem ---------------------------------------------------------------------------
rem Stop script for the CATALINA Server
rem ---------------------------------------------------------------------------

set "CATALINA_HOME=D:\tools\apache-tomcat-8.5.41"
set "CATALINA_BASE=D:\tools\apache-tomcat-8.5.41\Domains\bizWorkflowManager"
%CATALINA_HOME%/bin/shutdown.bat "-config %CATALINA_BASE%/conf/server.xml"

6. 将web应用生成的war包放在bizWorkflowManager\webapps\ROOT路径下,执行bin路径下的start.bat启动应用即可

Windows部署多个tomcat实例

路径下放置了一个clean.bat文件用于方便清理ROOT路径下部署的文件,进行重新部署,clean.bat具体内容如下:

@echo off

call :DEL_DIR
call :DEL_FILE
goto :EOF


REM 删除文件夹
:DEL_DIR
for /f %%i in ('dir /ad/b') do (
	echo [INFO]: 删除文件夹:%%i
	rd /s /q %%i
)
goto :EOF

REM 删除文件
:DEL_FILE
for /f %%i in ('dir /b') do (
	if not "%%i"=="clean.bat" (
		echo [INFO]: 删除文件:%%i
		del /f /s /q %%i
	)
)
goto :EOF

添加其他实例,步骤同上

上一篇:SpringCloud集成Zuul报错No content to map due to end-of-input at [Source: (String)““; line: 1, column: 0]


下一篇:MAC环境下Nginx配置