Elasticsearch 2.1.1 on localhost Java client error: MasterNotDiscoveredException[waited for [30s]]

Elasticsearch 2.1.1 on localhost Java client error: MasterNotDiscoveredException[waited for [30s]]

所以在我的本地机器上使用最新版本的 elasticsearch,java 客户端节点,没有收到任何关于主节点的信息。并断开连接。

即使使用默认配置,我也尝试了以下代码。还是不行。

如果我使用 TransportClient,一切正常。

有人知道这是怎么回事吗?

Java 客户端代码

Node node = nodeBuilder()
                .clusterName("Scrapper")
                .client(true)
                .data(false)
                .local(false)
                .settings(
                    Settings.builder()
                        .put("path.home", ".")
                        .put("name", "JG")
                        .put("http.enabled", false)
                        .put("node.master", false)
                        .put("discovery.zen.ping.multicast.enabled", false)
                        .put("discovery.zen.ping.unicast.hosts", "127.0.0.1:9300")
                        .put("network.host", "127.0.0.1")
                        .put("transport.tcp.port", "9301")
                )
                .node();
Client client = node.client();

System.out.println("Firing Requests.");

String INDEX = "test_index";
boolean indexExists = client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists();
if (!indexExists) {
  client.admin().indices().prepareCreate(INDEX).execute().actionGet();
}

SearchResponse allHits = client.prepareSearch(INDEX)
                             .addFields("title", "category")
                             .setQuery(QueryBuilders.matchAllQuery())
                             .execute().actionGet();

System.out.println("allHits = " + allHits);

Java 客户端日志:

Jan 13, 2016 12:28:50 PM org.elasticsearch.node.Node <init>
INFO: [JG] version[2.1.1], pid[33792], build[40e2c53/2015-12-15T13:05:55Z]
Jan 13, 2016 12:28:50 PM org.elasticsearch.node.Node <init>
INFO: [JG] initializing ...
Jan 13, 2016 12:28:50 PM org.elasticsearch.plugins.PluginsService <init>
INFO: [JG] loaded [], sites []
Jan 13, 2016 12:28:52 PM org.elasticsearch.node.Node <init>
INFO: [JG] initialized
Jan 13, 2016 12:28:52 PM org.elasticsearch.node.Node start
INFO: [JG] starting ...
Jan 13, 2016 12:28:52 PM org.elasticsearch.transport.TransportService doStart
INFO: [JG] publish_address {127.0.0.1:9301}, bound_addresses {127.0.0.1:9301}
Jan 13, 2016 12:28:52 PM org.elasticsearch.discovery.DiscoveryService doStart
INFO: [JG] Scrapper/5OJu376pS7Gz4HSsZV-yFA
Firing Requests.
Jan 13, 2016 12:29:22 PM org.elasticsearch.discovery.DiscoveryService waitForInitialState
WARNING: [JG] waited for 30s and no initial state was set by the discovery
Jan 13, 2016 12:29:22 PM org.elasticsearch.node.Node start
INFO: [JG] started
Exception in thread "main" MasterNotDiscoveredException[waited for [30s]]
    at org.elasticsearch.action.support.master.TransportMasterNodeAction.onTimeout(TransportMasterNodeAction.java:154)
    at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:239)
    at org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:574)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Elasticsearch 日志:

