重复启动Tomcat时,大概率出现Deploying web application direct

仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述重复启动Tomcat时,大概率出现Deploying web application direct相关的知识,希望能为你提供帮助。
由前一篇文章开始折腾supervisor,想玩玩tomcat异常退出后使用supervisor自动让tomcat重新启动,
随即丢了一个tomcat在服务器里面,本来就没有放任何项目,空跑在那边,只是tomcat有个界面就看看起没起来。
 
于是手动停止tomcat的进程触发supervisor自动拉起服务,应该是没有问题的,但是,来来回回启动了个两三次,突然发现,tomcat竟然起不来了!
随即查阅下日志:
 

[email  protected] bin]# tail -f ../logs/catalina.out 19-Jun-2018 15:57:06.666 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 19-Jun-2018 15:57:06.667 INFO [main] org.apache.tomcat.util.net.NioselectorPool.getSharedSelector Using a shared selector for servlet write/read 19-Jun-2018 15:57:06.667 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 535 ms 19-Jun-2018 15:57:06.684 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 19-Jun-2018 15:57:06.684 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.1.15 19-Jun-2018 15:57:06.690 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/apache-tomcat-8.1.15-server/webapps/ROOT

 
卡在这个启动状态至少由10分钟才能完全启动起来,而且每次都这样。。。空跑都能这么操蛋?部署个项目还得了?难道要半小时?
网上查阅到有个大神写的文章,大意就是下面这句话:
 
The library used for random number generation in Sun‘s JVM relies on /dev/random by default for UNIX platforms. This can potentially block the Oracle WebLogic Communication Services process because on some operating systems /dev/random waits for a certain amount of "noise" to be generated on the host machine before returning a result. Although /dev/random is more secure, Oracle recommends using /dev/urandom if the default JVM configuration delays Oracle WebLogic Communication Services startup.To determine if your operating system exhibits this behavior, try displaying a portion of the file from a shell prompt:head -n 1 /dev/random Open the $java_HOME/jre/lib/security/java.security file in a text editor.Change the line:securerandom.source=file:/dev/random to read:securerandom.source=file:/dev/urandom Save your change and exit the text editor.

 
就是linux提供随机数设备是/dev/random 和/dev/urandom,一般我们都只是都使用" /dev/random" ,这个参数做随机数(因为每本操蛋的书都是这么写的!也没人说过为啥。)
 
两个有区别,urandom安全性没有random高,但random需要时间间隔生成随机数。jdk默认调用random。
 
所以根据上面的说法,修改配置文件:
 
find / -name securerandom.source

 
找到Java.security文件,在文件中找到securerandom.source这个设置项,将其改为:
 
securerandom.source=file:/dev/urandom

【重复启动Tomcat时,大概率出现Deploying web application direct】 
修改完毕后,重启tomcat,瞬间启动完毕。

    推荐阅读