tomcat7/8/9在linux環(huán)境下啟動慢的優(yōu)化辦法

云服務(wù)器:阿里云CentOS7.3 64,Tomcat:9.0.14.0

tomcat webapps下的項目

tomcat啟動耗時

現(xiàn)象:如上圖所示,tomcat官網(wǎng)下載的壓縮包,未做任何添加,啟動耗時11分34秒

原因
Tomcat 7/8都使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom類產(chǎn)生安全隨機類SecureRandom的實例作為會話ID,這里花去了342秒,也即接近6分鐘。

解決辦法

  • 1、在Tomcat環(huán)境中解決
    可以通過配置JRE使用非阻塞的Entropy Source。
    在catalina.sh中加入這么一行:-Djava.security.egd=file:/dev/./urandom 即可。

  • 2、在JVM環(huán)境中解決
    打開$JAVA_PATH/jre/lib/security/java.security這個文件,找到下面的內(nèi)容:
    securerandom.source=file:/dev/random
    替換成
    securerandom.source=file:/dev/./urandom

[root@sihan ~]# vim /usr/lib/jvm/jdk1.8.0_202/jre/lib/security/java.security 
# Specifying this System property will override the
# "securerandom.source" Security property.
#
# In addition, if "file:/dev/random" or "file:/dev/urandom" is
# specified, the "NativePRNG" implementation will be more preferred than
# SHA1PRNG in the Sun provider.
#
securerandom.source=file:/dev/./urandom

修改前啟動耗時



修改后啟動耗時


image.png

修改完后會有明顯的改善效果

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容