Go
Go

tomcat server.xml配置调优

记录Tomcat server.xml配置文件的各属性用于调优

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?xml version="1.0" encoding="UTF-8"?>

<!-- Server是最外层标签,包含了所有的子标签 -->
<Server port="8005" shutdown="SHUTDOWN">
<!-- 注册所有的监听器 -->
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener calssName="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- 全局的 JNDI 资源, tomcat管理用户信息 -->
<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包含了一个或者多个Container容器 -->
<Service name="Catalina">
<!-- connector使用的线程池Executor定义,参考Java线程池各个参数的意义 -->
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="500"
minSpareThreads="80"
maxQueueSize="100"
maxIdleTime="60000"
prestartminSpareThreads="true" />
<!-- Connector配置 http 8080 -->
<Connector port="8080" // 运行的端口
executor="tomcatThreadPool" // 之前定义的线程池
protocol="org.apache.coyote.http11.Http11NioProtocol" //Bio Nio Aio
connectionTimeout="20000"
redirectPort="8443"
maxConnections="10000"
enableLookups="false"
acceptCount="100"
maxPostSize="10485760"
maxHttpHeaderSize="4096"
compression="on"
disableUploadTimeout="true"
compressionMinSize="1024"
acceptorThreadCount="2" // cpu数量+1
processorCache="20000"
tcpNoDelay="true"
connectionLinger="5"
URIEncoding="utf-8"
server="Tengine"
compressableMimeType="text/html,text/plain,application/x-javascript,text/css,application/xml,text/javascript,application/x-httpd-php,image/jpeg,image/gif,image/png" />

<!-- 使用SSL证书 http+SSL 8443 -->

<!-- 使用AJP -->
...

<!-- jvmRouter 负载均衡 -->
<Engine name="Catalina" defaultHost="localhost">
...
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- guess -->
<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 &quot;%r&quot; %s %b" />
</Host>
</Engine>
</Service>
</Server>