WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [] milliseconds.


編譯安裝tomcat-native和tomcat-deamon以后,發現toomcat啟動很慢,好久才有響應。以下日志供參考:

11-Sep-2017 12:19:28.102 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-9.0/webapps/ROOT]
11-Sep-2017 12:19:28.667 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:20:34.870 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [66,193] milliseconds.
11-Sep-2017 12:20:34.917 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/ROOT] has finished in [66,815] ms
11-Sep-2017 12:20:34.918 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-9.0/webapps/host-manager]
11-Sep-2017 12:20:35.004 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:20:35.013 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/host-manager] has finished in [96] ms
11-Sep-2017 12:20:35.014 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-9.0/webapps/manager]
11-Sep-2017 12:20:35.062 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:20:35.066 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/manager] has finished in [53] ms
11-Sep-2017 12:20:35.074 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
11-Sep-2017 12:20:35.105 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
11-Sep-2017 12:20:35.113 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 67067 ms

tomcat啟動耗時67067ms折合67秒,剛剛安裝的干凈tomcat,顯然不對勁。

有一條日志引起了我的注意:

11-Sep-2017 12:20:34.870 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [66,193] milliseconds.

顯然tomcat執行到這里時出問題了,google了一下:"tomcat startup take long time SecureRandom",經過搜索,發現了一個解決方法

Slow startup on Tomcat 7.0.57 because of SecureRandom

 問題緣由:當沒有足夠的entropy反饋給/dev/random時調用securerandom的時候可能引起阻塞。

解決方法1:

修改 /opt/jdk1.8/jre/jre/lib/security/java.security

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

解決方法2:安裝haveged

apt-get install haveged
vim /etc/default/haveged #編輯配置文件,輸入下面一行
DAEMON_ARGS="-w 1024"

#刷新配置 update-rc.d haveged defaults

筆者采用了第二種方法,ubuntu16 amd64,64位系統,其他linux系統參考How to Setup Additional Entropy for Cloud Servers Using Haveged

同以上操作順利解決問題。

更新后重啟tomcat日志如下:

[/opt/apache-tomcat-9.0/webapps/ROOT]
11-Sep-2017 12:28:00.324 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:28:00.374 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/ROOT] has finished in [567] ms
11-Sep-2017 12:28:00.375 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-9.0/webapps/host-manager]
11-Sep-2017 12:28:00.448 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:28:00.456 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/host-manager] has finished in [80] ms
11-Sep-2017 12:28:00.456 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-9.0/webapps/manager]
11-Sep-2017 12:28:00.502 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars 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.
11-Sep-2017 12:28:00.504 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-9.0/webapps/manager] has finished in [48] ms
11-Sep-2017 12:28:00.514 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
11-Sep-2017 12:28:00.545 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
11-Sep-2017 12:28:00.565 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 803 ms

參考:

Tomcat takes too much time to start - Java SecureRandom

How to Setup Additional Entropy for Cloud Servers Using Haveged

Slow startup on Tomcat 7.0.57 because of SecureRandom

Tomcat 8熵池阻塞變慢詳解


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM