【Elasticsearch】之 编译源码

挑选对应版本, 从release中选择:https://github.com/elastic/elasticsearch/releases

Elasticsearch 版本:6.1.2
环境准备:Java 8

零、国内镜像加速

  1. 修改配置(可不修改)
$ cd elasticsearch-6.1.2/benchmarks
$ vim build.gradle 

buildscript {
    repositories {
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
    }
}
  1. 修改配置(可不修改)
$ cd elasticsearch-6.1.2/client/benchmark/
$ vim build.gradle

buildscript {
    repositories {
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
    }
}
  1. 更改全局Maven配置
$ cd ~/.gradle
$ touch init.gradle

# 增加下文

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all {
            ArtifactRepository repo ->
    if (repo instanceof MavenArtifactRepository) {
                def url = repo.url.toString()
                if (url.startsWith('https://repo.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}

一、编译、导入IDEA

  1. 执行编译
$ cd elasticsearch-6.1.2
$ ./gradlew assemble

# 编译成功,会显示如下
BUILD SUCCESSFUL in 4m 48s
  1. elasticsearch编译为 idea 工程
$ cd elasticsearch-6.1.2
$ ./gradlew idea

# 成功会显示如下:
BUILD SUCCESSFUL in 1m 43s
  1. 打开IDEA,导入此项目

二、本地运行

IDEA菜单中选择Run -> Edit Configurations

点击 + ,选择 Application

【Elasticsearch】之 编译源码_第1张图片

VM options中增加如下:

-Des.path.home=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome -Des.path.conf=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome/config -Xms1g -Xmx1g -Dlog4j2.disable.jmx=true -Djava.security.policy=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome/config/elasticsearch.policy

distribution 下的 src/config

grant {

    permission javax.management.MBeanTruxtPermission "register";
    permission javax.management.MBeanServerPermission "createMBeanServer";
    permission java.lang.RuntimePermission "createClassLoader";
};
[2020-06-14T14:10:11,160][INFO ][o.e.n.Node               ] [] initializing ...
[2020-06-14T14:10:11,238][INFO ][o.e.e.NodeEnvironment    ] [apVPSbl] using [1] data paths, mounts [[/ (/dev/nvme0n1p2)]], net usable_space [150.5gb], net total_space [233.2gb], types [ext4]
[2020-06-14T14:10:11,239][INFO ][o.e.e.NodeEnvironment    ] [apVPSbl] heap size [981.5mb], compressed ordinary object pointers [true]
[2020-06-14T14:10:11,240][INFO ][o.e.n.Node               ] node name [apVPSbl] derived from node ID [apVPSblPRoCNe-jxN4uBdg]; set [node.name] to override
[2020-06-14T14:10:11,240][INFO ][o.e.n.Node               ] version[6.1.2-SNAPSHOT], pid[5916], build[Unknown/Unknown], OS[Linux/4.15.0-50-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_162/25.162-b12]
[2020-06-14T14:10:11,240][INFO ][o.e.n.Node               ] JVM arguments [-Des.path.home=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome, -Des.path.conf=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome/config, -Xms1g, -Xmx1g, -Dlog4j2.disable.jmx=true, -Djava.security.policy=/home/donald/Documents/Code/Source/elasticsearch-6.1.2/eshome/config/elasticsearch.policy, -javaagent:/software/Tools/IDE/IDEA/lib/idea_rt.jar=38911:/software/Tools/IDE/IDEA/bin, -Dfile.encoding=UTF-8]
[2020-06-14T14:10:11,240][WARN ][o.e.n.Node               ] version [6.1.2-SNAPSHOT] is a pre-release version of Elasticsearch and is not suitable for production
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [aggs-matrix-stats]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [analysis-common]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [ingest-common]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [lang-expression]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [lang-mustache]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [lang-painless]
[2020-06-14T14:10:13,874][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [mapper-extras]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [parent-join]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [percolator]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [reindex]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [repository-url]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [transport-netty4]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] loaded module [tribe]
[2020-06-14T14:10:13,875][INFO ][o.e.p.PluginsService     ] [apVPSbl] no plugins loaded
[2020-06-14T14:10:13,981][INFO ][i.n.u.i.PlatformDependent] Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability.
[2020-06-14T14:10:15,210][INFO ][o.e.d.DiscoveryModule    ] [apVPSbl] using discovery type [zen]
[2020-06-14T14:10:15,606][INFO ][o.e.n.Node               ] initialized
[2020-06-14T14:10:15,606][INFO ][o.e.n.Node               ] [apVPSbl] starting ...
[2020-06-14T14:10:15,723][INFO ][o.e.t.TransportService   ] [apVPSbl] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2020-06-14T14:10:15,730][WARN ][o.e.b.BootstrapChecks    ] [apVPSbl] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-06-14T14:10:18,790][INFO ][o.e.c.s.MasterService    ] [apVPSbl] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {apVPSbl}{apVPSblPRoCNe-jxN4uBdg}{ahl6fjbOSeWwUYLnokoS7g}{127.0.0.1}{127.0.0.1:9300}
[2020-06-14T14:10:18,794][INFO ][o.e.c.s.ClusterApplierService] [apVPSbl] new_master {apVPSbl}{apVPSblPRoCNe-jxN4uBdg}{ahl6fjbOSeWwUYLnokoS7g}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {apVPSbl}{apVPSblPRoCNe-jxN4uBdg}{ahl6fjbOSeWwUYLnokoS7g}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2020-06-14T14:10:18,808][INFO ][o.e.h.n.Netty4HttpServerTransport] [apVPSbl] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2020-06-14T14:10:18,808][INFO ][o.e.n.Node               ] [apVPSbl] started

二、远程调试

除了在本地环境调试ES,有时还需要远程调试某个节点。

分布式系统总会遇到很多千奇百怪的问题,很多时候问题无法复现,或者某种问题只出现在特定环境中。

  1. 配置RUN -> Edit Configurations

【Elasticsearch】之 编译源码_第2张图片

三、代码书签和断点组

添加:Navigate -> Bookmarks -> Toggle Bookmark

你可能感兴趣的:(【Elasticsearch】)