如何在IDE中运行elasticsearch

来源:互联网 发布:linux rm -f 编辑:程序博客网 时间:2024/06/03 16:38

现在插播一篇,之前还一直没有源码跑过Elasticsearch,如果想调试Elasticsearch,或是对它做一些修改,那么就需要在IDE中将之在本地跑起来,不像直接下载的包,对于源码的运行还需要一些额外的注意。

本人是不习惯用Eclipse的,一直使用的是Intelli IDEA,对于使用Eclipse的同学,大家是可以类比的。那我们就直接从源码的main函数开始来运行,main的位置其实我已经在elasticsearch源码分析之启动过程一文中说过了。

第一次运行:

Exception in thread "main" java.lang.IllegalStateException: path.home is not configuredat org.elasticsearch.env.Environment.<init>(Environment.java:99)at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:82)at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:107)at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:100)at org.elasticsearch.bootstrap.BootstrapCLIParser.<init>(BootstrapCLIParser.java:48)at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:227)at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

可以看到是path.home没有配置,其实不只是path.home没有配置了,还有一些其他的关于JVM的配置也需要,在IDE的VM option中一并增加如下配置:

-Xms1g-Xmx1g-Djava.awt.headless=true-XX:+UseParNewGC-XX:+UseConcMarkSweepGC-XX:CMSInitiatingOccupancyFraction=75-XX:+UseCMSInitiatingOccupancyOnly-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=logs/heapdump.hprof-ea-Delasticsearch-Des.foreground=yes-Des.path.home=D:\coding\opensource\elasticsearch\core-Des.security.manager.enabled=false-Des.http.cors.enabled=true-Des.http.cors.allow-origin=*

第二次运行:

ERROR: command not specifiedNAME    elasticsearch - Manages elasticsearchSYNOPSIS    elasticsearch <command>DESCRIPTION    Start an elasticsearch nodeCOMMANDS    start      Start elasticsearch    version    Show version information and exitNOTES    [*] For usage help on specific commands please type "elasticsearch <command> -h"

提示很明显,在Program arguments中添加start即可。

第三次运行:

log4j:WARN No appenders could be found for logger (bootstrap).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

没有报错了,只有log4j没有配置的warn了。 打开浏览器看一下吧:

OK,搞定,但是配置都还是默认的,而且日志也还打不出来,所以还得将配置文件增加一下,配置文件的位置在home.path下的config文件夹中包含elasticsearch.yml和logging.yml,将ES官网下载的这两文件拷过去,并修改相应配置即可。

第四次运行:

[2015-12-06 23:22:07,567][WARN ][bootstrap                ] unable to install syscall filter: syscall filtering not supported for OS: 'Windows 7'[2015-12-06 23:22:07,883][INFO ][node                     ] [idea] version[2.1.0-SNAPSHOT], pid[28296], build[${build/NA][2015-12-06 23:22:07,883][INFO ][node                     ] [idea] initializing ...[2015-12-06 23:22:07,886][INFO ][plugins                  ] [idea] loaded [], sites [][2015-12-06 23:22:07,904][INFO ][env                      ] [idea] using [1] data paths, mounts [[(D:)]], net usable_space [6.1gb], net total_space [19.9gb], spins? [unknown], types [NTFS][2015-12-06 23:22:09,150][INFO ][node                     ] [idea] initialized[2015-12-06 23:22:09,150][INFO ][node                     ] [idea] starting ...[2015-12-06 23:22:09,339][INFO ][transport                ] [idea] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}, {[::1]:9300}[2015-12-06 23:22:09,349][INFO ][discovery                ] [idea] jasper/2qSAldpEQ8eFEj5aWfKXoQ[2015-12-06 23:22:13,385][INFO ][cluster.service          ] [idea] new_master {idea}{2qSAldpEQ8eFEj5aWfKXoQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)[2015-12-06 23:22:13,417][INFO ][gateway                  ] [idea] recovered [0] indices into cluster_state[2015-12-06 23:22:13,465][INFO ][http                     ] [idea] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}, {[::1]:9200}[2015-12-06 23:22:13,466][INFO ][node                     ] [idea] started

终于日志也打印正常了,那我们再来浏览器访问一下:

可以看到,node name和cluster name也都和我配置的一致了,看一下status:

也是一切正常,那再来插入一笔数据试试:

PUT http://127.0.0.1:9200/test/test/1{    "name": "jasper",    “age”: 24}

再来查询一把试试:

看来也是一切正常!!!

既然如此,那么后面如果要调试或是修改(额,这个感觉很有难度的呀),就会方便很多了。


转载请注明出处:http://www.opscoder.info/es_ide_run.html

原创粉丝点击