1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > tomcat端口修改以及jvm启动参数设置

tomcat端口修改以及jvm启动参数设置

时间:2021-09-10 12:21:01

相关推荐

tomcat端口修改以及jvm启动参数设置

1、端口更改:找到config目录下server.xml文件 如下

<?xml version='1.0' encoding='utf-8'?><!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License. You may obtain a copy of the License at/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--><!-- Note: A "Server" is not itself a "Container", so you may notdefine subcomponents such as "Valves" at this level.Documentation at /docs/config/server.html--><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" /><!-- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html--><GlobalNamingResources><!-- Editable user database that can also be used byUserDatabaseRealm 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><!-- A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note: A "Service" is not itself a "Container",so you may not define subcomponents such as "Valves" at this level.Documentation at /docs/config/service.html--><Service name="Catalina"><!--The connectors can use a shared executor, you can define one or more named thread pools--><!--<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"maxThreads="150" minSpareThreads="4"/>--><!-- A "Connector" represents an endpoint by which requests are receivedand responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)Java AJP Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL HTTP/1.1 Connector on port 8080--> <Connector port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="8192"connectionTimeout="20000"redirectPort="8443" URIEncoding="UTF-8"/><!-- A "Connector" using the shared thread pool--><!--<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" URIEncoding="UTF-8"/>--><!-- Define a SSL HTTP/1.1 Connector on port 8443This connector uses the BIO implementation that requires the JSSEstyle configuration. When using the APR/native implementation, theOpenSSL style configuration is required as described in the APR/nativedocumentation --><!--<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"maxThreads="150" SSLEnabled="true" scheme="https" secure="true"clientAuth="false" sslProtocol="TLS" />--><!-- Define an AJP 1.3 Connector on port 8009 --><Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /><!-- An Engine represents the entry point (within Catalina) that processesevery request. The Engine implementation for Tomcat stand aloneanalyzes the HTTP headers included with the request, and passes themon to the appropriate Host (virtual host).Documentation at /docs/config/engine.html --><!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">--><Engine name="Catalina" defaultHost="localhost"><!--For clustering, please take a look at documentation at:/docs/cluster-howto.html (simple how to)/docs/config/cluster.html (reference documentation) --><!--<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>--><!-- Use the LockOutRealm to prevent attempts to guess user passwordsvia a brute-force attack --><Realm className="org.apache.catalina.realm.LockOutRealm"><!-- This Realm uses the UserDatabase configured in the global JNDIresources under the key "UserDatabase". Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm. --><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true"><!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --><!--<Valve className="org.apache.catalina.authenticator.SingleSignOn" />--><!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: The pattern used is equivalent to using pattern="common" --><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>

我们一般只需要改掉我标红的port就行了。

2、启动参数设置

找到tomcat的bin目录下catalina.bat文件 ,打开如下

