首页 文章

使ElasticSearch集群变为绿色(OS X上的集群设置)

提问于
浏览
12

我有installed ElasticSearch on Mac OS X using Homebrew . 有用 . 群集以"green" health开始 . 但是,在添加数据之后,它已经转到"yellow" .

群集运行状况为:绿色,黄色或红色 . 在分片级别,红色状态表示特定分片未在群集中分配,黄色表示分配了主分片但副本不分配,绿色表示分配了所有分片 . 索引级别状态由最差的分片状态控制 . 群集状态由最差的索引状态控制 .

所以,我的副本分片没有分配 . 我该如何分配它们? (我在大声思考 . )

Shay在"I keep getting cluster health status of Yellow"上说:"the shard allocation mechanism does not allocate a shard and its replica on the same node, though it does allocate different shards on the same node. So, you will need two nodes to get cluster state of green."

所以,我需要启动第二个节点 . 我是这样做的:

cd ~/Library/LaunchAgents/
cp homebrew.mxcl.elasticsearch.plist homebrew.mxcl.elasticsearch-2.plist
# change line 8 to: homebrew.mxcl.elasticsearch-2
launchctl load -wF ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch-2.plist

现在 http://localhost:9200/ 上的"Korvus"和 http://localhost:9201/ 上的"Iron Monger" . 活泉 . 但是,我没有看到任何迹象表明他们彼此了解 . 如何将它们相互连接/引入?

注意:我读了Zen Discovery,但感觉还不开心 .

更新2012-08-13美国东部时间下午11:30:

这是我的两个节点:

curl "http://localhost:9200/_cluster/health?pretty=true"
{
  "cluster_name" : "elasticsearch_david",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}

curl "http://localhost:9201/_cluster/health?pretty=true"
{
  "cluster_name" : "elasticsearch_david",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0
}

更新2012-08-13 11:35 PM EST:

为了澄清,我的问题是 not 如何通过设置 index.number_of_replicas: 0 来解决问题 . 我想连接多个节点 .

更新2012-08-13 11:48 PM EST:

我刚发布了double gist that includes elasticsearch.yml and elasticsearch_david.log . 在我看来,两个节点都称自己为'master' . 那是我应该期待的吗?

更新2012-08-14美国东部时间上午12:36:

小说继续! :)如果我从所有外部网络断开我的Mac,然后重新启动节点,那么他们会找到对方 . 双击 . 这让我觉得问题在于我的网络/多播配置 . 目前我在我的配置中有这个: network.host: 127.0.0.1 . 也许这不正确?

3 回答

  • 19

    我遇到了同样的问题 . 当外部网络打开时,两个节点(两个elasticsearch实例运行不同的yml文件:elasticsearch - config = / usr / local / opt / elasticsearch / config / elasticsearch.yml elasticsearch --config = / usr / local / opt / elasticsearch / config / elasticsearch-1.yml)找不到对方,第一个实例处于黄色状态,第二个实例没有已分配的repllica .

    解决方法:sudo route add -net 224.0.0.0/4 127.0.0.1

    参考来自:

    https://issues.jboss.org/browse/JGRP-1808

  • 0

    解决了 . 不要使用 network.host: 127.0.0.1 . 将该行留下注释,以便自动导出 .

    默认 elasticsearch.yml 是正确的 . configuration tweak by the Homebrew installer指定 127.0.0.1 loopback接口:

    # Set up ElasticSearch for local development:
    inreplace "#{prefix}/config/elasticsearch.yml" do |s|
      # ...
      # 3. Bind to loopback IP for laptops roaming different networks
      s.gsub! /#\s*network\.host\: [^\n]+/, "network.host: 127.0.0.1"
    end
    

    我提交了an issue on the Homebrew issue tracker .

  • 13

    正确地注意到群集变黄了,因为您创建了一个包含副本的索引,但是群集中只有一个节点 . 解决此问题的一种方法是在第二个节点上分配它们 . 另一种方法是关闭复制品 . 可以在index creation期间指定副本数 . 以下命令将创建一个名为 new-index-name 的新索引,其中包含1个分片且没有副本 .

    curl -XPUT 'localhost:9200/new-index-name' -d '
    {
        "settings": {
            "index" : {
                "number_of_shards" : 1,
                "number_of_replicas" : 0
            }
        }
    }
    '
    

    在使用Indices Update Settings API创建索引之后,还可以更改副本数 . 对于群集中的所有索引,以下命令将将副本数更改为0:

    curl -XPUT 'localhost:9200/_settings' -d '
    {
        "index" : {
            "number_of_replicas" : 0
        }
    }
    '
    

    您可以通过运行cluster health命令验证节点是否相互找到:

    $ curl "http://localhost:9200/_cluster/health?pretty=true"
    {
      "cluster_name" : "elasticsearch",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 2,
      "number_of_data_nodes" : 2,
      "active_primary_shards" : 30,
      "active_shards" : 55,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0
    }
    

    这里的行 "number_of_data_nodes" : 2, 表示我的集群由两个节点组成,这意味着他们找到了彼此 . 您还可以运行Nodes Info命令以查看群集包含的节点:

    curl "http://localhost:9200/_cluster/nodes?pretty=true"
    

相关问题