您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发

【原】Linux下tomcat启动卡住的解决方案图文教程

不忘初心 不忘初心 2019-03-02 围观() 评论() 点赞() JAVA开发

简介:之前的服务器到期了,新入手了一台云服务器,在发布工程的时候,发现tomcat卡住很久,之前的服务器没有这个问题,开始以为是项目哪里配置出错了,自己检查了没问题,在本地也是可以启动的,就是在新买的这台服务器上面超级慢,一度让我怀疑是否新买的服务器有问题,一波百度下来,发现原来这个问题可以从tomcat着手找原因。。。大家可以看到,这两行日志之间卡了将近4分钟之久,真的是不能忍,具体日志信息如下:02

之前的服务器到期了,新入手了一台云服务器,在发布工程的时候,发现tomcat卡住很久,之前的服务器没有这个问题,开始以为是项目哪里配置出错了,自己检查了没问题,在本地也是可以启动的,就是在新买的这台服务器上面超级慢,一度让我怀疑是否新买的服务器有问题,一波百度下来,发现原来这个问题可以从tomcat着手找原因。。。

Linux下tomcat启动卡住4分钟之久

大家可以看到,这两行日志之间卡了将近4分钟之久,真的是不能忍,具体日志信息如下:

02-Mar-2019 18:32:34.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.30
02-Mar-2019 18:32:34.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 1 2015 22:30:46 UTC
02-Mar-2019 18:32:34.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.30.0
02-Mar-2019 18:32:34.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-514.26.2.el7.x86_64
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/local/jdk/jre
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_112-b15
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
02-Mar-2019 18:32:34.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
02-Mar-2019 18:32:34.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
02-Mar-2019 18:32:34.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/usr/local/tomcat/endorsed
02-Mar-2019 18:32:34.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
02-Mar-2019 18:32:34.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
02-Mar-2019 18:32:34.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
02-Mar-2019 18:32:34.160 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
02-Mar-2019 18:32:34.543 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
02-Mar-2019 18:32:34.569 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
02-Mar-2019 18:32:34.583 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
02-Mar-2019 18:32:34.585 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
02-Mar-2019 18:32:34.589 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1271 ms
02-Mar-2019 18:32:34.626 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
02-Mar-2019 18:32:34.626 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.30
02-Mar-2019 18:32:38.844 INFO [localhost-startStop-1] 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.
02-Mar-2019 18:34:02.990 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [77,044] milliseconds.
02-Mar-2019 18:34:06.508 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
02-Mar-2019 18:34:06.747 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 239 ms
02-Mar-2019 18:34:06.747 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
02-Mar-2019 18:34:06.839 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 91 ms
02-Mar-2019 18:34:06.839 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
02-Mar-2019 18:34:06.862 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 23 ms
02-Mar-2019 18:34:06.862 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/jwcz
02-Mar-2019 18:34:09.749 INFO [localhost-startStop-1] 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.
02-Mar-2019 18:34:18.455 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/jwcz has finished in 11,593 ms
02-Mar-2019 18:34:18.455 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
02-Mar-2019 18:34:18.482 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 26 ms
02-Mar-2019 18:34:18.502 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
02-Mar-2019 18:34:18.507 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
02-Mar-2019 18:34:18.510 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 103920 ms

日志信息太多了,前面的刷没了,我又重新启动了一遍,这次虽然没有卡住4分钟这么长,但是也卡住了快2分钟(唯一的区别:刚才找日志时发现太多了,难找的很,日志文件竟然有2G了,所以我清空了一下日志)。

为了验证是不是因为我清除了日志影响到了卡顿时间,所以我特意重启了一遍,这次又跟第一次一样卡住了很久,4分半钟

02-Mar-2019 18:37:26.869 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.30
02-Mar-2019 18:37:31.061 INFO [localhost-startStop-1] 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.
02-Mar-2019 18:41:52.152 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [254,338] milliseconds.
02-Mar-2019 18:41:55.444 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples

所以,上面的猜测可以排除了。

细看日志,发现卡住的地方就在deploy web这个位置

02-Mar-2019 18:34:02.990 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [77,044] milliseconds.
02-Mar-2019 18:34:06.508 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples

第一行虽然不是deploy web的日志,但是基本可以确定,就是在发布webapps目录中的工程时卡住了。

遂百度之,发现有大神碰见过这个问题,大概原因是启动时获取随机数时卡住了

解决方案:修改 $JAVA_HOME/jre/lib/security/java.security 文件,替换securerandom.source=file:/dev/random 为 securerandom.source=file:/dev/urandom

顺着此方案找到java.security文件,里面真的写的是file:/dev/random

Linux下tomcat启动卡住4分钟之久

修改为securerandom.source=file:/dev/urandom之后,再次重启tomcat

02-Mar-2019 18:57:54.772 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.30
02-Mar-2019 18:57:58.760 INFO [localhost-startStop-1] 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.
02-Mar-2019 18:58:09.402 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
02-Mar-2019 18:58:09.641 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 238 ms

时间已经缩短到了10秒以内,至此,问题得到解决!!!

Tips:在参考的文章中,作者说他改为了urandom之后也没有生效,需要多加一层目录(securerandom.source=file:/dev/./urandom),但是我在机器上测试的时候,直接写urandom就可以了,大家如果写urandom还没有解决,不妨也试试这种写法。

大神的文章地址:http://blog.csdn.net/queshuihaimian/article/details/78117356

tomcatlinux

看完文章,有任何疑问,请加入群聊一起交流!!!

很赞哦! ()

文章评论

  • 请先说点什么
    人参与,条评论

请使用电脑浏览器访问本页面,使用手机浏览器访问本页面会导致下载文件异常!!!

雨落无影

关注上方公众号,回复关键字【下载】获取下载码

用完即删,每次下载需重新获取下载码

若出现下载不了的情况,请及时联系站长进行解决

站点信息

  • 网站程序:spring + freemarker
  • 主题模板:《今夕何夕》
  • 文章统计:篇文章
  • 标签管理标签云
  • 微信公众号:扫描二维码,关注我们