一、一机器配置多Tomcat
1、配置多个CATALINA_BASE,CATALINA_HOME,TOMCAT_HOME
2、修改startup.bat,shutdown.bat,service.bat,catalina.bat
----startup.bat----
@echo off
if "%OS%" == "Windows_NT" setlocal
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME_Budget%" == "" goto gotHome
set "CATALINA_HOME_Budget=%CURRENT_DIR%"
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME_Budget=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME_Budget environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
set "EXECUTABLE=%CATALINA_HOME_Budget%\bin\catalina.bat"
----shutdown.bat----
@echo off
if "%OS%" == "Windows_NT" setlocal
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME_Budget%" == "" goto gotHome
set "CATALINA_HOME_Budget=%CURRENT_DIR%"
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME_Budget=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME_Budget environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
set "EXECUTABLE=%CATALINA_HOME_Budget%\bin\catalina.bat"
----service.bat----
@echo off
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME_Budget%" == "" goto gotHome
set "CATALINA_HOME_Budget=%cd%"
if exist "%CATALINA_HOME_Budget%\bin\tomcat6.exe" goto okHome
rem CD to the upper dir
cd ..
set "CATALINA_HOME_Budget=%cd%"
:gotHome
if exist "%CATALINA_HOME_Budget%\bin\tomcat6.exe" goto okHome
echo The tomcat.exe was not found...
echo The CATALINA_HOME_Budget environment variable is not defined correctly.
echo This environment variable is needed to run this program
goto end
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto okHome
echo The JAVA_HOME environment variable is not defined
echo This environment variable is needed to run this program
goto end
:okHome
if not "%CATALINA_BASE_Budget%" == "" goto gotBase
set "CATALINA_BASE_Budget=%CATALINA_HOME_Budget%"
:gotBase
set "EXECUTABLE=%CATALINA_HOME_Budget%\bin\tomcat6.exe"
rem Set default Service name
set SERVICE_NAME=Tomcat6
set PR_DISPLAYNAME=Apache Tomcat 6
if "%1" == "" goto displayUsage
if "%2" == "" goto setServiceName
set SERVICE_NAME=%2
set PR_DISPLAYNAME=Apache Tomcat %2
:setServiceName
if %1 == install goto doInstall
if %1 == remove goto doRemove
if %1 == uninstall goto doRemove
echo Unknown parameter "%1"
:displayUsage
echo.
echo Usage: service.bat install/remove [service_name]
goto end
:doRemove
rem Remove the service
"%EXECUTABLE%" //DS//%SERVICE_NAME%
echo The service '%SERVICE_NAME%' has been removed
goto end
:doInstall
rem Install the service
echo Installing the service '%SERVICE_NAME%' ...
echo Using CATALINA_HOME_Budget: "%CATALINA_HOME_Budget%"
echo Using CATALINA_BASE_Budget: "%CATALINA_BASE_Budget%"
echo Using JAVA_HOME: "%JAVA_HOME%"
rem Use the environment variables as an example
rem Each command line option is prefixed with PR_
set PR_DESCRIPTION=Apache Tomcat 6.0.32 Server - http://tomcat.apache.org/
set "PR_INSTALL=%EXECUTABLE%"
set "PR_LOGPATH=%CATALINA_BASE_Budget%\logs"
set "PR_CLASSPATH=%CATALINA_BASE_Budget%\bin\tomcat-juli.jar;%CATALINA_HOME_Budget%\bin\tomcat-juli.jar;%CATALINA_HOME_Budget%\bin\bootstrap.jar"
rem Set the server jvm from JAVA_HOME
set "PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dll"
if exist "%PR_JVM%" goto foundJvm
rem Set the client jvm from JAVA_HOME
set "PR_JVM=%JAVA_HOME%\jre\bin\client\jvm.dll"
if exist "%PR_JVM%" goto foundJvm
set PR_JVM=auto
:foundJvm
echo Using JVM: "%PR_JVM%"
"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
if not errorlevel 1 goto installed
echo Failed installing '%SERVICE_NAME%' service
goto end
:installed
rem Clear the environment variables. They are not needed any more.
set PR_DISPLAYNAME=
set PR_DESCRIPTION=
set PR_INSTALL=
set PR_LOGPATH=
set PR_CLASSPATH=
set PR_JVM=
rem Set extra parameters
"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE_Budget%;-Dcatalina.home=%CATALINA_HOME_Budget%;-Djava.endorsed.dirs=%CATALINA_HOME_Budget%\endorsed" --StartMode jvm --StopMode jvm
rem More extra parameters
set "PR_LOGPATH=%CATALINA_BASE_Budget%\logs"
set PR_STDOUTPUT=auto
set PR_STDERROR=auto
"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE_Budget%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE_Budget%\conf\logging.properties" --JvmMs 128 --JvmMx 256 --Startup=auto
echo The service '%SERVICE_NAME%' has been installed.
:end
cd "%CURRENT_DIR%"
----catalina.bat----
@echo off
set "CURRENT_DIR=%cd%"
if not "%CATALINA_HOME_Budget%" == "" goto gotHome
set "CATALINA_HOME_Budget=%CURRENT_DIR%"
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
cd ..
set "CATALINA_HOME_Budget=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%CATALINA_HOME_Budget%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME_Budget environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
rem Ensure that any user defined CLASSPATH variables are not used on startup,
rem but allow them to be specified in setenv.bat, in rare case when it is needed.
set CLASSPATH=
rem Get standard environment variables
if "%CATALINA_BASE_Budget%" == "" goto gotSetenvHome
if exist "%CATALINA_BASE_Budget%\bin\setenv.bat" call "%CATALINA_BASE_Budget%\bin\setenv.bat"
goto gotSetenvBase
:gotSetenvHome
if exist "%CATALINA_HOME_Budget%\bin\setenv.bat" call "%CATALINA_HOME_Budget%\bin\setenv.bat"
:gotSetenvBase
rem Get standard Java environment variables
if exist "%CATALINA_HOME_Budget%\bin\setclasspath.bat" goto okSetclasspath
echo Cannot find "%CATALINA_HOME_Budget%\bin\setclasspath.bat"
echo This file is needed to run this program
goto end
:okSetclasspath
set "BASEDIR=%CATALINA_HOME_Budget%"
call "%CATALINA_HOME_Budget%\bin\setclasspath.bat" %1
if errorlevel 1 goto end
if not "%CATALINA_BASE_Budget%" == "" goto gotBase
set "CATALINA_BASE_Budget=%CATALINA_HOME_Budget%"
:gotBase
if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
set "CATALINA_TMPDIR=%CATALINA_BASE_Budget%\temp"
:gotTmpdir
rem Add tomcat-juli.jar and bootstrap.jar to classpath
rem tomcat-juli.jar can be over-ridden per instance
rem Note that there are no quotes as we do not want to introduce random
rem quotes into the CLASSPATH
if "%CLASSPATH%" == "" goto emptyClasspath
set "CLASSPATH=%CLASSPATH%;"
:emptyClasspath
if "%CATALINA_BASE_Budget%" == "%CATALINA_HOME_Budget%" goto juliClasspathHome
if not exist "%CATALINA_BASE_Budget%\bin\tomcat-juli.jar" goto juliClasspathHome
set "CLASSPATH=%CLASSPATH%%CATALINA_BASE_Budget%\bin\tomcat-juli.jar;%CATALINA_HOME_Budget%\bin\bootstrap.jar"
goto juliClasspathDone
:juliClasspathHome
set "CLASSPATH=%CLASSPATH%%CATALINA_HOME_Budget%\bin\bootstrap.jar"
:juliClasspathDone
if not "%LOGGING_CONFIG%" == "" goto noJuliConfig
set LOGGING_CONFIG=-Dnop
if not exist "%CATALINA_BASE_Budget%\conf\logging.properties" goto noJuliConfig
set LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE_Budget%\conf\logging.properties"
:noJuliConfig
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%
if not "%LOGGING_MANAGER%" == "" goto noJuliManager
set LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
:noJuliManager
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%
rem ----- Execute The Requested Command ---------------------------------------
echo Using CATALINA_BASE_Budget: "%CATALINA_BASE_Budget%"
echo Using CATALINA_HOME_Budget: "%CATALINA_HOME_Budget%"
echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
if ""%1"" == ""debug"" goto use_jdk
echo Using JRE_HOME: "%JRE_HOME%"
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME: "%JAVA_HOME%"
:java_dir_displayed
echo Using CLASSPATH: "%CLASSPATH%"
set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=
if not ""%1"" == ""jpda"" goto noJpda
set JPDA=jpda
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
set JPDA_TRANSPORT=dt_socket
:gotJpdaTransport
if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=8000
:gotJpdaAddress
if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
set JPDA_SUSPEND=n
:gotJpdaSuspend
if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
:gotJpdaOpts
shift
:noJpda
if ""%1"" == ""debug"" goto doDebug
if ""%1"" == ""run"" goto doRun
if ""%1"" == ""start"" goto doStart
if ""%1"" == ""stop"" goto doStop
if ""%1"" == ""version"" goto doVersion
echo Usage: catalina ( commands ... )
echo commands:
echo debug Start Catalina in a debugger
echo debug -security Debug Catalina with a security manager
echo jpda start Start Catalina under JPDA debugger
echo run Start Catalina in the current window
echo run -security Start in the current window with security manager
echo start Start Catalina in a separate window
echo start -security Start in a separate window with security manager
echo stop Stop Catalina
echo version What version of tomcat are you running?
goto end
:doDebug
shift
set _EXECJAVA=%_RUNJDB%
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME_Budget%\..\..\java"
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE_Budget%\conf\catalina.policy"
goto execCmd
:doRun
shift
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE_Budget%\conf\catalina.policy"
goto execCmd
:doStart
shift
if not "%OS%" == "Windows_NT" goto noTitle
if "%TITLE%" == "" set TITLE=Tomcat
set _EXECJAVA=start "%TITLE%" %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%
:gotTitle
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set "SECURITY_POLICY_FILE=%CATALINA_BASE_Budget%\conf\catalina.policy"
goto execCmd
:doStop
shift
set ACTION=stop
set CATALINA_OPTS=
goto execCmd
:doVersion
%_EXECJAVA% -classpath "%CATALINA_HOME_Budget%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
goto end
:execCmd
rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs
rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE_Budget%" -Dcatalina.home="%CATALINA_HOME_Budget%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE_Budget%" -Dcatalina.home="%CATALINA_HOME_Budget%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE_Budget%" -Dcatalina.home="%CATALINA_HOME_Budget%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE_Budget%" -Dcatalina.home="%CATALINA_HOME_Budget%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:end
二、删除服务 sc delete 服务名
新增服务 tomcat路径下 cmd-->service.bat install 服务名
三、外置Tomcat部署springboot war包
1、环境变量
CATALINA_BASE
CATALINA_HOME
PATH: %CATALINA_HOME%/lib,%CATALINA_HOME%/bin
配置服务service.bat install
直接启动项目cmd -> startup
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<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" />
<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">
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
<Engine name="Catalina2" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapp"
unpackWARs="true" autoDeploy="true">
<Context docBase="/haikai-fund-tp-rest" path="/tpreport" reloadable="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>
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https" />
</Engine>
</Service>
</Server>
四、启动springboot 项目,优化Tomcat参数
java -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx4096m -Xmn4096m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -jar EXXX.war>E:\Users\HK_wansh\Desktop\journal.log