ElasticSearch调试环境搭建

本文转载自:https://blog.csdn.net/nisxiya/article/details/79110247,经过验证搭建调试环境成功

Introduction

Elasticsearch is quite a cool project. This post introduces how to setup Elasticsearch in IntelliJ Idea locally. After this, we are able to :

  • read Elasticsearch source code within an IDE
  • debug Elasticsearch
  • modify & develop new features of Elasticsearch

Solution

Step 1

clone the code from github (https://github.com/elastic/elasticsearch)

$> git clone git@github.com:elastic/elasticsearch.git
  • 1

Step 2

make sure you have IntelliJ Idea installed locally. Now let’s setup Elasticsearch project.

New a project from existing sources. 
这里写图片描述

Use Gradle as the package management tool. (ES 5.X, 6.X are using Gradle instead of Maven
这里写图片描述

Check Use auto-import. The Gradle project directory should be yours accordingly. Next click Finish
这里写图片描述

Step 3

The Elasticsearch project might contain multiple branches. The master branch requires latest version of GradleJava, etc. I checkout to 5.6 branch in my case, since my current environment looks good to 5.6 branch.

$> git checkout 5.6    #我使用的6.2分支,java 10验证通过

Have a try using the Gradle wrapper. The following will create a distribution of Elasticsearch with the source code. It could take a long time for downloading dependencies & building source codes (70 minutes on my computer).

./gradlew assemble

This generates a ES distribution locally.

Step 4

Now let’s begin to run & debug Elasticsearch source code. Directly running Elasticsearch within IntelliJ Idea is possible, but requires more extra effort. Let’s adopt Elastic's advices.

Run Elasticsearch

Set up a real Elasticsearch instance with ./gradlew run --debug-jvm

elastic@:~/Documents/elasticsearch (5.6)$ ./gradlew run --debug-jvm
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/4.3/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing

> Configure project :benchmarks 
...
Note: /Users/shun.ni/Documents/hulu/elasticsearch/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

[elasticsearch] Listening for transport dt_socket at address: 8000

> Task :distribution:run#start 
Running elasticsearch in debug mode, suspending until connected on port 8000

This instances listens to remote IDE in a certain port: 8000. Remember this port.

Debug Elasticsearch remotely

Then use IntelliJ Idea to debug this instance remotely. 
Set up Idea, click Run -> Edit Configurations. Setup a Remote Debugging. 
这里写图片描述

Click OK, then we get a new icon like this. 
这里写图片描述

Click Debug 'ES_remote', then IntelliJ Idea connects to ES
这里写图片描述

Verify the debugging

Set a breakpoint in OsInfo.java 
这里写图片描述

Access the local ES Restful API with a browser: http://localhost:9200/_nodes This should collect all nodes’ info, and it will invoke toXContent method in OsInfo.java. The program should be paused right at that line (shown in the above picture).

Also you get the response of the RESTful API like this: 
这里写图片描述

This is the start, now we are good to go. Read the source code & develop new features!

Reference

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值