ES源码之路(一):源码本地编译启动

ES源码之路(一):源码本地编译启动

先来一段客套话,介绍一下ES:

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。

现在就开始介绍ES的源码本地编译和启动,为后面的源码分析做准备:

一、下载ES,本次选用版本elasticsearch6.1.2

ES的编译需要gradle,6.1.2版本的ES需要gradle 3.3以上不要太高如5.6

gradle不作特别说明,搜一下一大把。

在%user%/.gradle/ini.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://repo1.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
        }
    }
}

进入到下载的elasticsearch6.1.2目录,gradle elasticsearch,开始下载一些东西

 Task :buildSrc:compileGroovy FAILED

失败的话多试几次就ok了

二、gradle相关问题

进入IDEA buildSrc目录下的build.gradle,右键import gradle project,如果报错

A problem occurred evaluating project ':benchmarks'.
> Failed to apply plugin [id 'elasticsearch.build']
   > JAVA_HOME must be set to build Elasticsearch

进入到elasticsearch-6.1.2\buildSrc\src\main\groovy\org\elasticsearch\gradle\BuildPlugin.groovy目录

代码173行

String javaHome = System.getenv('JAVA_HOME')

改成自己设置的目录

String javaHome = "D:\\soft\\Java\\jdk1.8.0_202";

再次尝试报错

A problem occurred evaluating project ':benchmarks'.
> Failed to apply plugin [id 'elasticsearch.build']
   > Gradle 4.3 or above is required to build elasticsearch

下载gradle4.4重新开始

将distribution目录下的build.gradle中的maven url改成阿里云的

buildscript {
  repositories {
    maven {
      url "http://maven.aliyun.com/nexus/content/groups/public/"
    }
  }
  dependencies {
    classpath 'com.netflix.nebula:gradle-ospackage-plugin:3.4.0'
  }
}

编译,ES目录下执行./gradlew assemble

ES源码之路(一):源码本地编译启动

ES源码之路(一):源码本地编译启动
编译成功

elasticsearch-6.1.2\distribution\zip\build\distributions目录下是编译好的项目

三、运行

本地运行需要指定ES源码的主类

ES源码之路(一):源码本地编译启动

org.elasticsearch.bootstrap.Elasticsearch

运行报错

path.home is not configured
vm option添加
-Des.path.home=D:\workspace\elasticsearch-6.1.2\distribution\zip\build\distributions\elasticsearch-6.1.2 -Des.path.conf=D:\workspace\elasticsearch-6.1.2\distribution\zip\build\distributions\elasticsearch-6.1.2\config 

ES源码之路(一):源码本地编译启动

运行继续报错:

Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "registe
添加  
-Dlog4j2.disable.jmx=true

运行,显示启动成功:

ES源码之路(一):源码本地编译启动

ES源码之路(一):源码本地编译启动

磁盘的可用空间不足,es也会报错

[2019-10-28T10:44:25,144][WARN ][o.e.c.r.a.DiskThresholdMonitor] [gX-XS76] high disk watermark [90%] exceeded on [gX-XS76eQ_qEWQUFNZKFLA][gX-XS76][D:\workspace\elasticsearch-6.1.2\distribution\zip\build\distributions\elasticsearch-6.1.2\data\nodes\0] free: 8.3gb[6%], shards will be relocated away from this node
[2019-10-28T10:44:25,144][INFO ][o.e.c.r.a.DiskThresholdMonitor] [gX-XS76] rerouting shards: [high disk watermark exceeded on one or more nodes]
[2019-10-28T10:44:55,149][WARN ][o.e.c.r.a.DiskThresholdMonitor] [gX-XS76] high disk watermark [90%] exceeded on [gX-XS76eQ_qEWQUFNZKFLA][gX-XS76][D:\workspace\elasticsearch-6.1.2\distribution\zip\build\distributions\elasticsearch-6.1.2\data\nodes\0] free: 8.3gb[6%], shards will be relocated away from this node
[2019-10-28T10:45:25,151][WARN ][o.e.c.r.a.DiskThresholdMonitor] [gX-XS76] high disk watermark [90%] exceeded on [gX-XS76eQ_qEWQUFNZKFLA][gX-XS76][D:\workspace\elasticsearch-6.1.2\distribution\zip\build\distributions\elasticsearch-6.1.2\data\nodes\0] free: 8.3gb[6%], shards will be relocated away from this node
[2019-10-28T10:45:25,151][INFO ][o.e.c.r.a.DiskThresholdMonitor] [gX-XS76] rerouting shards: [high disk watermark exceeded on one or more nodes]
......

第一阶段完成

上一篇:Linux 下部署tomcat


下一篇:BZOJ-3143/洛谷3232 游走(HNOI2013)概率DP