java后端集群化专题

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

2018-04-03  本文已影响146人  江江的大猪

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

直接使用shutdown.sh不能完全关闭tomcat的情况,多见在tomcat中使用了线程池,并且线程不都是守护线程。一般我们手动ps找到tomcat的pid并kill,但其实tomcat自带的脚本已经有了这个功能。

#   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"

加入了远程调试功能(参数含义可以看我之前的文章),并且指定了随机数生成器(后面解释这个)。
tomcat启动时会在$CATALINA_HOME/bin下新生成tomcat.pid文件存放pid,并把pid的值赋给CATALINA_PID参数

#!/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启动超慢的问题

centos7 遇到了这个问题,每次启动tomcat的catalina.out日志中has finished in [xxx] ms。这个xxx每次都不一样,几十秒到几百秒都有可能。在StackOverflow中找到了原因

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

PS:我现在使用的是第二种方法,因为我发现公司的运维交付给我们使用的虚拟机都是这样做的

上一篇 下一篇

猜你喜欢

热点阅读