[2016-01-13 12:28:44,579][INFO ][node                     ] [MasterScrapper] version[2.1.1], pid[33773], build[40e2c53/2015-12-15T13:05:55Z]
[2016-01-13 12:28:44,579][INFO ][node                     ] [MasterScrapper] initializing ...
[2016-01-13 12:28:44,747][INFO ][plugins                  ] [MasterScrapper] loaded [license, marvel-agent], sites []
[2016-01-13 12:28:44,762][INFO ][env                      ] [MasterScrapper] using [1] data paths, mounts [[/ (/dev/disk0s2)]], net usable_space [302.5gb], net total_space [465.1gb], spins? [unknown], types [hfs]
[2016-01-13 12:28:46,023][INFO ][node                     ] [MasterScrapper] initialized
[2016-01-13 12:28:46,024][INFO ][node                     ] [MasterScrapper] starting ...
[2016-01-13 12:28:46,093][INFO ][transport                ] [MasterScrapper] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2016-01-13 12:28:46,099][INFO ][discovery                ] [MasterScrapper] Scrapper/NfXHsmWlTJ23bPz5CJ5D9w
[2016-01-13 12:28:49,115][INFO ][cluster.service          ] [MasterScrapper] new_master {MasterScrapper}{NfXHsmWlTJ23bPz5CJ5D9w}{127.0.0.1}{127.0.0.1:9300}{master=true}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-01-13 12:28:49,125][INFO ][http                     ] [MasterScrapper] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}
[2016-01-13 12:28:49,125][INFO ][node                     ] [MasterScrapper] started
[2016-01-13 12:28:49,316][INFO ][license.plugin.core      ] [MasterScrapper] license [414cb515-23b0-4a78-8af8-fcf060a1071f] - valid
[2016-01-13 12:28:49,317][ERROR][license.plugin.core      ] [MasterScrapper] 
#
# License will expire on [Sunday, February 07, 2016]. If you have a new license, please update it.
# Otherwise, please reach out to your support contact.
# 
# Commercial plugins operate with reduced functionality on license expiration:
# - marvel
#  - The agent will stop collecting cluster and indices metrics
[2016-01-13 12:28:49,351][INFO ][gateway                  ] [MasterScrapper] recovered [11] indices into cluster_state
[2016-01-13 12:28:55,106][INFO ][cluster.service          ] [MasterScrapper] added {{JG}{5OJu376pS7Gz4HSsZV-yFA}{127.0.0.1}{127.0.0.1:9301}{client=true, data=false, local=false, master=false},}, reason: zen-disco-join(join from node[{JG}{5OJu376pS7Gz4HSsZV-yFA}{127.0.0.1}{127.0.0.1:9301}{client=true, data=false, local=false, master=false}])
[2016-01-13 12:29:52,463][INFO ][cluster.service          ] [MasterScrapper] removed {{JG}{5OJu376pS7Gz4HSsZV-yFA}{127.0.0.1}{127.0.0.1:9301}{client=true, data=false, local=false, master=false},}, reason: zen-disco-node_failed({JG}{5OJu376pS7Gz4HSsZV-yFA}{127.0.0.1}{127.0.0.1:9301}{client=true, data=false, local=false, master=false}), reason transport disconnected

集群运行状况 (GET _cluster/health)

{
  "cluster_name": "Scrapper",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 24,
  "active_shards": 24,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 24,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 50
}

主持人:

localhost (running everything on my local machine.)

Elasticsearch version 2.1.1 (downloaded ran from the official website)
Java Clientlib version org.elasticsearch - elasticsearch - 2.1.1

Installed plugins in /Users/myusername/libs/elasticsearch-2.1.1/plugins:
    - license
    - marvel-agent

config/elasticsearch.yml(精确配置)

cluster.name: "Scrapper"
node.name: "MasterScrapper"
node.master: true
node.data: true
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
network.host: "127.0.0.1"
transport.tcp.port: 9300

OS

OsX El Captain 10.11.2

java

$ java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

你的集群好像没有选master,说明有一些问题。请查看您的日志,看看您能在那里找到什么。您是否在 ElasticSearch 配置中设置了 minimum_master_nodes 属性 ?如果这样做,请检查集群中符合主节点条件的节点数量是否足以选举主节点(至少达到 属性 指定的数量)。

尝试curl -XGET 'localhost:9200/_cluster/health?pretty'

存在多个与许可证插件和 ES 2.0 相关的问题

我通过从 ES 主节点删除许可证插件使其工作。 java 客户端能够连接。嗯!

更多详情请访问:https://discuss.elastic.co/t/elasticsearch-2-1-1-on-localhost-java-client-error-masternotdiscoveredexception-waited-for-30s/39294