重複啓動Tomcat時,大概率出現Deploying web application direct

由前一篇文章開始折騰supervisor,想玩玩tomcat異常退出後使用supervisor自動讓tomcat重新啓動,
隨即丟了一個tomcat在服務器裏面,本來就沒有放任何項目,空跑在那邊,只是tomcat有個界面就看看起沒起來。
 
於是手動停止tomcat的進程觸發supervisor自動拉起服務,應該是沒有問題的,但是,來來回回啓動了個兩三次,突然發現,tomcat竟然起不來了!

隨即查閱下日誌:
 

root@test-s1 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,瞬間啓動完畢。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章