cluster-design.asciidoc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. [[high-availability-cluster-design]]
  2. == Designing for resilience
  3. Distributed systems like {es} are designed to keep working even if some of
  4. their components have failed. As long as there are enough well-connected
  5. nodes to take over their responsibilities, an {es} cluster can continue
  6. operating normally if some of its nodes are unavailable or disconnected.
  7. There is a limit to how small a resilient cluster can be. All {es} clusters
  8. require:
  9. * One <<modules-discovery-quorums,elected master node>> node
  10. * At least one node for each <<modules-node,role>>.
  11. * At least one copy of every <<scalability,shard>>.
  12. A resilient cluster requires redundancy for every required cluster component.
  13. This means a resilient cluster must have:
  14. * At least three master-eligible nodes
  15. * At least two nodes of each role
  16. * At least two copies of each shard (one primary and one or more replicas)
  17. A resilient cluster needs three master-eligible nodes so that if one of
  18. them fails then the remaining two still form a majority and can hold a
  19. successful election.
  20. Similarly, redundancy of nodes of each role means that if a node for a
  21. particular role fails, another node can take on its responsibilities.
  22. Finally, a resilient cluster should have at least two copies of each shard. If
  23. one copy fails then there should be another good copy to take over. {es}
  24. automatically rebuilds any failed shard copies on the remaining nodes in order
  25. to restore the cluster to full health after a failure.
  26. Failures temporarily reduce the total capacity of your cluster. In addition,
  27. after a failure the cluster must perform additional background activities to
  28. restore itself to health. You should make sure that your cluster has the
  29. capacity to handle your workload even if some nodes fail.
  30. Depending on your needs and budget, an {es} cluster can consist of a single
  31. node, hundreds of nodes, or any number in between. When designing a smaller
  32. cluster, you should typically focus on making it resilient to single-node
  33. failures. Designers of larger clusters must also consider cases where multiple
  34. nodes fail at the same time. The following pages give some recommendations for
  35. building resilient clusters of various sizes:
  36. * <<high-availability-cluster-small-clusters>>
  37. * <<high-availability-cluster-design-large-clusters>>
  38. [[high-availability-cluster-small-clusters]]
  39. === Resilience in small clusters
  40. In smaller clusters, it is most important to be resilient to single-node
  41. failures. This section gives some guidance on making your cluster as resilient
  42. as possible to the failure of an individual node.
  43. [[high-availability-cluster-design-one-node]]
  44. ==== One-node clusters
  45. If your cluster consists of one node, that single node must do everything.
  46. To accommodate this, {es} assigns nodes every role by default.
  47. A single node cluster is not resilient. If the the node fails, the cluster will
  48. stop working. Because there are no replicas in a one-node cluster, you cannot
  49. store your data redundantly. However, by default at least one replica is
  50. required for a <<cluster-health,`green` cluster health status>>. To ensure your
  51. cluster can report a `green` status, override the default by setting
  52. <<dynamic-index-settings,`index.number_of_replicas`>> to `0` on every index.
  53. If the node fails, you may need to restore an older copy of any lost indices
  54. from a <<modules-snapshots,snapshot>>.
  55. Because they are not resilient to any failures, we do not recommend using
  56. one-node clusters in production.
  57. [[high-availability-cluster-design-two-nodes]]
  58. ==== Two-node clusters
  59. If you have two nodes, we recommend they both be data nodes. You should also
  60. ensure every shard is stored redundantly on both nodes by setting
  61. <<dynamic-index-settings,`index.number_of_replicas`>> to `1` on every index.
  62. This is the default number of replicas but may be overridden by an
  63. <<indices-templates,index template>>. <<dynamic-index-settings,Auto-expand
  64. replicas>> can also achieve the same thing, but it's not necessary to use this
  65. feature in such a small cluster.
  66. We recommend you set `node.master: false` on one of your two nodes so that it is
  67. not <<master-node,master-eligible>>. This means you can be certain which of your
  68. nodes is the elected master of the cluster. The cluster can tolerate the loss of
  69. the other master-ineligible node. If you don't set `node.master: false` on one
  70. node, both nodes are master-eligible. This means both nodes are required for a
  71. master election. Since the election will fail if either node is unavailable,
  72. your cluster cannot reliably tolerate the loss of either node.
  73. By default, each node is assigned every role. We recommend you assign both nodes
  74. all other roles except master eligibility. If one node fails, the other node can
  75. handle its tasks.
  76. You should avoid sending client requests to just one of your nodes. If you do
  77. and this node fails, such requests will not receive responses even if the
  78. remaining node is a healthy cluster on its own. Ideally, you should balance your
  79. client requests across both nodes. A good way to do this is to specify the
  80. addresses of both nodes when configuring the client to connect to your cluster.
  81. Alternatively, you can use a resilient load balancer to balance client requests
  82. across the nodes in your cluster.
  83. Because it's not resilient to failures, we do not recommend deploying a two-node
  84. cluster in production.
  85. [[high-availability-cluster-design-two-nodes-plus]]
  86. ==== Two-node clusters with a tiebreaker
  87. Because master elections are majority-based, the two-node cluster described
  88. above is tolerant to the loss of one of its nodes but not the
  89. other one. You cannot configure a two-node cluster so that it can tolerate
  90. the loss of _either_ node because this is theoretically impossible. You might
  91. expect that if either node fails then {es} can elect the remaining node as the
  92. master, but it is impossible to tell the difference between the failure of a
  93. remote node and a mere loss of connectivity between the nodes. If both nodes
  94. were capable of running independent elections, a loss of connectivity would
  95. lead to a {wikipedia}/Split-brain_(computing)[split-brain
  96. problem] and therefore data loss. {es} avoids this and
  97. protects your data by electing neither node as master until that node can be
  98. sure that it has the latest cluster state and that there is no other master in
  99. the cluster. This could result in the cluster having no master until
  100. connectivity is restored.
  101. You can solve this problem by adding a third node and making all three nodes
  102. master-eligible. A <<modules-discovery-quorums,master election>> requires only
  103. two of the three master-eligible nodes. This means the cluster can tolerate the
  104. loss of any single node. This third node acts as a tiebreaker in cases where the
  105. two original nodes are disconnected from each other. You can reduce the resource
  106. requirements of this extra node by making it a <<voting-only-node,dedicated
  107. voting-only master-eligible node>>, also known as a dedicated tiebreaker.
  108. Because it has no other roles, a dedicated tiebreaker does not need to be as
  109. powerful as the other two nodes. It will not perform any searches nor coordinate
  110. any client requests and cannot be elected as the master of the cluster.
  111. The two original nodes should not be voting-only master-eligible nodes since a
  112. resilient cluster requires at least three master-eligible nodes, at least two
  113. of which are not voting-only master-eligible nodes. If two of your three nodes
  114. are voting-only master-eligible nodes then the elected master must be the third
  115. node. This node then becomes a single point of failure.
  116. We recommend assigning both non-tiebreaker nodes all other roles. This creates
  117. redundancy by ensuring any task in the cluster can be handled by either node.
  118. You should not send any client requests to the dedicated tiebreaker node.
  119. You should also avoid sending client requests to just one of the other two
  120. nodes. If you do, and this node fails, then any requests will not
  121. receive responses, even if the remaining nodes form a healthy cluster. Ideally,
  122. you should balance your client requests across both of the non-tiebreaker
  123. nodes. You can do this by specifying the address of both nodes
  124. when configuring your client to connect to your cluster. Alternatively, you can
  125. use a resilient load balancer to balance client requests across the appropriate
  126. nodes in your cluster. The {ess-trial}[Elastic Cloud] service
  127. provides such a load balancer.
  128. A two-node cluster with an additional tiebreaker node is the smallest possible
  129. cluster that is suitable for production deployments.
  130. [[high-availability-cluster-design-three-nodes]]
  131. ==== Three-node clusters
  132. If you have three nodes, we recommend they all be <<data-node,data
  133. nodes>> and every index should have at least one replica. Nodes are data nodes
  134. by default. You may prefer for some indices to have two replicas so that each
  135. node has a copy of each shard in those indices. You should also configure each
  136. node to be <<master-node,master-eligible>> so that any two of them can hold a
  137. master election without needing to communicate with the third node. Nodes are
  138. master-eligible by default. This cluster will be resilient to the loss of any
  139. single node.
  140. You should avoid sending client requests to just one of your nodes. If you do,
  141. and this node fails, then any requests will not receive responses even if the
  142. remaining two nodes form a healthy cluster. Ideally, you should balance your
  143. client requests across all three nodes. You can do this by specifying the
  144. address of multiple nodes when configuring your client to connect to your
  145. cluster. Alternatively you can use a resilient load balancer to balance client
  146. requests across your cluster. The {ess-trial}[Elastic Cloud]
  147. service provides such a load balancer.
  148. [[high-availability-cluster-design-three-plus-nodes]]
  149. ==== Clusters with more than three nodes
  150. Once your cluster grows to more than three nodes, you can start to specialise
  151. these nodes according to their responsibilities, allowing you to scale their
  152. resources independently as needed. You can have as many <<data-node,data
  153. nodes>>, <<ingest,ingest nodes>>, <<ml-node,{ml} nodes>>, etc. as needed to
  154. support your workload. As your cluster grows larger, we recommend using
  155. dedicated nodes for each role. This lets you to independently scale resources
  156. for each task.
  157. However, it is good practice to limit the number of master-eligible nodes in
  158. the cluster to three. Master nodes do not scale like other node types since
  159. the cluster always elects just one of them as the master of the cluster. If
  160. there are too many master-eligible nodes then master elections may take a
  161. longer time to complete. In larger clusters, we recommend you
  162. configure some of your nodes as dedicated master-eligible nodes and avoid
  163. sending any client requests to these dedicated nodes. Your cluster may become
  164. unstable if the master-eligible nodes are overwhelmed with unnecessary extra
  165. work that could be handled by one of the other nodes.
  166. You may configure one of your master-eligible nodes to be a
  167. <<voting-only-node,voting-only node>> so that it can never be elected as the
  168. master node. For instance, you may have two dedicated master nodes and a third
  169. node that is both a data node and a voting-only master-eligible node. This
  170. third voting-only node will act as a tiebreaker in master elections but will
  171. never become the master itself.
  172. [[high-availability-cluster-design-small-cluster-summary]]
  173. ==== Summary
  174. The cluster will be resilient to the loss of any node as long as:
  175. - The <<cluster-health,cluster health status>> is `green`.
  176. - There are at least two data nodes.
  177. - Every index has at least one replica of each shard, in addition to the
  178. primary.
  179. - The cluster has at least three master-eligible nodes, as long as at least two
  180. of these nodes are not voting-only master-eligible nodes.
  181. - Clients are configured to send their requests to more than one node or are
  182. configured to use a load balancer that balances the requests across an
  183. appropriate set of nodes. The {ess-trial}[Elastic Cloud] service provides such
  184. a load balancer.
  185. [[high-availability-cluster-design-large-clusters]]
  186. === Resilience in larger clusters
  187. It is not unusual for nodes to share some common infrastructure, such as a power
  188. supply or network router. If so, you should plan for the failure of this
  189. infrastructure and ensure that such a failure would not affect too many of your
  190. nodes. It is common practice to group all the nodes sharing some infrastructure
  191. into _zones_ and to plan for the failure of any whole zone at once.
  192. Your cluster’s zones should all be contained within a single data centre. {es}
  193. expects its node-to-node connections to be reliable and have low latency and
  194. high bandwidth. Connections between data centres typically do not meet these
  195. expectations. Although {es} will behave correctly on an unreliable or slow
  196. network, it will not necessarily behave optimally. It may take a considerable
  197. length of time for a cluster to fully recover from a network partition since it
  198. must resynchronize any missing data and rebalance the cluster once the
  199. partition heals. If you want your data to be available in multiple data centres,
  200. deploy a separate cluster in each data centre and use
  201. <<modules-cross-cluster-search,{ccs}>> or <<xpack-ccr,{ccr}>> to link the
  202. clusters together. These features are designed to perform well even if the
  203. cluster-to-cluster connections are less reliable or slower than the network
  204. within each cluster.
  205. After losing a whole zone's worth of nodes, a properly-designed cluster may be
  206. functional but running with significantly reduced capacity. You may need
  207. to provision extra nodes to restore acceptable performance in your
  208. cluster when handling such a failure.
  209. For resilience against whole-zone failures, it is important that there is a copy
  210. of each shard in more than one zone, which can be achieved by placing data
  211. nodes in multiple zones and configuring <<allocation-awareness,shard allocation
  212. awareness>>. You should also ensure that client requests are sent to nodes in
  213. more than one zone.
  214. You should consider all node roles and ensure that each role is split
  215. redundantly across two or more zones. For instance, if you are using
  216. <<ingest,ingest pipelines>> or {ml}, you should have ingest or {ml} nodes in two
  217. or more zones. However, the placement of master-eligible nodes requires a little
  218. more care because a resilient cluster needs at least two of the three
  219. master-eligible nodes in order to function. The following sections explore the
  220. options for placing master-eligible nodes across multiple zones.
  221. [[high-availability-cluster-design-two-zones]]
  222. ==== Two-zone clusters
  223. If you have two zones, you should have a different number of
  224. master-eligible nodes in each zone so that the zone with more nodes will
  225. contain a majority of them and will be able to survive the loss of the other
  226. zone. For instance, if you have three master-eligible nodes then you may put
  227. all of them in one zone or you may put two in one zone and the third in the
  228. other zone. You should not place an equal number of master-eligible nodes in
  229. each zone. If you place the same number of master-eligible nodes in each zone,
  230. neither zone has a majority of its own. Therefore, the cluster may not survive
  231. the loss of either zone.
  232. [[high-availability-cluster-design-two-zones-plus]]
  233. ==== Two-zone clusters with a tiebreaker
  234. The two-zone deployment described above is tolerant to the loss of one of its
  235. zones but not to the loss of the other one because master elections are
  236. majority-based. You cannot configure a two-zone cluster so that it can tolerate
  237. the loss of _either_ zone because this is theoretically impossible. You might
  238. expect that if either zone fails then {es} can elect a node from the remaining
  239. zone as the master but it is impossible to tell the difference between the
  240. failure of a remote zone and a mere loss of connectivity between the zones. If
  241. both zones were capable of running independent elections then a loss of
  242. connectivity would lead to a
  243. {wikipedia}/Split-brain_(computing)[split-brain problem] and
  244. therefore data loss. {es} avoids this and protects your data by not electing
  245. a node from either zone as master until that node can be sure that it has the
  246. latest cluster state and that there is no other master in the cluster. This may
  247. mean there is no master at all until connectivity is restored.
  248. You can solve this by placing one master-eligible node in each of your two
  249. zones and adding a single extra master-eligible node in an independent third
  250. zone. The extra master-eligible node acts as a tiebreaker in cases
  251. where the two original zones are disconnected from each other. The extra
  252. tiebreaker node should be a <<voting-only-node,dedicated voting-only
  253. master-eligible node>>, also known as a dedicated tiebreaker. A dedicated
  254. tiebreaker need not be as powerful as the other two nodes since it has no other
  255. roles and will not perform any searches nor coordinate any client requests nor
  256. be elected as the master of the cluster.
  257. You should use <<allocation-awareness,shard allocation awareness>> to ensure
  258. that there is a copy of each shard in each zone. This means either zone remains
  259. fully available if the other zone fails.
  260. All master-eligible nodes, including voting-only nodes, are on the critical path
  261. for publishing cluster state updates. Because of this, these nodes require
  262. reasonably fast persistent storage and a reliable, low-latency network
  263. connection to the rest of the cluster. If you add a tiebreaker node in a third
  264. independent zone then you must make sure it has adequate resources and good
  265. connectivity to the rest of the cluster.
  266. [[high-availability-cluster-design-three-zones]]
  267. ==== Clusters with three or more zones
  268. If you have three zones then you should have one master-eligible node in each
  269. zone. If you have more than three zones then you should choose three of the
  270. zones and put a master-eligible node in each of these three zones. This will
  271. mean that the cluster can still elect a master even if one of the zones fails.
  272. As always, your indices should have at least one replica in case a node fails.
  273. You should also use <<allocation-awareness,shard allocation awareness>> to
  274. limit the number of copies of each shard in each zone. For instance, if you have
  275. an index with one or two replicas configured then allocation awareness will
  276. ensure that the replicas of the shard are in a different zone from the primary.
  277. This means that a copy of every shard will still be available if one zone
  278. fails. The availability of this shard will not be affected by such a
  279. failure.
  280. [[high-availability-cluster-design-large-cluster-summary]]
  281. ==== Summary
  282. The cluster will be resilient to the loss of any zone as long as:
  283. - The <<cluster-health,cluster health status>> is `green`.
  284. - There are at least two zones containing data nodes.
  285. - Every index has at least one replica of each shard, in addition to the
  286. primary.
  287. - Shard allocation awareness is configured to avoid concentrating all copies of
  288. a shard within a single zone.
  289. - The cluster has at least three master-eligible nodes. At least two of these
  290. nodes are not voting-only master-eligible nodes, and they are spread evenly
  291. across at least three zones.
  292. - Clients are configured to send their requests to nodes in more than one zone
  293. or are configured to use a load balancer that balances the requests across an
  294. appropriate set of nodes. The {ess-trial}[Elastic Cloud] service provides such
  295. a load balancer.