作者:小寒风 | 来源:互联网 | 2023-08-28 20:03
1. 创建启动脚本app.sh
添加远程debug参数 ,远程连接端口5005;
关键参数如下:
-Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=5005
示例:
#!/bin/bash
: <java -server -Dspring.application.index=6666 -jar test-provider-1.0.0-SNAPSHOT.jar --server.port=6666 --server.context-path=/tmp --logging.file=logs/app.log
COMMENTBLOCK
export JAVA_HOME="/usr/local/java"
export PATH="${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH"
export APP_ROOT="/app/jar_9055"
export JVM_ARGS="-Xms4096m -Xmx4096m -Xmn1024m"
export JMX_ARGS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=7091"
export SYS_ARGS="-Dspring.application.index=9055 -Dconfig.entry=/usr/local/app/etc/mes-plat.properties"
export SPRING_APPLICATION_INDEX="9055"
export JAR="mes-plat.jar"
export APP_ARGS="-verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:/app/gc_log/gclog$(date +%Y%m%d-%H%M).log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/app/gc_log/"
export SERVER_PORT="9055"
export CONTEXT_PATH="/"
export LOGGING_FILE="logs/app.log"
export APP_DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=5005"
function start() {
pid=$(getpid)
if [[ -n $pid ]]; then
echo -e "Process already running (pid: $pid)"
else
echo -e "Begin starting process"
cd ${APP_ROOT} && mkdir -p logs && exec nohup ${JAVA_HOME}/bin/java -server ${JVM_ARGS} ${JMX_ARGS} ${SYS_ARGS} ${APP_DEBUG} -Dspring.application.index=${SPRING_APPLICATION_INDEX} -jar ${JAR} ${APP_ARGS} --server.port=${SERVER_PORT} --server.context-path=${CONTEXT_PATH} --logging.file=${LOGGING_FILE} >>logs/nohup.out 2>&1 &
echo -e "Start process success"
fi
}
function getpid() {
ps axu |grep java |grep "server.port=${SERVER_PORT}" |grep -v grep |awk '{print $2}'
}
2. 在idea中创建remote连接
3. 使用debug启动
如出现以上问题,说明是远程服务与本地网络不通。请检查IP地址是否准确,同时,检查远程监听服务是否开启。远程监听服务开启状态如下: