【问题标题】:How to add a new node to my Elasticsearch cluster如何向我的 Elasticsearch 集群添加新节点
【发布时间】:2016-06-13 13:38:57
【问题描述】:

我的集群的健康状况为 yellow,因为它只有一个节点,因此副本保持未签名只是因为没有其他节点可用于包含它们。

所以我想创建/添加另一个节点,以便 Elasticsearch 可以开始为其分配副本。我只有一台机器,并且将 ES 作为服务运行

我找到了大量包含一些信息的站点,但它们都没有清楚地告诉我如何将另一个节点添加到 ES。

谁能解释我必须编辑哪些文件以及我必须启动哪些命令才能在集群中创建另一个节点?我必须运行两个 ES 实例吗?我该怎么做?

提前致谢。

【问题讨论】:

  • 如果你在本地启动一个节点来尝试 elasticsearch 只是从你从 Elastic 网站下载的 elasticsearch 文件夹中调用 bin/elasticsearch,你可以简单地打开另一个终端窗口并在同一个中启动另一个 elasticsearch 进程方式!
  • @micpalmia 问题是我将 ES 作为服务运行。
  • 您是否在 AWS Elasticsearch 中运行您的集群?您有权访问配置吗?你是如何启动第一个节点的?
  • 刚刚使用 service elasticsearch start 将 ES 作为服务启动,一切都在一个节点上神奇地工作。

标签: elasticsearch cluster-computing replication


【解决方案1】:

首先,您可以删除副本以恢复绿色状态,即使在创建索引并向其添加文档之后也可以这样做。

以下是将副本数设置为 0 的方法:

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

如果您想简单地向集群添加另一个节点,则需要编辑 elasticsearch.yml,最好在您的两个节点上进行以下更改:

cluster.name: my-cluster
node.name: node01
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["192.168.0.5"]

在每个节点上设置单播主机以引用另一个,在两个节点上将集群名称设置为相同并为每个节点指定一个唯一的名称,然后重新启动两个 ES 实例,您的集群应该在线。

【讨论】:

  • each 节点是什么意思?每个节点都必须有一个elasticsearch.yml 吗?如何制作两个 ES 实例?如果您能以更清晰的方式详细说明您的答案,那就太好了。谢谢!
  • 我假设您有两台不同的机器要包含在一个集群中。因此,您需要在两台机器上安装 Elasticsearch 并为每台机器编辑 elasticsearch.yml 文件。
  • 只有一台机器。我不知道这是否有任何意义,但我的想法是创建一个新节点来在那里存储副本,就像进行故障转移一样。 elastic.co/guide/en/elasticsearch/guide/current/…
【解决方案2】:

我不清楚您的问题是什么。您有两种可能性。

1) 你有两个节点,你希望它们能够互相看到。到处都有很多关于这个的文档。如果是这种情况,我建议您进行测试以确保每个主机都可以与其他主机通信,即:ssh 进入主机 A 并尝试 curl 主机 B:9200,反之亦然。您还需要确保您的配置设置正确。

2) 您想在本地机器上设置一个“集群”。在这种情况下,您将需要两个单独的配置文件,并且您需要使用您的第二个“节点”的特定配置文件来启动 elasticsearch(以及修改第二个配置以使用不同的端口等)。您可能想查看此链接:http://www.concept47.com/austin_web_developer_blog/elasticsearch/how-to-run-multiple-elasticsearch-nodes-on-one-machine/

但是是的,最终,您需要运行到 elasticsearch 进程,无论它们是在同一台机器上,还是两台不同的机器上都取决于您

【讨论】:

【解决方案3】:

如果您在本地运行 Elasticsearch n,只需转到另一个终端并再次运行 elasticsearch。这样你将有两个实例。

您将在新运行的实例上看到以下消息:

