Tomcat在部署应用时卡住

最新在一台新的CentOS上部署环境,当部署完Tomcat8准备启起来看看效果时发现一直阻塞在部署应用这条日志下。

1
Deploying web application directory /tomcat/webapps/live

记得新下载的tomcat解压后直接启动一点问题没有,但为了安全清空了webapps下的tomcat ROOT和Manage应用后,并把我的应用传上来在启动就卡住了,一直无解。
后来google到了一篇文章

1
2
3
4
5
6
7
8
9
One thing I noticed on one of my first upgrades is that TC7 can often
take a long time to start up due to slow initialization of the
SessionIdGenerator - it can take up to nearly 2 minutes! It appears
to take longer if I restart TC7 quickly which seems to confirm that a
lack of entropy is the issue.
org.apache.catalina.util.SessionIdGenerator-: Creation of SecureRandom
instance for session ID generation using [SHA1PRNG] took [105,014]
milliseconds.

大体意思为Tomcat7+依赖 SecureRandom 提供的随机数给分布式Session做ID,取决于JRE,可能会导致Tomcat启动的延迟,上面这个人大概等了2分钟左右。

有两种解决方法.
1.修改Tomcat catalina.sh配置,设置非阻塞的SecureRandom初始化。

1
-Djava.security.egd=file:/dev/./urandom

2.修改JVM配置$JAVA_PATH/jre/lib/security/java.security。

1
securerandom.source=file:/dev/urandom

替换成

1
securerandom.source=file:/dev/./urandom

修改后,启动时间恢复正常。