渣渣的 ElasticSearch 源碼解析 —— 環境搭建

關注我

zhisheng

轉載請務必註明原創地址爲:http://www.54tianzhisheng.cn/2018/08/05/es-code01/java

軟件環境

一、Intellij Idea:2018.2版本node

二、Elasticsearch 源碼版本: 6.3.2git

三、JDK:10.0.2github

四、Gradle : 建議 4.5 及以上版本sql

五、Macbook Pro 2017express

安裝 ElasticSearch

https://www.elastic.co/downlo... 這裏找到 ElasticSearch 6.3.2 版本,下載後而後解壓就行了。(注意:這個版本須要和下面的源碼版本一致)apache

下載源碼

https://github.com/elastic/el... 上下載相應版本的源代碼,這裏建議用 git clone ,這樣的話後面你能夠隨意切換到 ElasticSearch 的其餘版本去。bootstrap

git clone git@github.com:elastic/elasticsearch.git

咱們看下有哪些版本的:app

git tag

找到了目前源碼版本最新的版本的穩定版爲:v6.3.2less

切換到該版本:

git checkout v6.3.2

因而就能夠切換到該穩定版本了。接下來不要直接導入到 IDEA/Eclipse 中。

編譯

GitHub 這裏已經有描述如何導入 IDEA/Eclipse 中:

JDK 10 is required to build Elasticsearch. You must have a JDK 10 installation with the environment variable JAVA_HOME referencing the path to Java home for your JDK 10 installation. By default, tests use the same runtime as JAVA_HOME. However, since Elasticsearch, supports JDK 8 the build supports compiling with JDK 10 and testing on a JDK 8 runtime; to do this, set RUNTIME_JAVA_HOME pointing to the Java home of a JDK 8 installation. Note that this mechanism can be used to test against other JDKs as well, this is not only limited to JDK 8.

Note: It is also required to have JAVA7_HOME, JAVA8_HOME and JAVA10_HOME available so that the tests can pass.

Warning: do not use sdkman for Java installations which do not have proper jrunscript for jdk distributions.

Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle using the wrapper via the gradlew script in the root of the repository.

Configuring IDEs And Running Tests
Eclipse users can automatically configure their IDE: ./gradlew eclipse then File: Import: Existing Projects into Workspace. Select the option Search for nested projects. Additionally you will want to ensure that Eclipse is using 2048m of heap by modifying eclipse.ini accordingly to avoid GC overhead errors.

IntelliJ users can automatically configure their IDE: ./gradlew idea then File->New Project From Existing Sources. Point to the root of the source directory, select Import project from external model->Gradle, enable Use auto-import. In order to run tests directly from IDEA 2017.2 and above, it is required to disable the IDEA run launcher in order to avoid idea_rt.jar causing "jar hell". This can be achieved by adding the -Didea.no.launcher=true JVM option. Alternatively, idea.no.launcher=true can be set in the idea.properties file which can be accessed under Help > Edit Custom Properties (this will require a restart of IDEA). For IDEA 2017.3 and above, in addition to the JVM option, you will need to go to Run->Edit Configurations->...->Defaults->JUnit and verify that the Shorten command line setting is set to user-local default: none. You may also need to remove ant-javafx.jar from your classpath if that is reported as a source of jar hell.

To run an instance of elasticsearch from the source code run ./gradlew run

The Elasticsearch codebase makes heavy use of Java asserts and the test runner requires that assertions be enabled within the JVM. This can be accomplished by passing the flag -ea to the JVM on startup.

For IntelliJ, go to Run->Edit Configurations...->Defaults->JUnit->VM options and input -ea.

For Eclipse, go to Preferences->Java->Installed JREs and add -ea to VM Arguments.

上面說了下如何編譯 Elasticsearch 和如何在 ide 中配置好環境。下面說下步驟吧:(這裏我只是演示在 IDEA 中如何導入)

一、在咱們下載的 Elasticsearch 根目錄下執行命令:(執行已經寫好的腳本 gradlew)

./gradlew idea

請注意版本和個人一致,早的版本可能沒有該執行腳本,須要執行 gradle idea 命令

最後結果以下:

idea-config

二、導入 IDEA

idea 中 File -> New Project From Existing Sources 選擇你下載的 Elasticsearch 根目錄,而後點 open ,以後 Import project from external model -> Gradle , 選中 Use auto-import, 而後就能夠了。

導入進去後,gradle 又會編譯一遍,須要等一會,好了以後以下:

ok

運行

