0%

Tomcat启动慢原因排查

故障现象1

Tomcat启动异常,卡在以下提示处

1
2
3
INFO: validateJarFile(/usr/local/apache-tomcat-7.0.79/webapps/thsbox/WEB-INF/lib/tomcat-servlet-api-8.5.15.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 17, 2017 2:36:19 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.

关闭TLDs

1
2
3
4
5
6
7
vim  /usr/local/apache-tomcat-7.0.79/conf/context.xml

<Context processTlds="false">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
……
</Context>

屏蔽jar包

1
2
3
4
vim /usr/local/apache-tomcat-7.0.79/conf/catalina.properties

tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
tomcat-servlet-api-8.5.15.jar

更改以上两个地方,日志还是会打印出来,启动还是卡主

故障现象2

起初以为是启动不起来了,后来一直等着,发现只是很慢,可以启动起来的,在7分钟左右

1
INFO: Server startup in 432720 ms

跟踪日志有重大发现

1
WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [422,085] milliseconds

第一种修改方法

1
2
3
4
vim /usr/local/jdk1.8.0_112/jre/lib/security/java.security

#securerandom.source=file:/dev/random
securerandom.source=file:/dev/./random

修改完成后INFO: Server startup in 118722 ms(还是慢)

第二种修改方法

1
2
3
vim /usr/local/apache-tomcat-7.0.79/bin/catalina.sh
修改第232行
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Djava.security.egd=file:/dev/./urandom"

修改完成后INFO: Server startup in 8985 ms

参考:http://www.cnblogs.com/raphael5200/p/6844510.html