今天拿到一台新的腾讯云机器,准备部署WEB服务

安装JDK,安装Tomcat,启服,访问,浏览器一直在转,查看安全组配置,没有问题,本地访问,依然是在等待中…

查看Tomcat日志,好像没有成功启动,像是卡在哪里了,结束,重启,还是这鬼样…

正在查找问题的同时,意外发现Tomcat启来了,也能访问,重启又是这鸟样

分析日志,启动时间太久 大概要4分钟

09-Aug-2017 13:30:47.978 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.35
09-Aug-2017 13:30:47.979 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          May 11 2016 21:57:08 UTC
09-Aug-2017 13:30:47.979 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.35.0
09-Aug-2017 13:30:47.979 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
09-Aug-2017 13:30:47.979 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-327.36.3.el7.x86_64
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/jdk1.8.0_92/jre
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_92-b14
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat-8080
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat-8080
09-Aug-2017 13:30:47.980 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat-8080/conf/logging.properties
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/usr/local/tomcat-8080/endorsed
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat-8080
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat-8080
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat-8080/temp
09-Aug-2017 13:30:47.981 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
09-Aug-2017 13:30:48.124 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
09-Aug-2017 13:30:48.139 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
09-Aug-2017 13:30:48.141 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
09-Aug-2017 13:30:48.143 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
09-Aug-2017 13:30:48.144 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 540 ms
09-Aug-2017 13:30:48.164 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
09-Aug-2017 13:30:48.164 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.35
09-Aug-2017 13:30:48.172 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat-8080/webapps/manager
09-Aug-2017 13:34:05.447 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [197,038] milliseconds.
09-Aug-2017 13:34:05.471 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat-8080/webapps/manager has finished in 197,299 ms
09-Aug-2017 13:34:05.472 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat-8080/webapps/ROOT
09-Aug-2017 13:34:05.490 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat-8080/webapps/ROOT has finished in 18 ms
09-Aug-2017 13:34:05.490 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat-8080/webapps/docs
09-Aug-2017 13:34:05.509 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat-8080/webapps/docs has finished in 19 ms
09-Aug-2017 13:34:05.509 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat-8080/webapps/host-manager
09-Aug-2017 13:34:05.532 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat-8080/webapps/host-manager has finished in 23 ms
09-Aug-2017 13:34:05.543 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
09-Aug-2017 13:34:05.550 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
09-Aug-2017 13:34:05.551 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 197407 ms

有了确定的现象,网络一下结论和解决方案

结论

Tomcat 的 SessionID 是通过 SHA1PRNG 算法计算得到的,SHA1 算法需要一个密钥,这个密钥在 Tomcat 启动的时候随机生成一个,生成是使用了 Linux 随机函数生成器/dev/random。
读取它相当于生成随机数字。/dev/random会根据 噪音 产生随机数,如果噪音不够它就会阻塞。linux 是通过 I/O,键盘终端、内存使用量、CPU 利用率等方式来收集噪音的,如果噪音不够生成随机数的时候就会被阻塞。

解决方案

安装熵服务

yum install rng-tools

启动熵服务

systemctl start rngd

重启Tomcat,Server startup in 305 ms

转载请注明原地址: http://blog.noark.xyz/article/2017/8/10/腾讯云tomcat启动太慢的情况/