[Black Widow] detected_master [N'Garai]

在已经运行的实例上(master node)

[N'Garai] added {[Black Widow]

假设[N'Garai]{[Black Widow] 是随机节点名称。

【讨论】:

    【解决方案4】:

    Windows Box 上的完整步骤是:

    1. 解压弹性文件到 C:\ELK\elastic\ 运行命令bin\service install elastic-search-x64-node01,这将创建名为 elastic-search-x64-node01
    2. 编辑elasticsearch.yml配置文件:

      cluster.name: Animals
      node.name: Snake
      node.master: true
      node.data: true
      path.data: C:\ELK\storage\data
      path.logs: C:\ELK\storage\logs
      http.port: 9200
      discovery.zen.ping.multicast.enabled: false
      discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
      
    3. 运行 service manager elastic-search-x64-node01 并设置您的服务规则并启动服务

    4. 解压缩弹性文件,例如,到 C:\ELK\elastic2\ 运行命令 bin\service install elastic-search-x64-node02,这将创建名为 elastic-search-x64-node02

    5. 编辑elasticsearch.yml配置文件:

      cluster.name: Animals
      node.name: Baboon
      node.master: false
      node.data: true
      path.data: C:\ELK\storage\data
      path.logs: C:\ELK\storage\logs
      http.port: 9201
      discovery.zen.ping.multicast.enabled: false
      discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
      
    6. 运行service manager elastic-search-x64-node02 并设置您的服务规则并启动服务

    此时您有 2 个单独的节点(它们将数据存储在同一个文件夹中,但我懒得为第二个节点编辑 path.data),因为 2 个单独的 Windows 服务和 GET http://localhost:9200/_cluster/health 显示如下:

    {
      "cluster_name": "Animals",
      "status": "green",
      "timed_out": false,
      "number_of_nodes": 2,
      "number_of_data_nodes": 2,
      "active_primary_shards": 4,
      "active_shards": 8,
      "relocating_shards": 0,
      "initializing_shards": 0,
      "unassigned_shards": 0,
      "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": 100
    }
    

    【讨论】:

    • 5.3.0 似乎不支持设置discovery.zen.ping.multicast.enabled,您还需要在配置中添加node.max_local_storage_nodes: 2
    【解决方案5】:

    添加另一个节点的提示:

    1) 版本:

    最好检查所有节点的状态: http://elastic-node1:9200/

    请记住,在大多数情况下:版本需要相同,即使是次要的

    {
    "name" : "node2",
    "cluster_name" : "xxxxxxxxxxx",
    "cluster_uuid" : "n-xxxxxxxxxxxxxxx",
    "version" : {
      "number" : "5.2.2",
      "build_hash" : "xxxx",
      "build_date" : "20-02-24T17:26:45.835Z",
      "build_snapshot" : false,
      "lucene_version" : "6.4.1"
    },
    "tagline" : "You Know, for Search"
    }
    

    请记住,如果您在 node1 中看到不同的版本号,例如

      "number" : "5.2.1"
    

    在这种情况下,您必须将您的节点更新到版本 5.2.2(与 node1 相同)。

    2) 节点和副本:

    节点的用例是什么?对于 3 个节点,我会这样做:

    curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
    {
      "transient": {
        "discovery.zen.minimum_master_nodes": 3
      }
    }
    '
    

    更好的是更改 Elasticsearch 的配置文件中的设置:

    /etc/elasticsearch/elasticsearch.yml 
    
    # need to be changed on each node (has to be unique for each node):
    node.name: node1
    
    # need to be the same in all nodes:
    cluster.name: my_cluster
    discovery.zen.ping.unicast.hosts: ["IP_ADDRESS_OR_HOSTNAME1", "IP_ADDRESS_OR_HOSTNAME2", "IP_ADDRESS_OR_HOSTNAME3"]
    

    如果你有 3 个节点,你想要两个副本和一个主节点吗?

    curl -XPUT 'localhost:9200/_settings?pretty' -H 'Content-Type: application/json' -d'
    {
        "index" : {
            "number_of_replicas" : 2
        }
    }'
    

    3) 确保节点已启用

    有一种踢节点的方法:

    curl -XPUT localhost:9200/_cluster/settings -d '{
      "transient" :{
          "cluster.routing.allocation.exclude._ip" : "NODE_TO_REMOVE_IP_ADDRESS_OR_HOSTNAME"
       }
    }';echo
    

    所以如果你这样做了,现在你想重新添加节点: https://www.elastic.co/guide/en/elasticsearch/guide/current/_rolling_restarts.html

    您可以通过以下请求做到这一点(请仔细阅读上面提到的链接):

    curl -XPUT localhost:9200/_cluster/settings -d '{
      "transient" :{
            "cluster.routing.allocation.enable" : "all"
       }
    }';echo
    

    4) 永远不要忘记,网络:

    防火墙、网络...你能到达端口 9200 的新节点吗? 你能在你的网络浏览器上看到它吗?

    可以吗

    curl http://your-elasticsearch-hostname:9200/
    

    ?

    从集群中删除节点的提示:

    1) 使用 API 删除

    curl -XPUT 'http://localhost:9200/_cluster/settings?pretty' -d '
    {
      "transient" : {
        "cluster.routing.allocation.exclude._name" : "node3"
      }
    }'
    

    2) 检查您的配置文件

    检查下面的配置文件: /etc/elasticsearch/elasticsearch.yml

    只留下你想保留的节点:

    discovery.zen.ping.unicast.hosts:["IP_ADDRESS_OR_HOSTNAME1", "IP_ADDRESS_OR_HOSTNAME2"]
    

    * 检查您的状态 *

    检查http://elk-pipeline:9200/_cat/shards 你的状态是什么?您可能会看到:正在初始化 这可能意味着数据被传输。因此,如果您的数据很大(而不是在 SSD 上),请稍候。

    不要忘记

    您可以通过键入以下内容查看您的数据当前是否正在移动:

    [watch] du /var/lib/elasticsearch/
    

    暂时就这些了。我会不时尝试在此处添加更多信息。

    请随时更改/添加。

    【讨论】:

      猜你喜欢
      • 2015-09-08
      • 2014-05-14
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多