elasticsearch 如何将新节点添加到我的Elasticsearch群集,elasticsearch,cluster-computing,replication,elasticsearch,Cluster Computing,Replication" /> elasticsearch 如何将新节点添加到我的Elasticsearch群集,elasticsearch,cluster-computing,replication,elasticsearch,Cluster Computing,Replication" />

elasticsearch 如何将新节点添加到我的Elasticsearch群集

elasticsearch 如何将新节点添加到我的Elasticsearch群集,elasticsearch,cluster-computing,replication,elasticsearch,Cluster Computing,Replication,我的集群只有一个节点,因此运行状况为黄色,因此副本保持未分配状态,因为没有其他节点可以容纳它们 因此我想创建/添加另一个节点,以便Elasticsearch可以开始为其分配副本。我只有一台机器,我正在运行ES作为服务。 我已经找到了大量的站点,其中包含一些信息,但没有一个能够清楚地告诉我如何向ES添加另一个节点 有人能解释一下,为了在集群中创建另一个节点,我需要编辑哪些文件,需要启动哪些命令吗?我必须运行两个ES实例吗?我该怎么做 提前感谢。首先,您可以删除复制副本以返回绿色状态,甚至在创建索引

我的集群只有一个节点,因此运行状况为
黄色
,因此副本保持未分配状态,因为没有其他节点可以容纳它们

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

我已经找到了大量的站点,其中包含一些信息,但没有一个能够清楚地告诉我如何向ES添加另一个节点

有人能解释一下,为了在集群中创建另一个节点,我需要编辑哪些文件,需要启动哪些命令吗?我必须运行两个ES实例吗?我该怎么做


提前感谢。

首先,您可以删除复制副本以返回绿色状态,甚至在创建索引并向其中添加文档后也可以执行此操作

以下是将副本计数设置为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实例,您的群集应该处于联机状态。

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

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

2) 您希望在本地计算机上设置“群集”。在这种情况下,您需要两个单独的配置文件,并且需要使用第二个“节点”的特定配置文件启动elasticsearch(以及修改第二个配置以使用不同的端口等)。您可能希望签出此链接:


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

如果您正在运行elasticsearch n local,只需转到另一个终端,然后再次运行
elasticsearch
。这样您将有两个实例

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

[Black Widow] detected_master [N'Garai]
在已经运行的实例(
master节点)


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

Windows Box上的完整步骤如下:

  • 例如,将elastic解压到C:\ELK\elastic\run command
    bin\service
    安装elastic-search-x64-node01
    ,它将创建名为
    elastic-search-x64-node01
  • 编辑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"]
    
    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"]
    
  • 运行
    服务管理器elastic-search-x64-node01
    ,设置服务规则并启动服务

  • 将elastic解压到C:\ELK\elastic2\run command
    bin\service
    安装elastic-search-x64-node02
    ,它将创建名为
    elastic-search-x64-node02

  • 编辑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"]
    
    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"]
    
  • 运行
    服务管理器elastic-search-x64-node02
    ,设置服务规则并启动服务

  • 此时,您有两个单独的节点(它们将数据存储在同一文件夹中,但我太懒散了,无法编辑第二个节点的path.data)作为两个单独的Windows服务和
    GEThttp://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
    }
    
    添加另一个节点的提示: 1)版本:

    建议检查所有节点的状态:

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

    {
    "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
    
    因此,如果您这样做了,现在您想重新添加节点:

    您可以通过以下请求完成此操作(请仔细阅读上面提到的链接):

    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"]
    
    *检查您的状态*

    检查 您的状态是什么?您可能会看到:正在初始化 这可能意味着数据已被传输。因此,如果您的数据很大(而不是在SSD上),请等待

    别忘了

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

    [watch] du /var/lib/elasticsearch/
    
    现在就这些。我会不时尝试在这里添加更多信息


    请随意更改/添加。

    这将引导您:如果您正在本地启动一个节点来尝试elasticsearch,只需从您从Elastic网站下载的elasticsearch文件夹中调用
    bin/elasticsearch
    ,您只需打开另一个终端窗口,并以同样的方式启动另一个elasticsearch进程!@micpalmia问题是我正在运行ES作为服务。你在AWS Elasticsearch中运行你的集群吗?你有权访问配置吗?你是怎么做到的