解決tomcat shutdown時的地址被佔用問題

老是在tomcat的啓動腳本catalina.sh的一開始加上dubug參數,以供遠程debug,原參數以下java

JAVA_OPTS='-XX:PermSize=728m -XX:MaxPermSize=728m -Xms1024m -Xmx1024m -DNode=DLOG4J 
-DProductMode=false -Dfile.encoding=utf-8 
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'

 

可是這樣作後,再運行tomcat的shutdown.sh腳本會報錯:web

ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initializedFATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)

之前老是懶得弄,直接killall -9 java 了事,可是如今同一臺機器上裝了不少服務,不能直接 killall了,用ps -ef | grep java去查又比較麻煩shell

因此查了一下google,獲得結果
tomcat

You are trying to debug tomcat on startup, so it binds to port 5005 when the jvm starts.jvm

When you run catalina.sh stop, it starts up another jvm which also tries to bind to port 5005.socket

You need to move the debug args to the run and start arguments (in catalina.sh) of tomcat, putting them straight into the JAVA_OPTS is the cause of the issue you're having.google

最後有一個很是簡單的解決方法:spa

CATALINA_OPTS 參數替代 JAVA_OPTS 參數 debug

把dubug參數換成:code

CATALINA_OPTS='-XX:PermSize=728m -XX:MaxPermSize=728m -Xms1024m -Xmx1024m -DNode=DLOG4J  
-DProductMode=false  -Dfile.encoding=utf-8 
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'
相關文章
相關標籤/搜索