赞
踩
一.准备
1. linux或windows上安装elasticsearch
2.idea导入elasticsearch 对应版本的源码
二.远程调试
说明: 我的环境是:
windows 上安装idea 导入 elasticsearch-6.4.1源码
linux 安装elasticsearch-6.4.1
1. 修改elasticsearch的启动脚本
在linux elasticsearch-6.4.1 的安装目录下
/data/elasticsearch-6.4.1/bin/
找到elasticsearch脚本
#!/bin/bash
# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
# ES_PATH_CONF -- Path to config directory
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Note that
# the Xms and Xmx lines in the JVM options file must be commented out. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
source "`dirname "$0"`"/elasticsearch-env
ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
ES_JAVA_OPTS="${JVM_OPTIONS//${ES_TMPDIR}/$ES_TMPDIR} $ES_JAVA_OPTS"
cd "$ES_HOME"
# manual parsing to find out, if process should be detached
if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
exec
"$JAVA"
$ES_JAVA_OPTS
-agentlib:jdwp=transport=dt_socket,server=y,address=8888,suspend=y
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@"
else
exec
"$JAVA"
$ES_JAVA_OPTS
-Des.path.home="$ES_HOME"
-Des.path.conf="$ES_PATH_CONF"
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR"
-Des.distribution.type="$ES_DISTRIBUTION_TYPE"
-cp "$ES_CLASSPATH"
org.elasticsearch.bootstrap.Elasticsearch
"$@"
<&- &
retval=$?
pid=$!
[ $retval -eq 0 ] || exit $retval
if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
sleep $ES_STARTUP_SLEEP_TIME
fi
if ! ps -p $pid > /dev/null ; then
exit 1
fi
exit 0
fi
exit $?
注意这3行
# 添加 java 远程调试代码在这里
-agentlib:jdwp=transport=dt_socket,server=y,address=8888,suspend=y
然后在linux上./elasticsearch 启动elasticsearch
等待远程连接中,出现这个表示成功
2.idea配置
打开idea ,打开elasticsearch-6.4.1 编译后源码(没编译的不行)
Edit Configurations
+ -> Remote
填上对应的信息,
记得要设置断点,
elasticsearch-6.4.1的入口main方法在
org.elasticsearch.bootstrap.Elasticsearch main方法中
设置断点
然后点击debug启动调试
开始调试 ok
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。