Elasticsearch源码编译运行

来源:互联网 发布:支付宝和淘宝什么关系 编辑:程序博客网 时间:2024/06/16 13:59

下载源码

从https://github.com/elastic/elasticsearch上下载相应版本的源代码,本人下载的是5.4.2版本的源代码

获取相关依赖

Elasticsearch在5.4版本是采用gradle来管理的,进入源码的根目录,因为我用的是idea编译器,因此执行:

gradle idea

然后进入漫长的下载相关依赖包的过程

如果觉得国外的镜像下载速度过慢,可以采用国内的镜像,在根目录的build.gradle文件中的allprojects内添加阿里云的镜像:

allprojects {  repositories {      maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }  }}

导入idea

在Idea中导入Elasticsearch源码,入口类文件为:

core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

点击编译运行

报错处理

报错1

Exception in thread "main" java.lang.IllegalStateException: path.home is not configured...

这个错误是没有指定项目的配置目录,因为运行Elasticsearch需要相应的插件、模块以及配置文件

因此,可以在官网上下载一个相应版本的编译好的Elasticsearch(如果源码是5.4.2,就要下载版本为5.4.2的发行版),将path.home指向其解压后的根目录,如果版本不一致,运行时会出错

而要加上path.home,我们可以直接修改虚拟机的运行参数,在idea中的Run菜单下点击Edit Configurations选项,配置VM options参数为:

-Des.path.home=D:\Java\elasticsearch //elasticsearch发行版的根目录

报错2

2017-06-23 14:00:44,760 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")...

这个问题的解决方法和上面类似,修改虚拟机的运行参数,加上:

-Dlog4j2.disable.jmx=true

运行成功

[2017-06-23T15:40:14,087][INFO ][o.e.n.Node               ] [] initializing ...[2017-06-23T15:40:14,564][INFO ][o.e.e.NodeEnvironment    ] [aJnQFVO] using [1] data paths, mounts [[(D:)]], net usable_space [146.6gb], net total_space [201gb], spins? [unknown], types [NTFS][2017-06-23T15:40:14,564][INFO ][o.e.e.NodeEnvironment    ] [aJnQFVO] heap size [1.7gb], compressed ordinary object pointers [true][2017-06-23T15:40:14,567][INFO ][o.e.n.Node               ] node name [aJnQFVO] derived from node ID [aJnQFVObS3GX_Z7B7l-BUg]; set [node.name] to override[2017-06-23T15:40:14,567][INFO ][o.e.n.Node               ] version[5.4.2-SNAPSHOT], pid[54392], build[Unknown/Unknown], OS[Windows 10/10.0/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_111/25.111-b14][2017-06-23T15:40:14,568][INFO ][o.e.n.Node               ] JVM arguments [-Des.path.home=D:\Java\elasticsearch, -Dlog4j2.disable.jmx=true, -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.3\lib\idea_rt.jar=51362:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.3\bin, -Dfile.encoding=UTF-8][2017-06-23T15:40:14,568][WARN ][o.e.n.Node               ] version [5.4.2-SNAPSHOT] is a pre-release version of Elasticsearch and is not suitable for production[2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [aggs-matrix-stats][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [ingest-common][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [lang-expression][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [lang-groovy][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [lang-mustache][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [lang-painless][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [percolator][2017-06-23T15:40:25,820][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [reindex][2017-06-23T15:40:25,821][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [transport-netty3][2017-06-23T15:40:25,821][INFO ][o.e.p.PluginsService     ] [aJnQFVO] loaded module [transport-netty4][2017-06-23T15:40:25,822][INFO ][o.e.p.PluginsService     ] [aJnQFVO] no plugins loaded[2017-06-23T15:40:29,525][INFO ][o.e.d.DiscoveryModule    ] [aJnQFVO] using discovery type [zen][2017-06-23T15:40:30,104][INFO ][o.e.n.Node               ] initialized[2017-06-23T15:40:30,104][INFO ][o.e.n.Node               ] [aJnQFVO] starting ...[2017-06-23T15:40:30,195][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.[2017-06-23T15:40:31,512][INFO ][o.e.t.TransportService   ] [aJnQFVO] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300}[2017-06-23T15:40:31,520][WARN ][o.e.b.BootstrapChecks    ] [aJnQFVO] initial heap size [134217728] not equal to maximum heap size [2126512128]; this can cause resize pauses and prevents mlockall from locking the entire heap[2017-06-23T15:40:34,620][INFO ][o.e.c.s.ClusterService   ] [aJnQFVO] new_master {aJnQFVO}{aJnQFVObS3GX_Z7B7l-BUg}{3au2Z08AQEKm4wS7CLOyuw}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)[2017-06-23T15:40:34,748][INFO ][o.e.g.GatewayService     ] [aJnQFVO] recovered [0] indices into cluster_state[2017-06-23T15:40:35,499][INFO ][o.e.h.n.Netty4HttpServerTransport] [aJnQFVO] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}[2017-06-23T15:40:35,552][INFO ][o.e.n.Node               ] [aJnQFVO] started
原创粉丝点击