打開 server 模塊下的 Elasticsearch 類:org.elasticsearch.bootstrap.Elasticsearch,運行裏面的 main 函數。

一、報錯以下:

ERROR: the system property [es.path.conf] must be set

1es-path-conf-must-be-set

咱們在運行的配置 vm options 以下:(後面啓動流程會寫爲何會報這個錯誤)

-Des.path.conf="/usr/local/elasticsearch-6.3.2/config"

2設置es-path-conf

二、再次運行,報錯以下:

Exception in thread "main" java.lang.IllegalStateException: path.home is not configured
    at org.elasticsearch.env.Environment.<init>(Environment.java:103)
    at org.elasticsearch.env.Environment.<init>(Environment.java:94)
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:86)
    at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86)

3path-home-not-config

咱們在運行的配置 vm options 以下:(後面啓動流程會寫爲何會報這個錯誤)

-Des.path.home="/usr/local/elasticsearch-6.3.2"

4配置es-path-home

三、再次運行,報錯以下:

2018-08-01 09:38:03,974 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")
    at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:371)
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1805)
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:318)
    at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)
    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)
    at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:556)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)
    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)
    at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)
    at org.elasticsearch.common.logging.LogConfigurator.configureStatusLogger(LogConfigurator.java:171)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:140)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:119)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:294)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86)

5access-denied

咱們在運行的配置 vm options 以下:

-Dlog4j2.disable.jmx=true

6log4j-disable-jmx

四、若是你用的是 JDK 1.8 編譯的應該還會報這個錯誤

[2018-08-01T11:02:24,663][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: jar hell!
class: jdk.packager.services.UserJvmOptionsService
jar1: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/lib/ant-javafx.jar
jar2: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/lib/packager.jar
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[main/:?]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[main/:?]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[main/:?]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[main/:?]
Caused by: java.lang.IllegalStateException: jar hell!
class: jdk.packager.services.UserJvmOptionsService
jar1: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/lib/ant-javafx.jar
jar2: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/lib/packager.jar
    at org.elasticsearch.bootstrap.JarHell.checkClass(JarHell.java:273) ~[main/:?]
    at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:190) ~[main/:?]
    at org.elasticsearch.bootstrap.JarHell.checkJarHell(JarHell.java:86) ~[main/:?]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:198) ~[main/:?]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[main/:?]
    ... 6 more
2018-08-01 11:02:24,713 Thread-2 ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

8jar-hell

有兩個解決方法就是,

(1)、把源碼中有關使用了 JarHell.checkJarHell 代碼的地方所有註釋掉就行了

(2)、換成 JDK 10 編譯

兩種方法我都試了是可行的,建議直接換第二種方案吧!

五、而後再啓動的話,應該沒問題了,出現下面日誌:(網上不少人在這步就行了)

