0
点赞
收藏
分享

微信扫一扫

解决tomcat关机问题和启动慢问题

女侠展昭 2021-09-28 阅读 73

shutdown.sh -force保证tomcat完全关闭

  • tomcat的catalina.sh中说明了如果想要加什么参数,不要修改catalina.sh,在CATALINA_BASE/bin创建一个setenv.sh,并设置CATALINA_OPTS
  • JAVA_OPTS中的参数在关闭tomcat的时候也会参与,大部分的参数应该放到CATALINA_OPTS中。CATALINA_OPTS只在tomcat启动中参与。
  • CATALINA_PID中会存放tomcat启动后的pid。
  • 使用shutdown.sh的时候添加-force参数,如果5s后tomcat还存活会使用kill命令杀掉,还可以通过-n制定等待秒数,kill的进程号需要CATALINA_PID参数
  • catalina.sh中和本文有关的内容如下
#   Do not set the variables in this script. Instead put them into a script
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#   JAVA_OPTS       (Optional) Java runtime options used when any command
#                   is executed.
#                   Most options should go into CATALINA_OPTS.
#   CATALINA_PID    (Optional) Path of the file which should contains the pid
#                   of the catalina startup java process, when start (fork) is
#                   used
echo "  stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running"
echo "  stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if still running"
echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined"
  • 创建如下内容的setenv.sh
#!/bin/sh
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:9000 -Djava.security.egd=file:/dev/urandom"
CATALINA_PID=$CATALINA_HOME/bin/tomcat.pid

解决tomcat启动超慢的问题

  • tomcat启动慢的罪魁祸首是启动时实例化一个SecureRandom实例特别慢,catalina.out中日志如下:

Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took **[1,718,769] milliseconds.**

  • 构造SecureRandom实例会使用系统的/dev/random生成随机数,但是/dev/random依赖系统中断,所以随机数更加随机但是产生的可能会很慢
  • 所以我们使用/dev/urandom代替/dev/random就可以了,这两个随机数生成器的区别网上一堆,这里不贴了
  • 有两种解决办法
    1. 在tomcat启动参数中指定Djava.security.egd=file:/dev/urandom(和上面)
    2. 修改/usr/java/default/jre/lib/security/java.security中指定securerandom.source=file:/dev/urandom
举报

相关推荐

0 条评论