allocation_awareness.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. [[allocation-awareness]]
  2. === Shard allocation awareness
  3. You can use custom node attributes as _awareness attributes_ to enable {es}
  4. to take your physical hardware configuration into account when allocating shards.
  5. If {es} knows which nodes are on the same physical server, in the same rack, or
  6. in the same zone, it can distribute the primary shard and its replica shards to
  7. minimise the risk of losing all shard copies in the event of a failure.
  8. When shard allocation awareness is enabled with the
  9. `cluster.routing.allocation.awareness.attributes` setting, shards are only
  10. allocated to nodes that have values set for the specified awareness
  11. attributes. If you use multiple awareness attributes, {es} considers
  12. each attribute separately when allocating shards.
  13. The allocation awareness settings can be configured in
  14. `elasticsearch.yml` and updated dynamically with the
  15. <<cluster-update-settings,cluster-update-settings>> API.
  16. {es} prefers using shards in the same location (with the same
  17. awareness attribute values) to process search or GET requests. Using local
  18. shards is usually faster than crossing rack or zone boundaries.
  19. NOTE: The number of attribute values determines how many shard copies are
  20. allocated in each location. If the number of nodes in each location is
  21. unbalanced and there are a lot of replicas, replica shards might be left
  22. unassigned.
  23. [float]
  24. [[enabling-awareness]]
  25. ==== Enabling shard allocation awareness
  26. To enable shard allocation awareness:
  27. . Specify the location of each node with a custom node attribute. For example,
  28. if you want Elasticsearch to distribute shards across different racks, you might
  29. set an awareness attribute called `rack_id` in each node's `elasticsearch.yml`
  30. config file.
  31. +
  32. [source,yaml]
  33. --------------------------------------------------------
  34. node.attr.rack_id: rack_one
  35. --------------------------------------------------------
  36. +
  37. You can also set custom attributes when you start a node:
  38. +
  39. [source,sh]
  40. --------------------------------------------------------
  41. `./bin/elasticsearch -Enode.attr.rack_id=rack_one`
  42. --------------------------------------------------------
  43. . Tell {es} to take one or more awareness attributes into account when
  44. allocating shards by setting
  45. `cluster.routing.allocation.awareness.attributes` in *every* master-eligible
  46. node's `elasticsearch.yml` config file.
  47. +
  48. --
  49. [source,yaml]
  50. --------------------------------------------------------
  51. cluster.routing.allocation.awareness.attributes: rack_id <1>
  52. --------------------------------------------------------
  53. <1> Specify multiple attributes as a comma-separated list.
  54. --
  55. +
  56. You can also use the
  57. <<cluster-update-settings,cluster-update-settings>> API to set or update
  58. a cluster's awareness attributes.
  59. With this example configuration, if you start two nodes with
  60. `node.attr.rack_id` set to `rack_one` and create an index with 5 primary
  61. shards and 1 replica of each primary, all primaries and replicas are
  62. allocated across the two nodes.
  63. If you add two nodes with `node.attr.rack_id` set to `rack_two`,
  64. {es} moves shards to the new nodes, ensuring (if possible)
  65. that no two copies of the same shard are in the same rack.
  66. If `rack_two` fails and takes down both its nodes, by default {es}
  67. allocates the lost shard copies to nodes in `rack_one`. To prevent multiple
  68. copies of a particular shard from being allocated in the same location, you can
  69. enable forced awareness.
  70. [float]
  71. [[forced-awareness]]
  72. ==== Forced awareness
  73. By default, if one location fails, Elasticsearch assigns all of the missing
  74. replica shards to the remaining locations. While you might have sufficient
  75. resources across all locations to host your primary and replica shards, a single
  76. location might be unable to host *ALL* of the shards.
  77. To prevent a single location from being overloaded in the event of a failure,
  78. you can set `cluster.routing.allocation.awareness.force` so no replicas are
  79. allocated until nodes are available in another location.
  80. For example, if you have an awareness attribute called `zone` and configure nodes
  81. in `zone1` and `zone2`, you can use forced awareness to prevent Elasticsearch
  82. from allocating replicas if only one zone is available:
  83. [source,yaml]
  84. -------------------------------------------------------------------
  85. cluster.routing.allocation.awareness.attributes: zone
  86. cluster.routing.allocation.awareness.force.zone.values: zone1,zone2 <1>
  87. -------------------------------------------------------------------
  88. <1> Specify all possible values for the awareness attribute.
  89. With this example configuration, if you start two nodes with `node.attr.zone` set
  90. to `zone1` and create an index with 5 shards and 1 replica, Elasticsearch creates
  91. the index and allocates the 5 primary shards but no replicas. Replicas are
  92. only allocated once nodes with `node.attr.zone` set to `zone2` are available.