我的集群只有一个节点,所以健康状态为 黄色
,因为没有其他的可用节点可以分配副本。
因此,我想创建/添加另一个节点,这样 Elasticsearch 就可以开始将副本分配给它了。我只有一台机器,而且我正在运行 ES 作为服务。
我找到了很多网站,其中一些提供了一些信息,但没有一个能够清楚地告诉我如何向 ES 添加另一个节点。
有人能解释一下我需要编辑哪些文件以及要启动哪些命令才能在我的集群中创建另一个节点吗?我需要运行两个 ES 实例吗?我应该如何操作?
提前致谢。
我的集群只有一个节点,所以健康状态为 黄色
,因为没有其他的可用节点可以分配副本。
因此,我想创建/添加另一个节点,这样 Elasticsearch 就可以开始将副本分配给它了。我只有一台机器,而且我正在运行 ES 作为服务。
我找到了很多网站,其中一些提供了一些信息,但没有一个能够清楚地告诉我如何向 ES 添加另一个节点。
有人能解释一下我需要编辑哪些文件以及要启动哪些命令才能在我的集群中创建另一个节点吗?我需要运行两个 ES 实例吗?我应该如何操作?
提前致谢。
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 你的状态是什么?你可能会看到:INITIALIZING 这可能意味着数据正在传输中。因此,如果你的数据很大(而且不在SSD上),请等待。
别忘了
您可以通过键入以下命令来查看数据是否正在移动:
[watch] du /var/lib/elasticsearch/
目前就这些内容。我会尝试不定期更新更多信息。
请随意修改/添加。
在Windows操作系统上完成的步骤如下:
bin\service install 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"]
运行 service manager elastic-search-x64-node01
命令,设置服务规则并启动服务。
将 Elastic 解压缩到 C:\ELK\elastic2\ 目录下,然后运行命令 bin\service install elastic-search-x64-node02
,这将创建名为 elastic-search-x64-node02
的服务。
编辑 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"]
运行 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
}
discovery.zen.ping.multicast.enabled
,您还需要将 node.max_local_storage_nodes: 2
添加到配置中。 - stairie首先,您可以删除副本以返回到绿色状态。即使在创建索引并添加文档后,您也可以这样做。
以下是将副本计数设置为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实例,您的群集应该在线。
elasticsearch.yml
文件吗?如何创建两个ES实例?如果您能更清晰地阐述您的答案,那将非常好。谢谢! - Avión我不清楚你的问题是什么。你有两种可能的选择。
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进程,无论它们是否在同一台机器上或两台不同的机器上都由你决定。
elasticsearch
即可。这样,您将拥有两个实例。[Black Widow] detected_master [N'Garai]
在已经运行的实例上(主节点)
[N'Garai] added {[Black Widow]
[N'Garai]
和 {[Black Widow]
是随机节点名称。
bin/elasticsearch
即可。您可以简单地打开另一个终端窗口并以同样的方式启动另一个elasticsearch进程! - Michele Palmiaservice elasticsearch start
就可以将 ES 作为服务启动,并且一切都神奇地在一个节点上运行。 - Avión