[elasticsearch] Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[elasticsearch] [2018-08-04T16:42:26,073][INFO ][o.e.n.Node               ] [node-0] initializing ...
[elasticsearch] [2018-08-04T16:42:26,185][INFO ][o.e.e.NodeEnvironment    ] [node-0] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [109.3gb], net total_space [233.4gb], types [apfs]
[elasticsearch] [2018-08-04T16:42:26,187][INFO ][o.e.e.NodeEnvironment    ] [node-0] heap size [494.9mb], compressed ordinary object pointers [true]
[elasticsearch] [2018-08-04T16:42:26,190][INFO ][o.e.n.Node               ] [node-0] node name [node-0], node ID [o9SuMXP-R7uvJLtE3h37Rw]
[elasticsearch] [2018-08-04T16:42:26,191][INFO ][o.e.n.Node               ] [node-0] version[6.3.2-SNAPSHOT], pid[61499], build[default/zip/053779d/2018-08-04T08:39:59.714654Z], OS[Mac OS X/10.13.5/x86_64], JVM["Oracle Corporation"/Java HotSpot(TM) 64-Bit Server VM/10.0.2/10.0.2+13]
[elasticsearch] [2018-08-04T16:42:26,191][INFO ][o.e.n.Node               ] [node-0] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/var/folders/mb/3vpbvkkx13l2jmpt2kmmt0fr0000gn/T/elasticsearch.URRKTybG, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -XX:UseAVX=2, -ea, -esa, -Xms512m, -Xmx512m, -Des.path.home=/Users/zhisheng/IdeaProjects/github/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.3.2-SNAPSHOT, -Des.path.conf=/Users/zhisheng/IdeaProjects/github/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.3.2-SNAPSHOT/config, -Des.distribution.flavor=default, -Des.distribution.type=zip]
[elasticsearch] [2018-08-04T16:42:26,191][WARN ][o.e.n.Node               ] [node-0] version [6.3.2-SNAPSHOT] is a pre-release version of Elasticsearch and is not suitable for production
[elasticsearch] [2018-08-04T16:42:28,808][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [aggs-matrix-stats]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [analysis-common]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [ingest-common]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [lang-expression]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [lang-mustache]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [lang-painless]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [mapper-extras]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [parent-join]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [percolator]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [rank-eval]
[elasticsearch] [2018-08-04T16:42:28,809][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [reindex]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [repository-url]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [transport-netty4]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [tribe]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-core]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-deprecation]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-graph]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-logstash]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-ml]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-monitoring]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-rollup]
[elasticsearch] [2018-08-04T16:42:28,810][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-security]
[elasticsearch] [2018-08-04T16:42:28,811][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-sql]
[elasticsearch] [2018-08-04T16:42:28,811][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-upgrade]
[elasticsearch] [2018-08-04T16:42:28,811][INFO ][o.e.p.PluginsService     ] [node-0] loaded module [x-pack-watcher]
[elasticsearch] [2018-08-04T16:42:28,811][INFO ][o.e.p.PluginsService     ] [node-0] no plugins loaded
[elasticsearch] [2018-08-04T16:42:32,722][INFO ][o.e.x.s.a.s.FileRolesStore] [node-0] parsed [0] roles from file [/Users/zhisheng/IdeaProjects/github/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.3.2-SNAPSHOT/config/roles.yml]
[elasticsearch] [2018-08-04T16:42:33,358][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/61517] [Main.cc@109] controller (64 bit): Version 6.3.2-SNAPSHOT (Build 903094f295d249) Copyright (c) 2018 Elasticsearch BV
[elasticsearch] [2018-08-04T16:42:33,783][DEBUG][o.e.a.ActionModule       ] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[elasticsearch] [2018-08-04T16:42:34,110][INFO ][o.e.d.DiscoveryModule    ] [node-0] using discovery type [zen]
[elasticsearch] [2018-08-04T16:42:34,971][INFO ][o.e.n.Node               ] [node-0] initialized
[elasticsearch] [2018-08-04T16:42:34,971][INFO ][o.e.n.Node               ] [node-0] starting ...
[elasticsearch] [2018-08-04T16:42:35,217][INFO ][o.e.t.TransportService   ] [node-0] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[elasticsearch] [2018-08-04T16:42:38,291][INFO ][o.e.c.s.MasterService    ] [node-0] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: new_master {node-0}{o9SuMXP-R7uvJLtE3h37Rw}{xjoT1zvpRsm1ZDGLCab1sA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=17179869184, xpack.installed=true, testattr=test, ml.max_open_jobs=20, ml.enabled=true}
[elasticsearch] [2018-08-04T16:42:38,295][INFO ][o.e.c.s.ClusterApplierService] [node-0] new_master {node-0}{o9SuMXP-R7uvJLtE3h37Rw}{xjoT1zvpRsm1ZDGLCab1sA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=17179869184, xpack.installed=true, testattr=test, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {node-0}{o9SuMXP-R7uvJLtE3h37Rw}{xjoT1zvpRsm1ZDGLCab1sA}{127.0.0.1}{127.0.0.1:9300}{ml.machine_memory=17179869184, xpack.installed=true, testattr=test, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]])
[elasticsearch] [2018-08-04T16:42:38,317][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [node-0] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[elasticsearch] [2018-08-04T16:42:38,319][INFO ][o.e.n.Node               ] [node-0] started
[elasticsearch] [2018-08-04T16:42:38,358][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [node-0] Failed to clear cache for realms [[]]
[elasticsearch] [2018-08-04T16:42:38,413][INFO ][o.e.g.GatewayService     ] [node-0] recovered [0] indices into cluster_state
[elasticsearch] [2018-08-04T16:42:38,597][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.watch-history-7] for index patterns [.watcher-history-7*]
[elasticsearch] [2018-08-04T16:42:38,660][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.watches] for index patterns [.watches*]
[elasticsearch] [2018-08-04T16:42:38,707][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.triggered_watches] for index patterns [.triggered_watches*]
[elasticsearch] [2018-08-04T16:42:38,771][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.monitoring-logstash] for index patterns [.monitoring-logstash-6-*]
[elasticsearch] [2018-08-04T16:42:38,836][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.monitoring-es] for index patterns [.monitoring-es-6-*]
[elasticsearch] [2018-08-04T16:42:38,878][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.monitoring-alerts] for index patterns [.monitoring-alerts-6]
[elasticsearch] [2018-08-04T16:42:38,926][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.monitoring-beats] for index patterns [.monitoring-beats-6-*]
[elasticsearch] [2018-08-04T16:42:38,970][INFO ][o.e.c.m.MetaDataIndexTemplateService] [node-0] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-6-*]
[elasticsearch] [2018-08-04T16:42:39,055][INFO ][o.e.l.LicenseService     ] [node-0] license [79704513-d3c4-4535-8276-beeb146765de] mode [basic] - valid

六、可是我出現了下面這個問題,一直困擾着我呢,我是直接跳過去的。

[2018-08-01T09:44:27,370][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] fatal error in thread [main], exiting
java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader
    at org.elasticsearch.plugins.PluginsService.loadBundle(PluginsService.java:632) ~[main/:?]
    at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:557) ~[main/:?]
    at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:162) ~[main/:?]
    at org.elasticsearch.node.Node.<init>(Node.java:311) ~[main/:?]
    at org.elasticsearch.node.Node.<init>(Node.java:252) ~[main/:?]
    at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[main/:?]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[main/:?]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[main/:?]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[main/:?]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[main/:?]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[main/:?]
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.plugins.ExtendedPluginsClassLoader
    at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ~[?:?]
    at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) ~[?:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[?:?]
    ... 15 more

7noclassDefFoundError

遇到的這個問題,我在 GitHub 求助信息以下:

https://github.com/elastic/el...

可是並無解決個人問題,這裏暫時先記錄下來!我本身也跟了下源碼,定位到錯誤信息是怎麼產生的,可是沒有解決方案!

後面寫了篇文章:教你如何在 IDEA 遠程 Debug ElasticSearch

或許能夠幫你解決上面問題帶給你的困擾!

更新

後面有一個讀者提醒了我一下,他本身也遇到這個問題,而後他的解決方案挺好的,完美解決個人問題。這裏作個記錄:

解決方法: 打開 IDEA Edit Configurations ,給 Include dependencies with Provided scope 打上勾便可解決,很簡單吧!!

繼續RUN,又來一個 EXceptin:

[2018-08-23T01:13:38,551][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[main/:?]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[main/:?]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[main/:?]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[main/:?]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[main/:?]
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:?]
    at java.security.AccessController.checkPermission(AccessController.java:895) ~[?:?]
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:335) ~[?:?]
    at java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:397) ~[?:?]
