生产环境部署Tomcat配置
Contents
操作系统设置
limit
╭─sky@sky-linux ~
╰─➤ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-m: resident set size (kbytes) unlimited
-u: processes 63555
-n: file descriptors 1024
-l: locked-in-memory size (kbytes) 64
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 63555
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
会话级别
如果不想全局设置limit,可以在会话级别设置,即在启动程序之前,设置好limit后再启动程序
# 硬设置
ulimit -Hc unlimited
ulimit -Hn 65535
# 软设置
ulimit -Sc unlimited
ulimit -Sn 65535
全局设置limit
编辑 /etc/security/limits.conf
文件.添加或修改为如下
* soft core unlimited
* hard core unlimited
* soft nofile 65535
* hard nofile 65535
Tomcat自身设置
统一UTF-8
<Connector port="8095" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
关闭 auto-deploy
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false">
Tomcat线程池
threadPriority
: 线程的优先级minSpareThreads
:最小一定存活线程数,这个是会一直保持的,默认为25
maxThreads
: 最大同时存活线程数,默认为200
daemon
:是否是守护线程,默认为true
.maxIdleTime
: 最大空闲时间,单位是毫秒。即线程达到了这个时间后,就会shutdown,直到线程数达到了minSpareThreads
数.maxQueueSize
:最大任务队列数。默认值为Integer.MAX_VALUE
prestartminSpareThreads
: 启动时,是否初化minSpareThreads
的线程。默认为false
.threadRenewalDelay
: 重建线程池的线程的时间间隔。(前提是配置了ThreadLocalLeakPreventionListener
。 默认为1000
ms。如果为负,则不重建.namePrefix
:线程名前的前缀<Executor name="tomcatThreadPool" namePrefix="mytomcat-exec-" maxThreads="150" minSpareThreads="4"/>
然后在Connector里配置使用线程池
<Connector port="8095" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true" executor="tomcatThreadPool" />
JVM 配置
#!/bin/sh
JVM_TYPE = " -server"
JVM_GC=" -XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:/tmp/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M"
JVM_DUMP=" -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/jvm-dump-`date`.hprof"
JVM_GC_TYPE=" -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=90 -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark"
# 单位:秒
JVM_DNS_CACHE=" -Dsun.net.inetaddr.ttl=60"
# hostname如果为远程,则是外网的IP
JVM_RMI=" -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
# survivorratio = eden / from 的比值
JVM_MEM=" -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -Xmn300m -XX:SurvivorRatio=8"
JVM_DEBUG=" -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
CATALINA_OPTS=" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager ${JVM_TYPE} ${JVM_GC_TYPE} ${JVM_GC} ${JVM_DUMP} ${JVM_DNS_CACHE} ${JVM_RMI} ${JVM_MEM} ${JVM_DEBUG} "