OS信息:
Linux rel65 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Tomcat版本信息:
apache-tomcat-8.5.34
JDK版本信息:
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
执行startup.sh脚本启动tomcat服务时正常,但是使用相同用户执行shutdown.sh脚本关闭tomcat服务时报错,错误信息
ERROR: transport error 202: bind failed
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
将tomcat/bin/catalina.sh中的JAVA_OPTS去除远程调试用的-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005,并增加到属性CATALINA_OPTS中。
这里需要看下JAVA_OPTS和CATALINA_OPTS在catalina.sh脚本中的作用。
先查看下备注:
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.
由注释信息可知, CATALINA_OPTS属性里面的参数只会在start,run和debug时被执行调用,而JAVA_OPTS在执行任何命令时均会被调用。
因此当启动时,两个属性里面的参数均会被调用,所以原先远程调试的参数均有效。但是当调用关闭服务命令时,JAVA_OPTS的参数会被再次调用,但此时端口号已经被占用,所以会报端口占用的错误。而CATALINA_OPTS则不会有影响。
所以如注释所说,大部分参数应当放到CATALINA_OPTS中。