Tomcat 启动时间较长

Tomcat 启动时间较长

我们目前正在两台不同的服务器上部署我们的内部程序。这两台服务器均内置于 Cisco Openstack 中。操作系统为 Centos 7。

问题是,每次重新部署应用程序时,我们都需要重新启动 tomcat;关闭 tomcat 的行为符合预期。当我们启动 tomcat 时,服务器会无响应 10 多分钟。

以下是我的流程:

  1. 使用 $TomcatHome/bin/shutdown.sh 关闭 tomcat
  2. 部署两个 war 文件
  3. 使用 $TomcatHome/bin/startup.sh 启动 tomcat

如果我导航到与该网页关联的 URL,加载栏会旋转大约 10 分钟或更长时间,直到页面突然出现。

我还尝试在应用程序主页上使用 wget。我收到等待响应错误,如下所示:

[vagrant@host-10-105-5-51 Gen]$ !w wget 10.105.5.47:8080/am --2016-09-10 11:34:51-- http://10.105.5.47:8080/am Connecting to 10.105.5.47:8080... connected. HTTP request sent, awaiting response...

除了用谷歌搜索之外,我不太清楚如何解决这个问题。

我应该针对这个问题补充一些细节:

  • 我在本地虚拟机上运行 app/tomcat,它在启动脚本被调用几秒钟后启动。
  • 查看日志目录中的 catalina out 文件。似乎有一个错误,涉及短语“地址已被使用”

答案1

我发现这个问题与 SecureRandom 有关。这是我的 openstack 机器:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Running renew job for nxueo client in background 27-Sep-2016 09:25:08.992 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [632,566] milliseconds.

这是我在流浪机器上遇到的错误:

26-Sep-2016 12:31:49.714 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [26,213] milliseconds.

通过执行以下命令可以解决这个问题:

sudo echo "securerandom.source=file:/dev/urandom" >> $JAVA_HOME"/jre/lib/security/java.security";

答案2

如果没有更多信息,很难说出发生了什么,但由于您的 web 应用程序最终运行良好,我猜部署只是需要很长时间。

您是否检查过 tomcat 日志来寻找线索?

我看到的一个常见问题是,如果 Web 应用程序在部署期间需要互联网访问或解析主机名,则需要花费很长时间等待超时。

相关内容