导致Tomcat启动过程缓慢的原因及解决方法

1、现象

在CentOS启动Tomcat时,启动过程很慢,需要几分钟,经过查看日志,发现耗时在这里:是session引起的随机数问题导致的。Tocmat的Session ID是通过SHA1算法计算得到的,计算Session ID的时候必须有一个密钥。为了提高安全性Tomcat在启动的时候会通过随机生成一个密钥。 

22-Apr-2017 19:33:07.623 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of

 SecureRandom instance for session ID generation using [SHA1PRNG] took [55,507] milliseconds.

22-Apr-2017 19:33:07.653 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web appli

cation directory /application/apache-tomcat-8.0.27/webapps/ROOT has finished in 55,935 ms

主要原因是生成随机数的时候卡住了,导致tomcat启动不了。

是否有足够的熵来用于产生随机数,可以通过如下命令来查看

[root@oldboy tools]# cat /proc/sys/kernel/random/entropy_avail

扫描二维码关注公众号,回复: 432893 查看本文章

7

为了加速/dev/random提供随机数的速度,你可以通过操作设备的外设,让其产生大量的中断(如网络传输数据,按键,移动鼠标,在命令行敲几个不同的命令,俗称聚气。

cat /dev/random 会消耗能量

方法1:

vim $JAVA_HOME/jre/lib/security/java.security

securerandom.source=file:/dev/random

改为

securerandom.source=file:/dev/urandom

方法2:

vim $TOMCAT_HOME/bin/catalina.sh

if [[ "$JAVA_OPTS" != *-Djava.security.egd=* ]]; then

    JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/urandom"

fi

这个系统属性egd表示熵收集守护进程(entropy gathering daemon)

方法3:

yum install rng-tools # 安装rngd服务(熵服务,增大熵池)

systemctl start rngd  # 启动服务

猜你喜欢

转载自www.cnblogs.com/bowen-li/p/s920318.html