elasticsearch-节点
editelasticsearch-节点
editThe elasticsearch-node 命令使您能够在节点关闭时执行某些不安全的操作。此命令允许您调整节点的角色,不安全地编辑集群设置,并且在灾难后可能能够恢复一些数据,或者即使节点与磁盘上的数据不兼容,也可以启动节点。
概要
editbin/elasticsearch-node repurpose|unsafe-bootstrap|detach-cluster|override-version [-E <KeyValuePair>] [-h, --help] ([-s, --silent] | [-v, --verbose])
描述
edit此工具具有多种模式:
-
elasticsearch-node repurpose可以用于从节点中删除不需要的数据,如果它曾经是一个数据节点或一个主节点,但已被重新配置为不具有这些角色之一。 -
elasticsearch-node remove-settings可以用于从集群状态中删除持久设置,以防其中包含阻止集群形成的兼容性设置。 -
elasticsearch-node remove-index-settings可以用于从集群状态中删除索引设置,以防其中包含阻止集群形成的兼容性索引设置。 -
elasticsearch-node remove-customs可以用于从集群状态中删除自定义元数据,以防其中包含阻止集群状态加载的损坏元数据。 -
elasticsearch-node unsafe-bootstrap可以用于执行不安全的集群引导。它强制其中一个节点使用其本地副本的集群元数据自行形成一个全新的集群。 -
elasticsearch-node detach-cluster使您能够将节点从一个集群移动到另一个集群。这可以用于将节点移动到使用elasticsearch-node unsafe-bootstrap命令创建的新集群中。如果不安全的集群引导不可行,它还使您能够将节点移动到一个全新的集群中。 -
elasticsearch-node override-version使您能够在数据路径中的数据由不兼容版本的Elasticsearch写入的情况下启动节点。这有时可能允许您降级到较早版本的Elasticsearch。
JVM 选项
editCLI 工具以 64MB 的堆内存运行。对于大多数工具来说,这个值是合适的。然而,如果需要,可以通过设置 CLI_JAVA_OPTS 环境变量来覆盖此值。例如,以下命令将 elasticsearch-node 工具使用的堆内存大小增加到 1GB。
export CLI_JAVA_OPTS="-Xmx1g" bin/elasticsearch-node ...
更改节点的角色
edit在某些情况下,您可能希望在不遵循适当的重新利用流程的情况下重新利用节点。elasticsearch-node repurpose工具允许您删除任何多余的数据并重新利用节点后启动它。
预期用途是:
- 停止节点
-
通过设置
elasticsearch.yml中的node.roles来更新。 -
在节点上运行
elasticsearch-node repurpose - 启动节点
如果你在没有data角色和具有master角色的节点上运行elasticsearch-node repurpose,它将删除该节点上任何剩余的分片数据,但会保留索引和集群元数据。如果你在没有data和master角色的节点上运行elasticsearch-node repurpose,它将删除任何剩余的分片数据和索引元数据,但会保留集群元数据。
运行此命令可能会导致所提及索引的数据丢失,如果其中包含的数据在集群中的其他节点上不可用。只有在您理解并接受可能的后果,并且确定节点无法干净地重新利用后,才应运行此工具。
该工具提供了即将删除数据的摘要,并在进行任何更改之前要求确认。您可以通过传递详细信息选项(-v)来获取有关受影响索引和分片的详细信息。
移除持久化集群设置
edit在某些情况下,节点可能包含持久化的集群设置,这些设置会阻止集群的形成。由于集群无法形成,因此无法使用集群更新设置 API 来移除这些设置。
使用 elasticsearch-node remove-settings 工具可以强制从磁盘上的集群状态中删除这些持久化设置。该工具接受一个应删除的设置列表作为参数,并且还支持通配符模式。
预期用途是:
- 停止节点
-
在节点上运行
elasticsearch-node remove-settings name-of-setting-to-remove - 对所有其他符合主节点资格的节点重复此操作
- 启动节点
移除索引设置
edit可能存在索引包含阻止集群形成的索引设置的情况。由于集群无法形成,因此无法使用更新索引设置 API 来移除这些设置。
使用 elasticsearch-node remove-index-settings 工具可以强制从磁盘上的集群状态中删除这些索引设置。该工具接受一个应删除的索引设置列表作为参数,并且还支持通配符模式。
预期用途是:
- 停止节点
-
在节点上运行
elasticsearch-node remove-index-settings name-of-index-setting-to-remove - 对所有节点重复此操作
- 启动节点
从集群状态中移除自定义元数据
edit在某些情况下,节点可能包含由插件提供的自定义元数据,这些元数据可能会阻止节点启动并从磁盘加载集群。
工具 elasticsearch-node remove-customs 允许你强制移除有问题的自定义元数据。该工具接受一个自定义元数据名称列表作为参数,这些名称应该被移除,并且还支持通配符模式。
预期用途是:
- 停止节点
-
在节点上运行
elasticsearch-node remove-customs name-of-custom-to-remove - 对所有其他符合主节点资格的节点重复此操作
- 启动节点
灾难后的数据恢复
edit有时Elasticsearch节点会暂时停止,可能是因为需要执行某些维护活动,或者可能是因为硬件故障。在您解决了临时情况并重新启动节点后,它将重新加入集群并继续正常运行。根据您的配置,您的集群即使在停止了一个或多个节点的情况下,也可能能够完全保持可用。
有时在节点停止后可能无法重新启动它。例如,节点的主机可能遇到无法修复的硬件问题。如果集群仍然可用,您可以在另一台主机上启动一个新节点,Elasticsearch会将此节点加入集群以替代失败的节点。
每个节点将其数据存储在由path.data设置定义的数据目录中。这意味着在灾难情况下,您也可以通过将数据目录移动到另一个主机来重新启动节点,前提是这些数据目录可以从故障主机中恢复。
Elasticsearch 需要从大多数主节点候选节点获得响应,以便选举主节点并更新集群状态。这意味着如果你有三个主节点候选节点,那么即使其中一个节点发生故障,集群仍然可以保持可用。然而,如果三个主节点候选节点中有两个发生故障,那么集群将无法使用,直到至少有一个节点重新启动。
在极少数情况下,可能无法重启足够多的节点来恢复集群的可用性。如果发生此类灾难,您应该从最近的快照构建一个新集群,并重新导入自该快照生成以来摄取的任何数据。
然而,如果灾难严重到一定程度,那么可能也无法从最近的快照中恢复。不幸的是,在这种情况下,没有不冒数据丢失风险的方法,但可能可以使用elasticsearch-node工具构建一个包含失败集群中部分数据的新集群。
绕过版本检查
editElasticsearch 写入磁盘的数据旨在被当前版本和有限数量的未来版本读取。它通常不能被较旧的版本读取,也不能被比当前版本新一个以上主要版本的版本读取。存储在磁盘上的数据包括写入该数据的节点的版本,Elasticsearch 在启动时会检查它是否与此版本兼容。
在极少数情况下,可能需要绕过此检查并使用由不兼容版本写入的数据启动Elasticsearch节点。如果存储数据的格式已更改,这可能不起作用,并且这是一个有风险的过程,因为格式可能会以Elasticsearch可能误解的方式更改,从而可能导致数据丢失。
要绕过此检查,您可以使用 elasticsearch-node override-version 工具将数据路径中存储的版本号覆盖为当前版本,从而使 Elasticsearch 认为它与磁盘上的数据兼容。
不安全的集群引导
edit如果至少有一个剩余的主资格节点,但无法重启大多数节点,那么elasticsearch-node unsafe-bootstrap命令将不安全地覆盖集群的投票配置,就像执行另一个集群引导过程一样。目标节点可以利用目标节点上本地保存的集群元数据自行形成一个新的集群。
这些步骤可能导致任意数据丢失,因为目标节点可能不持有最新的集群元数据,而这种过时的元数据可能使得无法使用集群中的一些或所有索引。
由于不安全的引导会形成一个包含单个节点的新集群,一旦您运行了它,您必须使用elasticsearch-node
detach-cluster工具将任何其他幸存的节点从失败的集群迁移到这个新集群中。
当您运行 elasticsearch-node unsafe-bootstrap 工具时,它将分析节点的状态,并在采取任何操作之前请求确认。在请求确认之前,它会报告在其上运行的节点的集群状态的任期和版本,如下所示:
Current node cluster state (term, version) pair is (4, 12)
如果你有多个节点可以选择运行此工具,那么你应该选择一个具有尽可能大任期的节点。如果有多个节点具有相同的任期,选择版本号最大的那个。
这个信息标识了具有最新集群状态的节点,这最小化了可能丢失的数据量。例如,如果第一个节点报告(4, 12),而第二个节点报告(5, 3),那么第二个节点是首选,因为它的任期更大。然而,如果第二个节点报告(3, 17),那么第一个节点是首选,因为它的任期更大。如果第二个节点报告(4, 10),那么它与第一个节点具有相同的任期,但版本号更小,所以第一个节点是首选。
运行此命令可能导致任意数据丢失。仅在您理解并接受可能的后果,并且已经穷尽所有其他恢复集群的可能性后,才运行此工具。
使用此工具的操作顺序如下:
- Make sure you have really lost access to at least half of the master-eligible nodes in the cluster, and they cannot be repaired or recovered by moving their data paths to healthy hardware.
- Stop all remaining nodes.
- Choose one of the remaining master-eligible nodes to become the new elected master as described above.
-
On this node, run the
elasticsearch-node unsafe-bootstrapcommand as shown below. Verify that the tool reportedMaster node was successfully bootstrapped. - Start this node and verify that it is elected as the master node.
-
Run the
elasticsearch-node detach-clustertool, described below, on every other node in the cluster. - Start all other nodes and verify that each one joins the cluster.
- Investigate the data in the cluster to discover if any was lost during this process.
当您运行该工具时,它会确保用于引导集群的节点未在运行。重要的是,在该工具运行期间,所有其他符合主节点资格的节点也必须停止,但该工具不会检查这一点。
消息 Master node was successfully bootstrapped 并不意味着没有数据丢失,它只是意味着工具能够完成其工作。
从集群中分离节点
edit在不同集群之间移动节点是不安全的,因为不同的集群具有完全不同的集群元数据。无法安全地将两个集群的元数据合并在一起。
为了防止无意中加入错误的集群,每个集群在首次启动时会创建一个唯一的标识符,称为集群UUID。每个节点都会记录其集群的UUID,并拒绝加入具有不同UUID的集群。
然而,如果一个节点的集群永久性失败,那么可能需要尝试将其移动到一个新的集群中。elasticsearch-node detach-cluster 命令允许你通过重置其集群UUID来将节点从其集群中分离。然后,它可以加入具有不同UUID的另一个集群。
例如,在非安全集群引导之后,您需要将所有其他幸存的节点从其旧集群中分离,以便它们可以加入新的、非安全引导的集群。
不安全的集群引导只有在至少有一个幸存的符合主节点资格的节点时才可能实现。如果没有剩余的符合主节点资格的节点,那么集群元数据将完全丢失。然而,各个数据节点也包含与其分片对应的索引元数据的副本。这有时允许新集群将这些分片作为悬空索引导入。在集群中所有主节点资格节点丢失后,有时可以通过创建一个新集群,然后使用elasticsearch-node detach-cluster命令将任何幸存的节点移动到这个新集群中来恢复一些索引。一旦新集群完全形成,使用悬空索引API来列出、导入或删除任何悬空索引。
导入悬空索引时存在数据丢失的风险,因为数据节点可能没有最新的索引元数据副本,并且没有任何关于哪些分片副本是同步的的信息。这意味着可能会选择一个陈旧的分片副本作为主分片,并且某些分片可能与导入的映射不兼容。
执行此命令可能导致任意数据丢失。仅在您理解并接受可能的后果,并且已穷尽所有其他恢复集群的可能性后,才运行此工具。
使用此工具的操作顺序如下:
- 确保您已经完全失去了对集群中所有主节点候选节点的访问权限,并且它们无法通过将数据路径移动到健康硬件上来修复或恢复。
- 启动一个新集群并验证其是否健康。该集群可以由一个或多个全新的主节点候选节点组成,或者可以是一个如上所述的不安全引导的集群。
- 停止所有剩余的数据节点。
-
在每个数据节点上,运行
elasticsearch-node detach-cluster工具,如下所示。验证工具是否报告了Node was successfully detached from the cluster。 - 如有必要,配置每个数据节点以发现新集群。
- 启动每个数据节点并验证它是否已加入新集群。
- 等待所有恢复完成,并调查集群中的数据,以发现在此过程中是否丢失了任何数据。使用Dangling indices API列出、导入或删除任何悬空索引。
消息 Node was successfully detached from the cluster 并不意味着没有数据丢失,它只是意味着工具能够完成其工作。
参数
edit-
repurpose - 当节点的角色发生更改时,删除多余的数据。
-
unsafe-bootstrap - 指定不安全地引导此节点作为新的单节点集群。
-
detach-cluster - 指定不安全地从其集群中分离此节点,以便它可以加入不同的集群。
-
override-version - 覆盖存储在数据路径中的版本号,以便节点可以在与磁盘数据不兼容的情况下启动。
-
remove-settings - 强制从磁盘集群状态中移除提供的持久化集群设置。
-
-E <KeyValuePair> - 配置一个设置。
-
-h, --help - 返回所有命令参数。
-
-s, --silent - 显示最小输出。
-
-v, --verbose - 显示详细输出。
示例
edit将节点重新用作专用主节点
edit在这个示例中,一个以前的数据节点被重新用作专用主节点。
首先更新节点的设置,将其在 elasticsearch.yml 配置文件中的 node.roles: [ "master" ] 设置。然后运行 elasticsearch-node repurpose 命令以查找并删除多余的碎片数据:
node$ ./bin/elasticsearch-node repurpose
WARNING: Elasticsearch MUST be stopped before running this tool.
Found 2 shards in 2 indices to clean up
Use -v to see list of paths and indices affected
Node is being re-purposed as master and no-data. Clean-up of shard data will be performed.
Do you want to proceed?
Confirm [y/N] y
Node successfully repurposed to master and no-data.
将节点重新用作仅协调节点
edit在这个示例中,一个之前持有数据的节点被重新用作仅协调节点。首先在节点的elasticsearch.yml配置文件中更新设置为node.roles: []。然后运行elasticsearch-node repurpose命令以查找并删除多余的碎片数据和索引元数据:
node$./bin/elasticsearch-node repurpose
WARNING: Elasticsearch MUST be stopped before running this tool.
Found 2 indices (2 shards and 2 index meta data) to clean up
Use -v to see list of paths and indices affected
Node is being re-purposed as no-master and no-data. Clean-up of index data will be performed.
Do you want to proceed?
Confirm [y/N] y
Node successfully repurposed to no-master and no-data.
移除持久化集群设置
edit如果您的节点包含持久化的集群设置,这些设置会阻止集群形成,即无法使用Cluster更新设置 API 删除,您可以运行以下命令来删除一个或多个集群设置。
node$ ./bin/elasticsearch-node remove-settings xpack.monitoring.exporters.my_exporter.host
WARNING: Elasticsearch MUST be stopped before running this tool.
The following settings will be removed:
xpack.monitoring.exporters.my_exporter.host: "10.1.2.3"
You should only run this tool if you have incompatible settings in the
cluster state that prevent the cluster from forming.
This tool can cause data loss and its use should be your last resort.
Do you want to proceed?
Confirm [y/N] y
Settings were successfully removed from the cluster state
您还可以使用通配符来删除多个设置,例如使用
node$ ./bin/elasticsearch-node remove-settings xpack.monitoring.*
移除索引设置
edit如果你的索引包含阻止集群形成的索引设置,你可以运行以下命令来删除一个或多个索引设置。
node$ ./bin/elasticsearch-node remove-index-settings index.my_plugin.foo
WARNING: Elasticsearch MUST be stopped before running this tool.
You should only run this tool if you have incompatible index settings in the
cluster state that prevent the cluster from forming.
This tool can cause data loss and its use should be your last resort.
Do you want to proceed?
Confirm [y/N] y
Index settings were successfully removed from the cluster state
您还可以使用通配符来删除多个索引设置,例如使用
node$ ./bin/elasticsearch-node remove-index-settings index.my_plugin.*
从集群状态中移除自定义元数据
edit如果磁盘上的集群状态包含自定义元数据,导致节点无法启动并加载集群状态,您可以运行以下命令来删除此自定义元数据。
node$ ./bin/elasticsearch-node remove-customs snapshot_lifecycle
WARNING: Elasticsearch MUST be stopped before running this tool.
The following customs will be removed:
snapshot_lifecycle
You should only run this tool if you have broken custom metadata in the
cluster state that prevents the cluster state from being loaded.
This tool can cause data loss and its use should be your last resort.
Do you want to proceed?
Confirm [y/N] y
Customs were successfully removed from the cluster state
不安全的集群引导
edit假设您的集群有五个主节点候选节点,并且您已经永久性地失去了其中三个,只剩下两个节点。
-
在第一个剩余节点上运行该工具,但在确认步骤中回答
n。
node_1$ ./bin/elasticsearch-node unsafe-bootstrap
WARNING: Elasticsearch MUST be stopped before running this tool.
Current node cluster state (term, version) pair is (4, 12)
You should only run this tool if you have permanently lost half or more
of the master-eligible nodes in this cluster, and you cannot restore the
cluster from a snapshot. This tool can cause arbitrary data loss and its
use should be your last resort. If you have multiple surviving master
eligible nodes, you should run this tool on the node with the highest
cluster state (term, version) pair.
Do you want to proceed?
Confirm [y/N] n
-
在剩余的第二个节点上运行该工具,并在确认步骤中再次回答
n。
node_2$ ./bin/elasticsearch-node unsafe-bootstrap
WARNING: Elasticsearch MUST be stopped before running this tool.
Current node cluster state (term, version) pair is (5, 3)
You should only run this tool if you have permanently lost half or more
of the master-eligible nodes in this cluster, and you cannot restore the
cluster from a snapshot. This tool can cause arbitrary data loss and its
use should be your last resort. If you have multiple surviving master
eligible nodes, you should run this tool on the node with the highest
cluster state (term, version) pair.
Do you want to proceed?
Confirm [y/N] n
- 由于第二个节点的术语更大,它具有更新的集群状态,因此最好使用此节点不安全地引导集群:
node_2$ ./bin/elasticsearch-node unsafe-bootstrap
WARNING: Elasticsearch MUST be stopped before running this tool.
Current node cluster state (term, version) pair is (5, 3)
You should only run this tool if you have permanently lost half or more
of the master-eligible nodes in this cluster, and you cannot restore the
cluster from a snapshot. This tool can cause arbitrary data loss and its
use should be your last resort. If you have multiple surviving master
eligible nodes, you should run this tool on the node with the highest
cluster state (term, version) pair.
Do you want to proceed?
Confirm [y/N] y
Master node was successfully bootstrapped
从集群中分离节点
edit在非安全地引导新集群后,运行 elasticsearch-node
detach-cluster 命令以将所有剩余节点从失败的集群中分离,以便它们可以加入新集群:
node_3$ ./bin/elasticsearch-node detach-cluster
WARNING: Elasticsearch MUST be stopped before running this tool.
You should only run this tool if you have permanently lost all of the
master-eligible nodes in this cluster and you cannot restore the cluster
from a snapshot, or you have already unsafely bootstrapped a new cluster
by running `elasticsearch-node unsafe-bootstrap` on a master-eligible
node that belonged to the same cluster as this node. This tool can cause
arbitrary data loss and its use should be your last resort.
Do you want to proceed?
Confirm [y/N] y
Node was successfully detached from the cluster
绕过版本检查
edit运行 elasticsearch-node override-version 命令以覆盖存储在数据路径中的版本,以便节点可以启动,尽管它与数据路径中存储的数据不兼容:
node$ ./bin/elasticsearch-node override-version
WARNING: Elasticsearch MUST be stopped before running this tool.
This data path was last written by Elasticsearch version [x.x.x] and may no
longer be compatible with Elasticsearch version [y.y.y]. This tool will bypass
this compatibility check, allowing a version [y.y.y] node to start on this data
path, but a version [y.y.y] node may not be able to read this data or may read
it incorrectly leading to data loss.
You should not use this tool. Instead, continue to use a version [x.x.x] node
on this data path. If necessary, you can use reindex-from-remote to copy the
data from here into an older cluster.
Do you want to proceed?
Confirm [y/N] y
Successfully overwrote this node's metadata to bypass its version compatibility checks.