{"id":6759,"date":"2017-06-03T18:25:20","date_gmt":"2017-06-03T10:25:20","guid":{"rendered":"http:\/\/rmohan.com\/?p=6759"},"modified":"2017-06-03T18:25:20","modified_gmt":"2017-06-03T10:25:20","slug":"tomcat-starts-with-slow-optimization-methods","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6759","title":{"rendered":"Tomcat starts with slow optimization methods"},"content":{"rendered":"<p><strong>Tomcat starts with slow optimization methods<\/strong><br \/>\nTomcat started today and found that the start is very slow, take a few minutes, the problem worthy of attention, so go to view the log, found that time is caused by a random number caused by the problem. Tomcat Session ID calculated by SHA1 algorithm, the time to calculate Session ID must have a secret key, in order to improve the security Tomcat at startup time through the random number generated secret key.<\/p>\n<p>First, the environment introduced<\/p>\n<p>System version: CentOS 7.2<br \/>\nSoftware version: Tomcat 8<\/p>\n<p>Second, the log analysis, troubleshooting reasons are as follows:<\/p>\n<p>4-Mayr-2017 8:07:49 .623 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandominstance for session ID generation using [SHA1PRNG] took [55,507] milliseconds.<br \/>\n4- Mayr-2017 8:07:49 .653 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectoryDeployment of web application directory \/ application \/ apache-tomcat-8.0.27 \/ webapps \/ ROOT has finished In 165,935 ms<\/p>\n<p>The main reason:<br \/>\nis generated by the random number of the key when the card stuck, causing Tomcat to start slow or failure.<br \/>\n# Affect the strength of the random number is generated with the entropy, the specific meaning of their own daughters check, not here to elaborate.<\/p>\n<p>To see if there is enough entropy to generate a random number, you can use the<br \/>\nfollowing command to see [root @ qiuyuetao tools] # cat \/proc\/sys\/kernel\/random\/entropy_avail<br \/>\n7<\/p>\n<p>In order to speed up \/dev\/random to provide the speed of random numbers, you can operate the device peripherals,<br \/>\n let it produce a lot of interrupt (such as network transmission data,<br \/>\n press the button, move the mouse, at the command line to knock on several different commands, commonly known as poly Gas<br \/>\n cat \/dev\/random ## can consume energy<\/p>\n<p>Third,<br \/>\nthere are three ways to deal with and optimize the solution;<br \/>\nMethod 1: Use rngd software to increase the entropy pool *****<br \/>\nRecommended to use grep rdrand \/proc\/cpuinfo # Need cpu support<br \/>\nyum install rng-tools # Install rngd service (entropy service , Increase the entropy pool)<br \/>\nsystemctl start rngd # start the service<\/p>\n<p>Method 2: java<br \/>\nenvironment to modify the configuration file vim $JAVA_HOME\/jre\/lib\/security\/java.security<br \/>\nsecurerandom.source = file: \/dev\/random<br \/>\nto<br \/>\nsecurerandom.source = file: \/dev\/urandom<\/p>\n<p>Method 3: You can<br \/>\nconfigure a JRE using a non-blocking Entropy Source: vim $TOMCAT_HOME\/bin\/catalina.sh<br \/>\nif [[$ JAVA_OPTS &#8220;! = * &#8211; Djava.security.egd = *]]; then<br \/>\n  JAVA_OPTS =&#8221; $ JAVA_OPTS -Djava.security.egd = file: \/dev\/urandom &#8221;<br \/>\nfi<br \/>\n## This system attribute egd said entropy collection daemon (entropy gathering daemon)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tomcat starts with slow optimization methods Tomcat started today and found that the start is very slow, take a few minutes, the problem worthy of attention, so go to view the log, found that time is caused by a random number caused by the problem. Tomcat Session ID calculated by SHA1 algorithm, the time to [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6759"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6759"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6759\/revisions"}],"predecessor-version":[{"id":6761,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6759\/revisions\/6761"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}