- 找到Node.java的如下方法:
protected Node(final Environment environment, Collection<Class<? extends Plugin>> classpathPlugins) {
final List resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error
boolean success = false;
{
// use temp logger just to say we are starting. we can’t use it later on because the node name might not be set
Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(environment.settings()));
logger.info(“initializing …”);
}
在logger.info(“initializing …”);这一行代码下面增加下面这一行内容,作用是在elasticsearch启动时打印Node类实例的调用堆栈:
printTrack(logger, “Here is stack of Node instance”);
保存好再退出,接下来可以编译了;
编译构建
- 进入文件夹elasticsearch-6.1.2,执行命令./gradlew assemble即可开始编译,下载依赖会消耗大量时间,因此请耐心等待,编译过程中CPU占用略高,如下图:
- 大约10多分钟后,编译构建成功,控制台如下所示:
…
Task
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
:test:fixtures:old-elasticsearch:javadocJar
Building without git revision id.
Task :test:fixtures:old-elasticsearch:sourcesJar
Building without git revision id.
BUILD SUCCESSFUL in 11m 3s
473 actionable tasks: 473 executed
-
编译完成后,进入目录elasticsearch-6.1.2/distribution/tar/build/distributions可以见到构建成功的结果:elasticsearch-6.1.2-SNAPSHOT.tar.gz,这就是可用的elasticsearch-6.1.2;
-
构建结果文件以SNAPSHOT作为文件名后缀,如果不想要此后缀,在编译的时候改用以下命令即可:
./gradlew assemble -Dbuild.snapshot=false
验证构建的elasticsearch是否可用
-
解压elasticsearch-6.1.2-SNAPSHOT.tar.gz到一个目录下;
-
进入目录elasticsearch-6.1.2-SNAPSHOT/config,修改network.host的配置为0.0.0.0,如下图:
-
进入目录elasticsearch-6.1.2-SNAPSHOT/bin,执行./elasticsearch命令启动服务;
-
在控制台可以看到新增的代码打出的日志,将Node类的调用堆栈打印出来了,我们也借此机会了解到elasticsearch启动时的涉及到的关键类:
[2019-04-20T04:02:55,785][INFO ][o.e.n.Node ] [] initializing …
[2019-04-20T04:02:55,789][INFO ][o.e.n.Node ] [] Here is stack of Node instance
java.lang.Thread.getStackTrace() 1,559 <-
org.elasticsearch.node.Node.printTrack() 953 <-
org.elasticsearch.node.Node.() 255 <-
org.elasticsearch.node.Node.() 245 <-
org.elasticsearch.bootstrap.Bootstrap$5.() 212 <-
org.elasticsearch.bootstrap.Bootstrap.setup() 212 <-
org.elasticsearch.bootstrap.Bootstrap.init() 322 <-
org.elasticsearch.bootstrap.Elasticsearch.init() 121 <-
org.elasticsearch.bootstrap.Elasticsearch.execute() 112 <-
org.elasticsearch.cli.EnvironmentAwareCommand.execute() 86 <-
org.elasticsearch.cli.Command.mainWithoutErrorHandling() 124 <-
org.elasticsearch.cli.Command.main() 90 <-
org.elasticsearch.bootstrap.Elasticsearch.main() 92 <-
org.elasticsearch.bootstrap.Elasticsearch.main() 85
- 我的ubutnu电脑的IP地址是192.168.50.75,因此用浏览器访问此地址:http://192.168.50.75:9200 ,返回内容如下所示:
至此编译构建elasticsearch6.1.2成功,在您编译构建elasticsearch的时候,希望本文能给您提供参考;