Elasticsearch集群'master_not_discovered_exception'

时间:2016-06-22 13:54:29

标签: elasticsearch

我已安装elasticsearch 2.2.3并在2个节点的集群中配置

节点1(elasticsearch.yml)

cluster.name: my-cluster
node.name: node1
bootstrap.mlockall: true
discovery.zen.ping.unicast.hosts: ["ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com", "ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com"]
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.multicast.enabled: false
indices.fielddata.cache.size: "30%"
indices.cache.filter.size: "30%"
node.master: true
node.data: true
http.cors.enabled: true
script.inline: false
script.indexed: false
network.bind_host: 0.0.0.0

节点2(elasticsearch.yml)

cluster.name: my-cluster
node.name: node2
bootstrap.mlockall: true
discovery.zen.ping.unicast.hosts: ["ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com", "ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com"]
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.multicast.enabled: false
indices.fielddata.cache.size: "30%"
indices.cache.filter.size: "30%"
node.master: false
node.data: true
http.cors.enabled: true
script.inline: false
script.indexed: false
network.bind_host: 0.0.0.0

如果我得到curl -XGET 'http://localhost:9200/_cluster/state?pretty'我有:

{
  "error" : {
    "root_cause" : [ {
      "type" : "master_not_discovered_exception",
      "reason" : null
    } ],
    "type" : "master_not_discovered_exception",
    "reason" : null
  },
  "status" : 503
}

进入节点1的日志:

[2016-06-22 13:33:56,167][INFO ][cluster.service          ] [node1] new_master {node1}{Vwj4gI3STr6saeTxKkSqEw}{127.0.0.1}{127.0.0.1:9300}{master=true}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-06-22 13:33:56,210][INFO ][http                     ] [node1] publish_address {127.0.0.1:9200}, bound_addresses {[::]:9200}
[2016-06-22 13:33:56,210][INFO ][node                     ] [node1] started
[2016-06-22 13:33:56,221][INFO ][gateway                  ] [-node1] recovered [0] indices into cluster_state

改为进入节点2的日志:

[2016-06-22 13:34:38,419][INFO ][discovery.zen            ] [node2] failed to send join request to master [{node1}{Vwj4gI3STr6saeTxKkSqEw}{127.0.0.1}{127.0.0.1:9300}{master=true}], reason [RemoteTransportException[[node2][127.0.0.1:9300][internal:discovery/zen/join]]; nested: IllegalStateException[Node [{node2}{_YUbBNx9RUuw854PKFe1CA}{127.0.0.1}{127.0.0.1:9300}{master=false}] not master for join request]; ]

错误在哪里?

7 个答案:

答案 0 :(得分:3)

我解决了这句话:

network.publish_host: ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com

每个elasticsearch.yml配置文件必须包含您的主机名

答案 1 :(得分:3)

master not discovered异常的根本原因是节点无法在端口9300上相互ping通。这需要两种方式。即node1应该能够ping 9300上的node2,反之亦然。

  

注意:Elasticsearch为群集保留端口9300-9400   用于访问elasticsearch API的通信和端口9200-9300。

一个简单的telnet就可以确认了。从node1开始,触发telnet node2 9300

如果成功,则从node2接下来尝试telnet node1 9300

如果master not discovered例外,至少有一个上述telnet会失败。

如果您没有安装telnet,您甚至可以curl

希望这有帮助。

答案 2 :(得分:2)

这里有很多你不想要的设置(比如fielddata)或者不需要。此外,您明确使用AWS EC2实例,因此您应该使用cloud-aws plugin(分为ES 5.x中的单独插件)。这将提供一种新的发现模型,您可以利用而不是zen

对于每个节点,您都希望安装cloud-aws插件(假设ES 2.x):

$ bin/plugin install cloud-aws

安装在每个节点上后,您就可以使用它来利用discovery-ec2组件:

# Guarantee that the plugin is installed
plugin.mandatory: cloud-aws

# Discovery / AWS EC2 Settings
discovery
  type: ec2
  ec2:
    availability_zones: [ "us-east-1a", "us-east-1b" ]
    groups: [ "my_security_group1", "my_security_group2" ]

cloud:
  aws
    access_key: AKVAIQBF2RECL7FJWGJQ
    secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
    region: us-east-1
  node.auto_attributes: true

# Bind to the network on whatever IP you want to allow connections on.
# You _should_ only want to allow connections from within the network
# so you only need to bind to the private IP
node.host: _ec2:privateIp_

# You can bind to all hosts that are possible to communicate with the
# node but advertise it to other nodes via the private IP (less
# relevant because of the type of discovery used, but not a bad idea).
#node:
#  bind_host: [ _ec2:privateIp_, _ec2:publicIp_, _ec2:publicDns_ ]
#  publish_host: _ec2:privateIp_

# Node-specific settings (note: nodes default to be master and data nodes)
node:
  name: node1
  master: true
  data: true

# Constant settings
cluster.name: my-cluster
bootstrap.mlockall: true

最后,你的问题是,由于某些原因很可能源于连接问题,导致大师选举失败。上述配置应解决这些问题,但您还有另一个关键问题:您未正确指定discovery.zen.minimum_master_nodes设置。您有两个符合条件的主节点,但您要求Elasticsearch要求一个用于任何选举。这意味着,在每个符合条件的主节点中,每个符合条件的主节点都可以决定它们具有仲裁,因此可以单独选择它们(从而提供两个主节点,实际上是两个节点)。这是错误

必须因此始终使用法定人数设置该设置:(M / 2) + 1,向下舍入,其中M是主符合条件的节点的数量。所以:

M = 2
(2 / 2) + 1 = (1) + 1 = 2

如果您有3个,4个或5个符合条件的主节点,那么它将是:

M = 3
(3 / 2) + 1 = (1.5) + 1 = 2.5 => 2

M = 4
(4 / 2) + 1 = (2) + 1 = 3

M = 5
(5 / 2) + 1 = (2.5) + 1 = 3.5 => 3

所以,你应该设置,在你的情况下:

discovery.zen.minimum_master_nodes: 2

注意,您可以将其添加为另一行,或者您可以从上面修改发现块(它实际上归结为YAML的样式):

discovery
  type: ec2
  ec2:
    availability_zones: [ "us-east-1a", "us-east-1b" ]
    groups: [ "my_security_group1", "my_security_group2" ]
  zen.minimum_master_nodes: 2

答案 3 :(得分:2)

这可能是没有发现主节点的原因。如果 EC2 实例在同一个 VPC 下,请在 /etc/elasticsearch/elasticsearch.yml 中提供私有 IP,如下所示:

cluster.initial_master_nodes: ["<PRIVATE-IP"]

注意:上述配置更改后,请重启弹性搜索服务,例如sudo service elasticsearch stopsudo service elasticsearch stop 如果操作系统是 ubuntu。

答案 4 :(得分:0)

在我的系统中,防火墙处于打开状态,这就是为什么当我关闭防火墙时出现相同的错误,然后一切正常。因此,请确保您的防火墙已关闭。

答案 5 :(得分:0)

如果master以旧版本的Elastic索引开始,而worker以空索引开头并以新版本初始化,您也可能会遇到此错误

答案 6 :(得分:0)

Sandeep的上述回答向我暗示了节点之间无法相互通信。当我对此进行更多研究时,我发现我缺少EC2安全组中TCP(端口9300)的入站规则。添加了规则,并在所有节点上重新启动elasticsearch服务,该服务开始工作。