...

Exception: java.security.AccessControlException thrown from the UncaughtExceptionHandler in thread "Thread-2"

第一種: 在 config 目錄下新建 java.policy 文件,填入下面內容:

grant {
    permission java.lang.RuntimePermission "createClassLoader";
};

而後在 VM options 加入 java.security.policy 的設置,指向該文件便可

-Djava.security.policy=/usr/local/elasticsearch-6.3.2/config/java.policy

第二種: 就是在 %JAVA_HOME%/conf/security 目錄下(JDK10是這個路徑,以前的版本不肯定),個人目錄是 /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/conf/security,打開 java.policy 文件,在 grant 中加入下面這句,賦予權限。

//for es 6.3.2
permission java.lang.RuntimePermission "createClassLoader";

再 RUN,此次可終於運行起來了!!!

再次感謝下讀者,他的文章地址是:[http://laijianfeng.org/2018/0...]()

總結

折騰的路上少不了各類錯誤煩擾你,學會解決問題!

相關文章

一、渣渣菜雞爲何要看 ElasticSearch 源碼?

二、渣渣菜雞的 ElasticSearch 源碼解析 —— 環境搭建

三、渣渣菜雞的 ElasticSearch 源碼解析 —— 啓動流程(上)

四、渣渣菜雞的 ElasticSearch 源碼解析 —— 啓動流程(下)

五、Elasticsearch 系列文章(一):Elasticsearch 默認分詞器和中分分詞器之間的比較及使用方法

六、Elasticsearch 系列文章(二):全文搜索引擎 Elasticsearch 集羣搭建入門教程

七、Elasticsearch 系列文章(三):ElasticSearch 集羣監控

八、Elasticsearch 系列文章(四):ElasticSearch 單個節點監控

九、Elasticsearch 系列文章(五):ELK 實時日誌分析平臺環境搭建

十、教你如何在 IDEA 遠程 Debug ElasticSearch

相關文章
相關標籤/搜索