当前位置:   article > 正文

elasticsearch 远程调试_elasticsearch 远程debug

elasticsearch 远程debug

一.准备

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 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

添加 java 远程调试代码在这里

    -agentlib:jdwp=transport=dt_socket,server=y,address=8888,suspend=y 
  • 1

添加结束

    -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 $?
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

注意这3行

# 添加  java 远程调试代码在这里 
    -agentlib:jdwp=transport=dt_socket,server=y,address=8888,suspend=y 
  • 1
  • 2

添加结束

然后在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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/949274
推荐阅读
相关标签
  

闽ICP备14008679号