node-tool.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. [[node-tool]]
  2. == elasticsearch-node
  3. The `elasticsearch-node` command enables you to perform certain unsafe
  4. operations on a node that are only possible while it is shut down. This command
  5. allows you to adjust the <<modules-node,role>> of a node and may be able to
  6. recover some data after a disaster.
  7. [float]
  8. === Synopsis
  9. [source,shell]
  10. --------------------------------------------------
  11. bin/elasticsearch-node repurpose|unsafe-bootstrap|detach-cluster
  12. [--ordinal <Integer>] [-E <KeyValuePair>]
  13. [-h, --help] ([-s, --silent] | [-v, --verbose])
  14. --------------------------------------------------
  15. [float]
  16. === Description
  17. This tool has three modes:
  18. * `elasticsearch-node repurpose` can be used to delete unwanted data from a
  19. node if it used to be a <<data-node,data node>> or a
  20. <<master-node,master-eligible node>> but has been repurposed not to have one
  21. or other of these roles.
  22. * `elasticsearch-node unsafe-bootstrap` can be used to perform _unsafe cluster
  23. bootstrapping_. It forces one of the nodes to form a brand-new cluster on
  24. its own, using its local copy of the cluster metadata.
  25. * `elasticsearch-node detach-cluster` enables you to move nodes from one
  26. cluster to another. This can be used to move nodes into a new cluster
  27. created with the `elasticsearch-node unsafe-bootstap` command. If unsafe
  28. cluster bootstrapping was not possible, it also enables you to move nodes
  29. into a brand-new cluster.
  30. [[node-tool-repurpose]]
  31. [float]
  32. ==== Changing the role of a node
  33. There may be situations where you want to repurpose a node without following
  34. the <<change-node-role,proper repurposing processes>>. The `elasticsearch-node
  35. repurpose` tool allows you to delete any excess on-disk data and start a node
  36. after repurposing it.
  37. The intended use is:
  38. * Stop the node
  39. * Update `elasticsearch.yml` by setting `node.master` and `node.data` as
  40. desired.
  41. * Run `elasticsearch-node repurpose` on the node
  42. * Start the node
  43. If you run `elasticsearch-node repurpose` on a node with `node.data: false` and
  44. `node.master: true` then it will delete any remaining shard data on that node,
  45. but it will leave the index and cluster metadata alone. If you run
  46. `elasticsearch-node repurpose` on a node with `node.data: false` and
  47. `node.master: false` then it will delete any remaining shard data and index
  48. metadata, but it will leave the cluster metadata alone.
  49. [WARNING]
  50. Running this command can lead to data loss for the indices mentioned if the
  51. data contained is not available on other nodes in the cluster. Only run this
  52. tool if you understand and accept the possible consequences, and only after
  53. determining that the node cannot be repurposed cleanly.
  54. The tool provides a summary of the data to be deleted and asks for confirmation
  55. before making any changes. You can get detailed information about the affected
  56. indices and shards by passing the verbose (`-v`) option.
  57. [float]
  58. ==== Recovering data after a disaster
  59. Sometimes {es} nodes are temporarily stopped, perhaps because of the need to
  60. perform some maintenance activity or perhaps because of a hardware failure.
  61. After you resolve the temporary condition and restart the node,
  62. it will rejoin the cluster and continue normally. Depending on your
  63. configuration, your cluster may be able to remain completely available even
  64. while one or more of its nodes are stopped.
  65. Sometimes it might not be possible to restart a node after it has stopped. For
  66. example, the node's host may suffer from a hardware problem that cannot be
  67. repaired. If the cluster is still available then you can start up a fresh node
  68. on another host and {es} will bring this node into the cluster in place of the
  69. failed node.
  70. Each node stores its data in the data directories defined by the
  71. <<path-settings,`path.data` setting>>. This means that in a disaster you can
  72. also restart a node by moving its data directories to another host, presuming
  73. that those data directories can be recovered from the faulty host.
  74. {es} <<modules-discovery-quorums,requires a response from a majority of the
  75. master-eligible nodes>> in order to elect a master and to update the cluster
  76. state. This means that if you have three master-eligible nodes then the cluster
  77. will remain available even if one of them has failed. However if two of the
  78. three master-eligible nodes fail then the cluster will be unavailable until at
  79. least one of them is restarted.
  80. In very rare circumstances it may not be possible to restart enough nodes to
  81. restore the cluster's availability. If such a disaster occurs, you should
  82. build a new cluster from a recent snapshot and re-import any data that was
  83. ingested since that snapshot was taken.
  84. However, if the disaster is serious enough then it may not be possible to
  85. recover from a recent snapshot either. Unfortunately in this case there is no
  86. way forward that does not risk data loss, but it may be possible to use the
  87. `elasticsearch-node` tool to construct a new cluster that contains some of the
  88. data from the failed cluster.
  89. [[node-tool-unsafe-bootstrap]]
  90. [float]
  91. ===== Unsafe cluster bootstrapping
  92. If there is at least one remaining master-eligible node, but it is not possible
  93. to restart a majority of them, then the `elasticsearch-node unsafe-bootstrap`
  94. command will unsafely override the cluster's <<modules-discovery-voting,voting
  95. configuration>> as if performing another
  96. <<modules-discovery-bootstrap-cluster,cluster bootstrapping process>>.
  97. The target node can then form a new cluster on its own by using
  98. the cluster metadata held locally on the target node.
  99. [WARNING]
  100. These steps can lead to arbitrary data loss since the target node may not hold the latest cluster
  101. metadata, and this out-of-date metadata may make it impossible to use some or
  102. all of the indices in the cluster.
  103. Since unsafe bootstrapping forms a new cluster containing a single node, once
  104. you have run it you must use the <<node-tool-detach-cluster,`elasticsearch-node
  105. detach-cluster` tool>> to migrate any other surviving nodes from the failed
  106. cluster into this new cluster.
  107. When you run the `elasticsearch-node unsafe-bootstrap` tool it will analyse the
  108. state of the node and ask for confirmation before taking any action. Before
  109. asking for confirmation it reports the term and version of the cluster state on
  110. the node on which it runs as follows:
  111. [source,txt]
  112. ----
  113. Current node cluster state (term, version) pair is (4, 12)
  114. ----
  115. If you have a choice of nodes on which to run this tool then you should choose
  116. one with a term that is as large as possible. If there is more than one
  117. node with the same term, pick the one with the largest version.
  118. This information identifies the node with the freshest cluster state, which minimizes the
  119. quantity of data that might be lost. For example, if the first node reports
  120. `(4, 12)` and a second node reports `(5, 3)`, then the second node is preferred
  121. since its term is larger. However if the second node reports `(3, 17)` then
  122. the first node is preferred since its term is larger. If the second node
  123. reports `(4, 10)` then it has the same term as the first node, but has a
  124. smaller version, so the first node is preferred.
  125. [WARNING]
  126. Running this command can lead to arbitrary data loss. Only run this tool if you
  127. understand and accept the possible consequences and have exhausted all other
  128. possibilities for recovery of your cluster.
  129. The sequence of operations for using this tool are as follows:
  130. 1. Make sure you have really lost access to at least half of the
  131. master-eligible nodes in the cluster, and they cannot be repaired or recovered
  132. by moving their data paths to healthy hardware.
  133. 2. Stop **all** remaining nodes.
  134. 3. Choose one of the remaining master-eligible nodes to become the new elected
  135. master as described above.
  136. 4. On this node, run the `elasticsearch-node unsafe-bootstrap` command as shown
  137. below. Verify that the tool reported `Master node was successfully
  138. bootstrapped`.
  139. 5. Start this node and verify that it is elected as the master node.
  140. 6. Run the <<node-tool-detach-cluster,`elasticsearch-node detach-cluster`
  141. tool>>, described below, on every other node in the cluster.
  142. 7. Start all other nodes and verify that each one joins the cluster.
  143. 8. Investigate the data in the cluster to discover if any was lost during this
  144. process.
  145. When you run the tool it will make sure that the node that is being used to
  146. bootstrap the cluster is not running. It is important that all other
  147. master-eligible nodes are also stopped while this tool is running, but the tool
  148. does not check this.
  149. The message `Master node was successfully bootstrapped` does not mean that
  150. there has been no data loss, it just means that tool was able to complete its
  151. job.
  152. [[node-tool-detach-cluster]]
  153. [float]
  154. ===== Detaching nodes from their cluster
  155. It is unsafe for nodes to move between clusters, because different clusters
  156. have completely different cluster metadata. There is no way to safely merge the
  157. metadata from two clusters together.
  158. To protect against inadvertently joining the wrong cluster, each cluster
  159. creates a unique identifier, known as the _cluster UUID_, when it first starts
  160. up. Every node records the UUID of its cluster and refuses to join a
  161. cluster with a different UUID.
  162. However, if a node's cluster has permanently failed then it may be desirable to
  163. try and move it into a new cluster. The `elasticsearch-node detach-cluster`
  164. command lets you detach a node from its cluster by resetting its cluster UUID.
  165. It can then join another cluster with a different UUID.
  166. For example, after unsafe cluster bootstrapping you will need to detach all the
  167. other surviving nodes from their old cluster so they can join the new,
  168. unsafely-bootstrapped cluster.
  169. Unsafe cluster bootstrapping is only possible if there is at least one
  170. surviving master-eligible node. If there are no remaining master-eligible nodes
  171. then the cluster metadata is completely lost. However, the individual data
  172. nodes also contain a copy of the index metadata corresponding with their
  173. shards. This sometimes allows a new cluster to import these shards as
  174. <<modules-gateway-dangling-indices,dangling indices>>. You can sometimes
  175. recover some indices after the loss of all master-eligible nodes in a cluster
  176. by creating a new cluster and then using the `elasticsearch-node
  177. detach-cluster` command to move any surviving nodes into this new cluster.
  178. There is a risk of data loss when importing a dangling index because data nodes
  179. may not have the most recent copy of the index metadata and do not have any
  180. information about <<docs-replication,which shard copies are in-sync>>. This
  181. means that a stale shard copy may be selected to be the primary, and some of
  182. the shards may be incompatible with the imported mapping.
  183. [WARNING]
  184. Execution of this command can lead to arbitrary data loss. Only run this tool
  185. if you understand and accept the possible consequences and have exhausted all
  186. other possibilities for recovery of your cluster.
  187. The sequence of operations for using this tool are as follows:
  188. 1. Make sure you have really lost access to every one of the master-eligible
  189. nodes in the cluster, and they cannot be repaired or recovered by moving their
  190. data paths to healthy hardware.
  191. 2. Start a new cluster and verify that it is healthy. This cluster may comprise
  192. one or more brand-new master-eligible nodes, or may be an unsafely-bootstrapped
  193. cluster formed as described above.
  194. 3. Stop **all** remaining data nodes.
  195. 4. On each data node, run the `elasticsearch-node detach-cluster` tool as shown
  196. below. Verify that the tool reported `Node was successfully detached from the
  197. cluster`.
  198. 5. If necessary, configure each data node to
  199. <<modules-discovery-hosts-providers,discover the new cluster>>.
  200. 6. Start each data node and verify that it has joined the new cluster.
  201. 7. Wait for all recoveries to have completed, and investigate the data in the
  202. cluster to discover if any was lost during this process.
  203. The message `Node was successfully detached from the cluster` does not mean
  204. that there has been no data loss, it just means that tool was able to complete
  205. its job.
  206. [float]
  207. === Parameters
  208. `repurpose`:: Delete excess data when a node's roles are changed.
  209. `unsafe-bootstrap`:: Specifies to unsafely bootstrap this node as a new
  210. one-node cluster.
  211. `detach-cluster`:: Specifies to unsafely detach this node from its cluster so
  212. it can join a different cluster.
  213. `--ordinal <Integer>`:: If there is <<max-local-storage-nodes,more than one
  214. node sharing a data path>> then this specifies which node to target. Defaults
  215. to `0`, meaning to use the first node in the data path.
  216. `-E <KeyValuePair>`:: Configures a setting.
  217. `-h, --help`:: Returns all of the command parameters.
  218. `-s, --silent`:: Shows minimal output.
  219. `-v, --verbose`:: Shows verbose output.
  220. [float]
  221. === Examples
  222. [float]
  223. ==== Repurposing a node as a dedicated master node (master: true, data: false)
  224. In this example, a former data node is repurposed as a dedicated master node.
  225. First update the node's settings to `node.master: true` and `node.data: false`
  226. in its `elasticsearch.yml` config file. Then run the `elasticsearch-node
  227. repurpose` command to find and remove excess shard data:
  228. [source,txt]
  229. ----
  230. node$ ./bin/elasticsearch-node repurpose
  231. WARNING: Elasticsearch MUST be stopped before running this tool.
  232. Found 2 shards in 2 indices to clean up
  233. Use -v to see list of paths and indices affected
  234. Node is being re-purposed as master and no-data. Clean-up of shard data will be performed.
  235. Do you want to proceed?
  236. Confirm [y/N] y
  237. Node successfully repurposed to master and no-data.
  238. ----
  239. [float]
  240. ==== Repurposing a node as a coordinating-only node (master: false, data: false)
  241. In this example, a node that previously held data is repurposed as a
  242. coordinating-only node. First update the node's settings to `node.master:
  243. false` and `node.data: false` in its `elasticsearch.yml` config file. Then run
  244. the `elasticsearch-node repurpose` command to find and remove excess shard data
  245. and index metadata:
  246. [source,txt]
  247. ----
  248. node$./bin/elasticsearch-node repurpose
  249. WARNING: Elasticsearch MUST be stopped before running this tool.
  250. Found 2 indices (2 shards and 2 index meta data) to clean up
  251. Use -v to see list of paths and indices affected
  252. Node is being re-purposed as no-master and no-data. Clean-up of index data will be performed.
  253. Do you want to proceed?
  254. Confirm [y/N] y
  255. Node successfully repurposed to no-master and no-data.
  256. ----
  257. [float]
  258. ==== Unsafe cluster bootstrapping
  259. Suppose your cluster had five master-eligible nodes and you have permanently
  260. lost three of them, leaving two nodes remaining.
  261. * Run the tool on the first remaining node, but answer `n` at the confirmation
  262. step.
  263. [source,txt]
  264. ----
  265. node_1$ ./bin/elasticsearch-node unsafe-bootstrap
  266. WARNING: Elasticsearch MUST be stopped before running this tool.
  267. Current node cluster state (term, version) pair is (4, 12)
  268. You should only run this tool if you have permanently lost half or more
  269. of the master-eligible nodes in this cluster, and you cannot restore the
  270. cluster from a snapshot. This tool can cause arbitrary data loss and its
  271. use should be your last resort. If you have multiple surviving master
  272. eligible nodes, you should run this tool on the node with the highest
  273. cluster state (term, version) pair.
  274. Do you want to proceed?
  275. Confirm [y/N] n
  276. ----
  277. * Run the tool on the second remaining node, and again answer `n` at the
  278. confirmation step.
  279. [source,txt]
  280. ----
  281. node_2$ ./bin/elasticsearch-node unsafe-bootstrap
  282. WARNING: Elasticsearch MUST be stopped before running this tool.
  283. Current node cluster state (term, version) pair is (5, 3)
  284. You should only run this tool if you have permanently lost half or more
  285. of the master-eligible nodes in this cluster, and you cannot restore the
  286. cluster from a snapshot. This tool can cause arbitrary data loss and its
  287. use should be your last resort. If you have multiple surviving master
  288. eligible nodes, you should run this tool on the node with the highest
  289. cluster state (term, version) pair.
  290. Do you want to proceed?
  291. Confirm [y/N] n
  292. ----
  293. * Since the second node has a greater term it has a fresher cluster state, so
  294. it is better to unsafely bootstrap the cluster using this node:
  295. [source,txt]
  296. ----
  297. node_2$ ./bin/elasticsearch-node unsafe-bootstrap
  298. WARNING: Elasticsearch MUST be stopped before running this tool.
  299. Current node cluster state (term, version) pair is (5, 3)
  300. You should only run this tool if you have permanently lost half or more
  301. of the master-eligible nodes in this cluster, and you cannot restore the
  302. cluster from a snapshot. This tool can cause arbitrary data loss and its
  303. use should be your last resort. If you have multiple surviving master
  304. eligible nodes, you should run this tool on the node with the highest
  305. cluster state (term, version) pair.
  306. Do you want to proceed?
  307. Confirm [y/N] y
  308. Master node was successfully bootstrapped
  309. ----
  310. [float]
  311. ==== Detaching nodes from their cluster
  312. After unsafely bootstrapping a new cluster, run the `elasticsearch-node
  313. detach-cluster` command to detach all remaining nodes from the failed cluster
  314. so they can join the new cluster:
  315. [source, txt]
  316. ----
  317. node_3$ ./bin/elasticsearch-node detach-cluster
  318. WARNING: Elasticsearch MUST be stopped before running this tool.
  319. You should only run this tool if you have permanently lost all of the
  320. master-eligible nodes in this cluster and you cannot restore the cluster
  321. from a snapshot, or you have already unsafely bootstrapped a new cluster
  322. by running `elasticsearch-node unsafe-bootstrap` on a master-eligible
  323. node that belonged to the same cluster as this node. This tool can cause
  324. arbitrary data loss and its use should be your last resort.
  325. Do you want to proceed?
  326. Confirm [y/N] y
  327. Node was successfully detached from the cluster
  328. ----