一般应用程序都需要做参数调整,比如MySQL,Oracle。Tomcat的常见优化参数如下

一、打开JMX监控

 在catalina.sh文件中加入:

CATALINA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

二、调整tomcat的内存大小

 在catalina.sh文件中加入:

JAVA_OPTS="-server -Xms2048m -Xmx2048m -XX:MetaspaceSize=512m"

三、调整tomcat的线程数、长连接等参数

修改server.xml:

8080端口参数:

  <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" 
               maxThreads="2000"
               acceptCount="300"
               maxIdleTime="60000"
               minSpareThreads="50"
               maxKeepAliveRequests="100"
               keepAliveTimeout="1"
               acceptorThreadCount="16"
              />


8009端口参数(如果没有用到mod_jk可以不用调整):

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
maxThreads="800"
acceptCount="300"
minSpareThreads="50"
maxKeepAliveRequests="100"
keepAliveTimeout="1"
acceptorThreadCount="16"
/>


修改tomcat-users.xml,添加用户权限,如果需要用到maven自动上传war包到远程服务器可以用到 

  

  <role rolename="tomcat"/>

  <role rolename="manager-gui"/>

  <role rolename="manager-script"/>

  <role rolename="manager-jmx" />

  <user username="manager" password="manager" roles="manager-gui,manager-script" />

</tomcat-users>