ERROR: transport error 202: bind failed: Address already in use

今天 执行./shutdown.sh 关闭tomcat时,发生以下报错

[app@localhost bin]$ ./shutdown.sh 
Using CATALINA_BASE:   /home/app/apache-tomcat-9.0.65
Using CATALINA_HOME:   /home/app/apache-tomcat-9.0.65
Using CATALINA_TMPDIR: /home/app/apache-tomcat-9.0.65/temp
Using JRE_HOME:        /opt/jdk1.8.0_191/jre
Using CLASSPATH:       /home/app/apache-tomcat-9.0.65/bin/bootstrap.jar:/home/app/apache-tomcat-9.0.65/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
-XX:+AlwaysPreTouch -XX:AutoBoxCacheMax=20000 -XX:CMSInitiatingOccupancyFraction=75 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -XX:CompressedClassSpaceSize=528482304 -XX:ErrorFile=../logs/hs_err_%p.log -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/ -XX:InitialHeapSize=4294967296 -XX:InitialTenuringThreshold=3 -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=536870912 -XX:MaxNewSize=2147483648 -XX:MaxTenuringThreshold=3 -XX:MetaspaceSize=134217728 -XX:NewSize=2147483648 -XX:OldPLABSize=16 -XX:-OmitStackTraceInFastThrow -XX:ParGCCardsPerStrideChunk=1024 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintPromotionFailure -XX:+PrintTenuringDistribution -XX:ThreadStackSize=256 -XX:+UnlockDiagnosticVMOptions -XX:-UseBiasedLocking -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC 
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]

很好奇为何关闭服务还会报Address already ?
于是查看 shutdown.sh 脚本文件

os400=false
case "`uname`" in
OS400*) os400=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are:
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi

exec "$PRGDIR"/"$EXECUTABLE" stop "$@"

里面提到了 EXECUTABLE=catalina.sh ,再看下catalina.sh文件内容

JAVA_OPTS="-Xms4G -Xmx4G -Xmn2G -Xss256k -XX:MetaspaceSize=128m 
......
 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=50052"

在catalina.sh中发现了一个配置项,里面含有 address=50052 ,将其更改,比如改为 50053,再次执行 ./shutdown.sh ,即可成功关闭。

[app@localhost bin]$ ./shutdown.sh 
Using CATALINA_BASE:   /home/app/apache-tomcat-9.0.65
Using CATALINA_HOME:   /home/app/apache-tomcat-9.0.65
Using CATALINA_TMPDIR: /home/app/apache-tomcat-9.0.65/temp
Using JRE_HOME:        /opt/jdk1.8.0_191/jre
Using CLASSPATH:       /home/app/apache-tomcat-9.0.65/bin/bootstrap.jar:/home/app/apache-tomcat-9.0.65/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
-XX:+AlwaysPreTouch -XX:AutoBoxCacheMax=20000 -XX:CMSInitiatingOccupancyFraction=75 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -XX:CompressedClassSpaceSize=528482304 -XX:ErrorFile=../logs/hs_err_%p.log -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/ -XX:InitialHeapSize=4294967296 -XX:InitialTenuringThreshold=3 -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=536870912 -XX:MaxNewSize=2147483648 -XX:MaxTenuringThreshold=3 -XX:MetaspaceSize=134217728 -XX:NewSize=2147483648 -XX:OldPLABSize=16 -XX:-OmitStackTraceInFastThrow -XX:ParGCCardsPerStrideChunk=1024 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintPromotionFailure -XX:+PrintTenuringDistribution -XX:ThreadStackSize=256 -XX:+UnlockDiagnosticVMOptions -XX:-UseBiasedLocking -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC 
Listening for transport dt_socket at address: 50053

总结:
找到catalina.sh 中的 配置的 address ,将其改掉后重新执行即可。

你可能感兴趣的:(tomcat,apache,java)