Mac 查看 ElasticSearch 源码

非常简单的查看 ES 源码的方法。注意,该方法只能查看源码,不能修改源码。

1. Mac ElasticSearch 安装

brew install ElasticSearch

我的ES安装地址:/usr/local/Cellar/elasticsearch/6.8.5

2. 修改jvm 参数

修改 /usr/local/Cellar/elasticsearch/6.8.5/libexec/config/jvm.options 中 jvm 参数,增加以下内容:

 -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

这个5005就是监听端口。

3. 启动 ElasticSearch

./bin/elasticsearch

启动日志中看到: Listening for transport dt_socket at address: 5005

访问:http://127.0.0.1:9200/_cat/health,显示 ES 健康信息。

4. 工程中引入 ElasticSearch 源代码

我用的 gradle,注意版本要与安装的 ES 版本一致

    compile group: 'org.elasticsearch', name: 'elasticsearch', version: '6.8.5'
    compile group: 'org.elasticsearch.client', name: 'transport', version: '6.8.5'
    compile group: 'org.elasticsearch.plugin', name: 'transport-netty4-client', version: '6.8.5'

5. Idea 中配置 remote

Eidt Application Configuration,增加 remote,如图

6. debug

debug Application,在 ElasticSearch 代码中设置断点,跟踪。

例如访问 http://127.0.0.1:9200/_cat/health,  入口 RestHealthAction.java 

访问 _search 端口,入口 RestSearchAction.java

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章