【问题标题】:How to fix cluster health yellow with Elastic Search如何使用 Elastic Search 修复集群健康黄色
【发布时间】:2018-09-12 12:41:21
【问题描述】:

我已经在服务器上设置了 MongoDb 和 ElasticSearch。使用https://github.com/richardwilly98/elasticsearch-river-mongodb,我将 ElasticSearch 和 MongoDb 连接在一起。

我使用以下方法创建一个新索引:

curl -XPUT 'http://127.0.0.1:9200/_river/mongodb/_meta' -d '{ 
        "type": "mongodb", 
        "mongodb": { 
        "db": "my_database", 
        "collection": "my_collection"
    }, 
        "index": {
        "name": "mainindex", 
        "type": "string",
        "bulk": {
            "concurrent_requests": 1
        }
    }
}'

执行命令后,我转到 http://x.x.x.x:9200/_plugin/head/,我看到消息:集群健康:黄色 (1, 6)。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    通过在弹性搜索配置中使用相同的集群名称来配置集群

    您可能使用的默认 elasticsearch.yml 在开始时有这些设置,如下所示:

    ################################### Cluster ###################################
    
    # Cluster name identifies your cluster for auto-discovery. If you're running
    # multiple clusters on the same network, make sure you're using unique names.
    #
    # cluster.name: elasticsearch
    
    
    #################################### Node #####################################
    
    # Node names are generated dynamically on startup, so you're relieved
    # from configuring them manually. You can tie this node to a specific name:
    #
    # node.name: "Franz Kafka"
    

    这里你需要配置一个唯一的

    cluster.name: "MainCluster"

    并且对于每台机器和/或实例都有不同的唯一性

    node.name: "LocalMachine1"

    您现在需要将此elasticsearch.yml 复制到另一台机器(在同一个网络中),或复制到与elasticsearch_2.yml 相同的地方编辑它:

    node.name: "LocalMachine2"

    您的集群已准备就绪

    如果没有配置 elastiscsearch 将使用一个随机的 Marvel 字符(根据文档为 3000 个),所以不要更改 node.name 也应该可以

    为了让两个节点在同一台机器上运行, 您必须进行配置,例如elasticsearch_2.yml 复制,具有上述更改。 此外,您必须拥有数据和日志路径的副本 例如(自制特定路径:)

    cp -r /usr/local/var/elasticsearch /usr/local/var/elasticsearch_2
    cp -r /usr/local/var/log/elasticsearch /usr/local/var/log/elasticsearch_2
    

    可能看起来像

    #################################### Paths ####################################
    
    # Path to directory containing configuration (this file and logging.yml):
    #
    # path.conf: /path/to/conf
    
    # Path to directory where to store index data allocated for this node.
    #
    path.data: /usr/local/var/elasticsearch_2/
    #
    # Can optionally include more than one location, causing data to be striped across
    # the locations (a la RAID 0) on a file level, favouring locations with most free
    # space on creation. For example:
    #
    # path.data: /path/to/data1,/path/to/data2
    
    # Path to temporary files:
    #
    # path.work: /path/to/work
    
    # Path to log files:
    #
    path.logs: /usr/local/var/log/elasticsearch_2/
    

    确保您没有在 localhost 环回设备上运行 elasicsearch

    127.0.0.1

    如果不是,只需将其注释掉(自制软件会以这种方式进行修补)

    ############################## Network And HTTP ###############################
    
    # Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
    # on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
    # communication. (the range means that if the port is busy, it will automatically
    # try the next port).
    
    # Set the bind address specifically (IPv4 or IPv6):
    #
    # network.bind_host: 192.168.0.1
    
    # Set the address other nodes will use to communicate with this node. If not
    # set, it is automatically derived. It must point to an actual IP address.
    #
    # network.publish_host: 192.168.0.1
    
    # Set both 'bind_host' and 'publish_host':
    #
    # network.host: 127.0.0.1
    

    现在你可以像这样开始弹性搜索了:

    bin/elasticsearch -D es.config=/usr/local/Cellar/elasticsearch/1.0.0.RC1/config/elasticsearch.yml
    

    对于第一个节点和master(因为先启动)

    然后

    bin/elasticsearch -D es.config=/usr/local/Cellar/elasticsearch/1.0.0.RC1/config/elasticsearch_2.yml
    

    现在你应该有 2 个节点在运行

    【讨论】:

    • 感谢您的反馈,我已尝试按照您的流程进行操作,但仍然遇到问题。一个问题是:当我重新启动服务时,我创建的索引不见了,我需要重新索引。第二个问题不是所有文档都被索引...按时它只是 5500 中的 1000 个,而其他时间是 5500 中的 5000 个。你能为我设置这些东西吗,也许通过远程会话,这样我就可以看到在哪里我做错事了。显然你会得到回报。
    • 仅供参考:我在一台机器上运行两个节点。
    【解决方案2】:

    看起来您没有可用于复制分片的节点。您可以将副本计数降低到 0 或向集群添加第二个节点,以便可以将主分片和副本分片安全地放置在不同的节点上。

    elasticsearch.yml中的默认配置大概是这样的:

    index.number_of_shards: 5  
    index.number_of_replicas: 1
    

    如果您的节点崩溃,集群中的另一个节点将拥有该分片的副本。由于您只有一个节点,因此集群不知道将副本放在哪里,因此处于黄色状态。

    【讨论】:

    • 我们如何将节点添加到集群中?
    • 你可以启动另一个 jvm 进程指向不同的配置文件,所以想象你在 /opt/elasticsearch 中安装了 es 代码,你可以在 / 中拥有 config/、data/、/logs、dirs选择/es-1,/选择/es-2。您可以使用 -Des.config=<..file..> 创建新节点从指向任意数量配置的命令行启动 es
    • 我是否只需要指向第二个节点的集群名称以便它加入它?如果是这样,我该怎么做?
    • 指向节点配置文件的语法是什么?
    • elasticsearch -Des.config=PATH_TO_YOUR_CONFIG_FILE
    【解决方案3】:

    我正在发布一个答案,因为我在寻找类似问题的解决方案时偶然发现了这个问题。

    我有一个开发环境,我只需要 1 个 Elasticsearch 节点,因此我的所有索引都不需要副本。

    为了解决 cluster health: yellow 问题,我刚刚做了index.number_of_replicas: 1

    PUT /_settings
    {
      "index" : {
            "number_of_replicas" : 0
        }
    }
    

    【讨论】:

    • 请注意,only 1 replica 的概念确实等同于 "number_of_replicas" : 0,因为副本是原件的副本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    相关资源
    最近更新 更多