SET JAVA_HOME=..\..\jdk1.7.0_60x64SET JAVA_OPTS=-server -Xmx8g -Xms8g -XX:MaxPermSize=2048m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseConcMarkSweepGC -Xloggc:e:/JVM_GC_XXX_8080.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps @echo offrem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements. See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License. You may obtain a copy of the License atremrem/licenses/LICENSE-2.0remrem Unless required by applicable law or agreed to in writing, softwarerem distributed under the License is distributed on an "AS IS" BASIS,rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.rem See the License for the specific language governing permissions andrem limitations under the License.rem ---------------------------------------------------------------------------rem Start/Stop Script for the CATALINA Serverremrem Environment Variable Prerequisitesremrem Do not set the variables in this script. Instead put them into a scriptrem setenv.bat in CATALINA_BASE/bin to keep your customizations separate.remrem WHEN RUNNING TOMCAT AS A WINDOWS SERVICE:rem Note that the environment variables that affect the behavior of thisrem script will have no effect at all on Windows Services. As such, anyrem local customizations made in a CATALINA_BASE/bin/setenv.bat scriptrem will also have no effect on Tomcat when launched as a Windows Service.rem The configuration that controls Windows Services is stored in the Windowsrem Registry, and is most conveniently maintained using the "tomcatXw.exe"rem maintenance utility, where "X" is the major version of Tomcat you arerem running.remrem CATALINA_HOME May point at your Catalina "build" directory.remrem CATALINA_BASE (Optional) Base directory for resolving dynamic portionsrem of a Catalina installation. If not present, resolves torem the same directory that CATALINA_HOME points to.remrem CATALINA_OPTS (Optional) Java runtime options used when the "start",rem "run" or "debug" command is executed.rem Include here and not in JAVA_OPTS all options, that shouldrem only be used by Tomcat itself, not by the stop process,rem the version command etc.rem Examples are heap size, GC logging, JMX ports etc.remrem CATALINA_TMPDIR (Optional) Directory path location of temporary directoryrem the JVM should use (java.io.tmpdir). Defaults torem %CATALINA_BASE%\temp.remrem JAVA_HOME Must point at your Java Development Kit installation.rem Required to run the with the "debug" argument.remrem JRE_HOME Must point at your Java Runtime installation.rem Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOMErem are both set, JRE_HOME is used.remrem JAVA_OPTS (Optional) Java runtime options used when any commandrem is executed.rem Include here and not in CATALINA_OPTS all options, thatrem should be used by Tomcat and also by the stop process,rem the version command etc.rem Most options should go into CATALINA_OPTS.remrem JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directoriesrem containing some jars in order to allow replacement of APIsrem created outside of the JCP (i.e. DOM and SAX from W3C).rem It can also be used to update the XML parser implementation.rem Defaults to $CATALINA_HOME/endorsed.remrem JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"rem command is executed. The default is "dt_socket".remrem JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"rem command is executed. The default is 8000.remrem JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"rem command is executed. Specifies whether JVM should suspendrem execution immediately after startup. Default is "n".remrem JPDA_OPTS (Optional) Java runtime options used when the "jpda start"rem command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,rem and JPDA_SUSPEND are ignored. Thus, all required jpdarem options MUST be specified. The default is:remrem -agentlib:jdwp=transport=%JPDA_TRANSPORT%,rem address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%remrem JSSE_OPTS (Optional) Java runtime options used to control the TLSrem implementation when JSSE is used. Default is:rem "-Djdk.tls.ephemeralDHKeySize=2048"remrem LOGGING_CONFIG (Optional) Override Tomcat's logging config filerem Example (all one line)rem set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"remrem LOGGING_MANAGER (Optional) Override Tomcat's logging managerrem Example (all one line)rem set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"remrem TITLE (Optional) Specify the title of Tomcat window. The defaultrem TITLE is Tomcat if it's not specified.rem Example (all one line)rem set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]rem ---------------------------------------------------------------------------setlocalrem Suppress Terminate batch job on CTRL+Cif not ""%1"" == ""run"" goto mainEntryif "%TEMP%" == "" goto mainEntryif exist "%TEMP%\%~nx0.run" goto mainEntryecho Y>"%TEMP%\%~nx0.run"if not exist "%TEMP%\%~nx0.run" goto mainEntryecho Y>"%TEMP%\%~nx0.Y"call "%~f0" %* <"%TEMP%\%~nx0.Y"rem Use provided errorlevelset RETVAL=%ERRORLEVEL%del /Q "%TEMP%\%~nx0.Y" >NUL 2>&1exit /B %RETVAL%:mainEntrydel /Q "%TEMP%\%~nx0.run" >NUL 2>&1rem Guess CATALINA_HOME if not definedset "CURRENT_DIR=%cd%"if not "%CATALINA_HOME%" == "" goto gotHomeset "CATALINA_HOME=%CURRENT_DIR%"if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHomecd ..set "CATALINA_HOME=%cd%"cd "%CURRENT_DIR%":gotHomeif exist "%CATALINA_HOME%\bin\catalina.bat" goto okHomeecho The CATALINA_HOME environment variable is not defined correctlyecho This environment variable is needed to run this programgoto end:okHomerem Copy CATALINA_BASE from CATALINA_HOME if not definedif not "%CATALINA_BASE%" == "" goto gotBaseset "CATALINA_BASE=%CATALINA_HOME%":gotBaserem 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 variablesif not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHomecall "%CATALINA_BASE%\bin\setenv.bat"goto setenvDone:checkSetenvHomeif exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat":setenvDonerem Get standard Java environment variablesif exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspathecho Cannot find "%CATALINA_HOME%\bin\setclasspath.bat"echo This file is needed to run this programgoto end:okSetclasspathcall "%CATALINA_HOME%\bin\setclasspath.bat" %1if errorlevel 1 goto endrem Add on extra jar file to CLASSPATHrem Note that there are no quotes as we do not want to introduce randomrem quotes into the CLASSPATHif "%CLASSPATH%" == "" goto emptyClasspathset "CLASSPATH=%CLASSPATH%;":emptyClasspathset "CLASSPATH=%CLASSPATH%%CATALINA_HOME%\bin\bootstrap.jar"if not "%CATALINA_TMPDIR%" == "" goto gotTmpdirset "CATALINA_TMPDIR=%CATALINA_BASE%\temp":gotTmpdirrem Add tomcat-juli.jar to classpathrem tomcat-juli.jar can be over-ridden per instanceif not exist "%CATALINA_BASE%\bin\tomcat-juli.jar" goto juliClasspathHomeset "CLASSPATH=%CLASSPATH%;%CATALINA_BASE%\bin\tomcat-juli.jar"goto juliClasspathDone:juliClasspathHomeset "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar":juliClasspathDoneif not "%JSSE_OPTS%" == "" goto gotJsseOptsset JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048":gotJsseOptsset "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%"if not "%LOGGING_CONFIG%" == "" goto noJuliConfigset LOGGING_CONFIG=-Dnopif not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliConfigset LOGGING_CONFIG=-Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties":noJuliConfigset "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%"if not "%LOGGING_MANAGER%" == "" goto noJuliManagerset LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager:noJuliManagerset "JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%"rem ----- Execute The Requested Command ---------------------------------------echo Using CATALINA_BASE: "%CATALINA_BASE%"echo Using CATALINA_HOME: "%CATALINA_HOME%"echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"if ""%1"" == ""debug"" goto use_jdkecho Using JRE_HOME: "%JRE_HOME%"goto java_dir_displayed:use_jdkecho Using JAVA_HOME: "%JAVA_HOME%":java_dir_displayedecho Using CLASSPATH: "%CLASSPATH%"set _EXECJAVA=%_RUNJAVA%set MAINCLASS=org.apache.catalina.startup.Bootstrapset ACTION=startset SECURITY_POLICY_FILE=set DEBUG_OPTS=set JPDA=if not ""%1"" == ""jpda"" goto noJpdaset JPDA=jpdaif not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransportset JPDA_TRANSPORT=dt_socket:gotJpdaTransportif not "%JPDA_ADDRESS%" == "" goto gotJpdaAddressset JPDA_ADDRESS=8000:gotJpdaAddressif not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspendset JPDA_SUSPEND=n:gotJpdaSuspendif not "%JPDA_OPTS%" == "" goto gotJpdaOptsset JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%:gotJpdaOptsshift:noJpdaif ""%1"" == ""debug"" goto doDebugif ""%1"" == ""run"" goto doRunif ""%1"" == ""start"" goto doStartif ""%1"" == ""stop"" goto doStopif ""%1"" == ""configtest"" goto doConfigTestif ""%1"" == ""version"" goto doVersionecho Usage: catalina ( commands ... )echo commands:echo debug Start Catalina in a debuggerecho debug -security Debug Catalina with a security managerecho jpda start Start Catalina under JPDA debuggerecho runStart Catalina in the current windowecho run -securityStart in the current window with security managerecho start Start Catalina in a separate windowecho start -security Start in a separate window with security managerecho stop Stop Catalinaecho configtest Run a basic syntax check on server.xmlecho version What version of tomcat are you running?goto end:doDebugshiftset _EXECJAVA=%_RUNJDB%set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"if not ""%1"" == ""-security"" goto execCmdshiftecho Using Security Managerset "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"goto execCmd:doRunshiftif not ""%1"" == ""-security"" goto execCmdshiftecho Using Security Managerset "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"goto execCmd:doStartshiftif "%TITLE%" == "" set TITLE=Tomcatset _EXECJAVA=start "%TITLE%" %_RUNJAVA%if not ""%1"" == ""-security"" goto execCmdshiftecho Using Security Managerset "SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy"goto execCmd:doStopshiftset ACTION=stopset CATALINA_OPTS=goto execCmd:doConfigTestshiftset ACTION=configtestset CATALINA_OPTS=goto execCmd:doVersion%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfogoto end:execCmdrem Get remaining unshifted command line arguments and save them in theset CMD_LINE_ARGS=:setArgsif ""%1""=="""" goto doneSetArgsset CMD_LINE_ARGS=%CMD_LINE_ARGS% %1shiftgoto setArgs:doneSetArgsrem Execute Java with the applicable propertiesif not "%JPDA%" == "" goto doJpdaif 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%" -Dcatalina.home="%CATALINA_HOME%" -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%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%goto end:doJpdaif not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda%_EXECJAVA% %JAVA_OPTS% %JPDA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%goto end:doSecurityJpda%_EXECJAVA% %JAVA_OPTS% %JPDA_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%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%goto end:end

#以上红色部分则为参数设置。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。