discovery-ec2.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. [[discovery-ec2]]
  2. === EC2 Discovery Plugin
  3. The EC2 discovery plugin provides a list of seed addresses to the
  4. {ref}/modules-discovery-hosts-providers.html[discovery process] by querying the
  5. https://github.com/aws/aws-sdk-java[AWS API] for a list of EC2 instances
  6. matching certain criteria determined by the <<discovery-ec2-usage,plugin
  7. settings>>.
  8. *If you are looking for a hosted solution of {es} on AWS, please visit
  9. http://www.elastic.co/cloud.*
  10. :plugin_name: discovery-ec2
  11. include::install_remove.asciidoc[]
  12. [[discovery-ec2-usage]]
  13. ==== Using the EC2 discovery plugin
  14. The `discovery-ec2` plugin allows {es} to find the master-eligible nodes in a
  15. cluster running on AWS EC2 by querying the
  16. https://github.com/aws/aws-sdk-java[AWS API] for the addresses of the EC2
  17. instances running these nodes.
  18. It is normally a good idea to restrict the discovery process just to the
  19. master-eligible nodes in the cluster. This plugin allows you to identify these
  20. nodes by certain criteria including their tags, their membership of security
  21. groups, and their placement within availability zones. The discovery process
  22. will work correctly even if it finds master-ineligible nodes, but master
  23. elections will be more efficient if this can be avoided.
  24. The interaction with the AWS API can be authenticated using the
  25. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[instance
  26. role], or else custom credentials can be supplied.
  27. ===== Enabling EC2 discovery
  28. To enable EC2 discovery, configure {es} to use the `ec2` seed hosts provider:
  29. [source,yaml]
  30. ----
  31. discovery.seed_providers: ec2
  32. ----
  33. ===== Configuring EC2 discovery
  34. EC2 discovery supports a number of settings. Some settings are sensitive and
  35. must be stored in the {ref}/secure-settings.html[{es} keystore]. For example,
  36. to authenticate using a particular access key and secret key, add these keys to
  37. the keystore by running the following commands:
  38. [source,sh]
  39. ----
  40. bin/elasticsearch-keystore add discovery.ec2.access_key
  41. bin/elasticsearch-keystore add discovery.ec2.secret_key
  42. ----
  43. The available settings for the EC2 discovery plugin are as follows.
  44. `discovery.ec2.access_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  45. An EC2 access key. If set, you must also set `discovery.ec2.secret_key`.
  46. If unset, `discovery-ec2` will instead use the instance role. This setting
  47. is sensitive and must be stored in the {es} keystore.
  48. `discovery.ec2.secret_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  49. An EC2 secret key. If set, you must also set `discovery.ec2.access_key`.
  50. This setting is sensitive and must be stored in the {es} keystore.
  51. `discovery.ec2.session_token` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  52. An EC2 session token. If set, you must also set `discovery.ec2.access_key`
  53. and `discovery.ec2.secret_key`. This setting is sensitive and must be
  54. stored in the {es} keystore.
  55. `discovery.ec2.endpoint`::
  56. The EC2 service endpoint to which to connect. See
  57. http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region to find
  58. the appropriate endpoint for the region. This setting defaults to
  59. `ec2.us-east-1.amazonaws.com` which is appropriate for clusters running in
  60. the `us-east-1` region.
  61. `discovery.ec2.protocol`::
  62. The protocol to use to connect to the EC2 service endpoint, which may be
  63. either `http` or `https`. Defaults to `https`.
  64. `discovery.ec2.proxy.host`::
  65. The address or host name of an HTTP proxy through which to connect to EC2.
  66. If not set, no proxy is used.
  67. `discovery.ec2.proxy.port`::
  68. When the address of an HTTP proxy is given in `discovery.ec2.proxy.host`,
  69. this setting determines the port to use to connect to the proxy. Defaults to
  70. `80`.
  71. `discovery.ec2.proxy.username` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  72. When the address of an HTTP proxy is given in `discovery.ec2.proxy.host`,
  73. this setting determines the username to use to connect to the proxy. When
  74. not set, no username is used. This setting is sensitive and must be stored
  75. in the {es} keystore.
  76. `discovery.ec2.proxy.password` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  77. When the address of an HTTP proxy is given in `discovery.ec2.proxy.host`,
  78. this setting determines the password to use to connect to the proxy. When
  79. not set, no password is used. This setting is sensitive and must be stored
  80. in the {es} keystore.
  81. `discovery.ec2.read_timeout`::
  82. The socket timeout for connections to EC2,
  83. {ref}/common-options.html#time-units[including the units]. For example, a
  84. value of `60s` specifies a 60-second timeout. Defaults to 50 seconds.
  85. `discovery.ec2.groups`::
  86. A list of the names or IDs of the security groups to use for discovery. The
  87. `discovery.ec2.any_group` setting determines the behaviour of this setting.
  88. Defaults to an empty list, meaning that security group membership is
  89. ignored by EC2 discovery.
  90. `discovery.ec2.any_group`::
  91. Defaults to `true`, meaning that instances belonging to _any_ of the
  92. security groups specified in `discovery.ec2.groups` will be used for
  93. discovery. If set to `false`, only instances that belong to _all_ of the
  94. security groups specified in `discovery.ec2.groups` will be used for
  95. discovery.
  96. `discovery.ec2.host_type`::
  97. +
  98. --
  99. Each EC2 instance has a number of different addresses that might be suitable
  100. for discovery. This setting allows you to select which of these addresses is
  101. used by the discovery process. It can be set to one of `private_ip`,
  102. `public_ip`, `private_dns`, `public_dns` or `tag:TAGNAME` where `TAGNAME`
  103. refers to a name of a tag. This setting defaults to `private_ip`.
  104. If you set `discovery.ec2.host_type` to a value of the form `tag:TAGNAME` then
  105. the value of the tag `TAGNAME` attached to each instance will be used as that
  106. instance's address for discovery. Instances which do not have this tag set will
  107. be ignored by the discovery process.
  108. For example if you tag some EC2 instances with a tag named
  109. `elasticsearch-host-name` and set `host_type: tag:elasticsearch-host-name` then
  110. the `discovery-ec2` plugin will read each instance's host name from the value
  111. of the `elasticsearch-host-name` tag.
  112. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[Read more
  113. about EC2 Tags].
  114. --
  115. `discovery.ec2.availability_zones`::
  116. A list of the names of the availability zones to use for discovery. The
  117. name of an availability zone is the
  118. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html[region
  119. code followed by a letter], such as `us-east-1a`. Only instances placed in
  120. one of the given availability zones will be used for discovery.
  121. [[discovery-ec2-filtering]]
  122. `discovery.ec2.tag.TAGNAME`::
  123. +
  124. --
  125. A list of the values of a tag called `TAGNAME` to use for discovery. If set,
  126. only instances that are tagged with one of the given values will be used for
  127. discovery. For instance, the following settings will only use nodes with a
  128. `role` tag set to `master` and an `environment` tag set to either `dev` or
  129. `staging`.
  130. [source,yaml]
  131. ----
  132. discovery.ec2.tag.role: master
  133. discovery.ec2.tag.environment: dev,staging
  134. ----
  135. NOTE: The names of tags used for discovery may only contain ASCII letters,
  136. numbers, hyphens and underscores. In particular you cannot use tags whose name
  137. includes a colon.
  138. --
  139. `discovery.ec2.node_cache_time`::
  140. Sets the length of time for which the collection of discovered instances is
  141. cached. {es} waits at least this long between requests for discovery
  142. information from the EC2 API. AWS may reject discovery requests if they are
  143. made too often, and this would cause discovery to fail. Defaults to `10s`.
  144. All **secure** settings of this plugin are
  145. {ref}/secure-settings.html#reloadable-secure-settings[reloadable], allowing you
  146. to update the secure settings for this plugin without needing to restart each
  147. node.
  148. [[discovery-ec2-permissions]]
  149. ===== Recommended EC2 permissions
  150. The `discovery-ec2` plugin works by making a `DescribeInstances` call to the AWS
  151. EC2 API. You must configure your AWS account to allow this, which is normally
  152. done using an IAM policy. You can create a custom policy via the IAM Management
  153. Console. It should look similar to this.
  154. [source,js]
  155. ----
  156. {
  157. "Statement": [
  158. {
  159. "Action": [
  160. "ec2:DescribeInstances"
  161. ],
  162. "Effect": "Allow",
  163. "Resource": [
  164. "*"
  165. ]
  166. }
  167. ],
  168. "Version": "2012-10-17"
  169. }
  170. ----
  171. // NOTCONSOLE
  172. [[discovery-ec2-attributes]]
  173. ===== Automatic node attributes
  174. The `discovery-ec2` plugin can automatically set the `aws_availability_zone`
  175. node attribute to the availability zone of each node. This node attribute
  176. allows you to ensure that each shard has copies allocated redundantly across
  177. multiple availability zones by using the
  178. {ref}/allocation-awareness.html[Allocation Awareness] feature.
  179. In order to enable the automatic definition of the `aws_availability_zone`
  180. attribute, set `cloud.node.auto_attributes` to `true`. For example:
  181. [source,yaml]
  182. ----
  183. cloud.node.auto_attributes: true
  184. cluster.routing.allocation.awareness.attributes: aws_availability_zone
  185. ----
  186. The `aws_availability_zone` attribute can be automatically set like this when
  187. using any discovery type. It is not necessary to set `discovery.seed_providers:
  188. ec2`. However this feature does require that the `discovery-ec2` plugin is
  189. installed.
  190. [[discovery-ec2-network-host]]
  191. ===== Binding to the correct address
  192. It is important to define `network.host` correctly when deploying a cluster on
  193. EC2. By default each {es} node only binds to `localhost`, which will prevent it
  194. from being discovered by nodes running on any other instances.
  195. You can use the {ref}/modules-network.html[core network host settings] to bind
  196. each node to the desired address, or you can set `network.host` to one of the
  197. following EC2-specific settings provided by the `discovery-ec2` plugin:
  198. [cols="<,<",options="header",]
  199. |==================================================================
  200. |EC2 Host Value |Description
  201. |`_ec2:privateIpv4_` |The private IP address (ipv4) of the machine.
  202. |`_ec2:privateDns_` |The private host of the machine.
  203. |`_ec2:publicIpv4_` |The public IP address (ipv4) of the machine.
  204. |`_ec2:publicDns_` |The public host of the machine.
  205. |`_ec2:privateIp_` |Equivalent to `_ec2:privateIpv4_`.
  206. |`_ec2:publicIp_` |Equivalent to `_ec2:publicIpv4_`.
  207. |`_ec2_` |Equivalent to `_ec2:privateIpv4_`.
  208. |==================================================================
  209. These values are acceptable when using any discovery type. They do not require
  210. you to set `discovery.seed_providers: ec2`. However they do require that the
  211. `discovery-ec2` plugin is installed.
  212. [[cloud-aws-best-practices]]
  213. ==== Best Practices in AWS
  214. This section contains some other information about designing and managing an
  215. {es} cluster on your own AWS infrastructure. If you would prefer to avoid these
  216. operational details then you may be interested in a hosted {es} installation
  217. available on AWS-based infrastructure from http://www.elastic.co/cloud.
  218. ===== Storage
  219. EC2 instances offer a number of different kinds of storage. Please be aware of
  220. the folowing when selecting the storage for your cluster:
  221. * http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html[Instance
  222. Store] is recommended for {es} clusters as it offers excellent performance and
  223. is cheaper than EBS-based storage. {es} is designed to work well with this kind
  224. of ephemeral storage because it replicates each shard across multiple nodes. If
  225. a node fails and its Instance Store is lost then {es} will rebuild any lost
  226. shards from other copies.
  227. * https://aws.amazon.com/ebs/[EBS-based storage] may be acceptable
  228. for smaller clusters (1-2 nodes). Be sure to use provisioned IOPS to ensure
  229. your cluster has satisfactory performance.
  230. * https://aws.amazon.com/efs/[EFS-based storage] is not
  231. recommended or supported as it does not offer satisfactory performance.
  232. Historically, shared network filesystems such as EFS have not always offered
  233. precisely the behaviour that {es} requires of its filesystem, and this has been
  234. known to lead to index corruption. Although EFS offers durability, shared
  235. storage, and the ability to grow and shrink filesystems dynamically, you can
  236. achieve the same benefits using {es} directly.
  237. ===== Choice of AMI
  238. Prefer the https://aws.amazon.com/amazon-linux-ami/[Amazon Linux AMIs] as these
  239. allow you to benefit from the lightweight nature, support, and EC2-specific
  240. performance enhancements that these images offer.
  241. ===== Networking
  242. * Smaller instance types have limited network performance, in terms of both
  243. https://lab.getbase.com/how-we-discovered-limitations-on-the-aws-tcp-stack/[bandwidth
  244. and number of connections]. If networking is a bottleneck, avoid
  245. https://aws.amazon.com/ec2/instance-types/[instance types] with networking
  246. labelled as `Moderate` or `Low`.
  247. * It is a good idea to distribute your nodes across multiple
  248. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html[availability
  249. zones] and use {ref}/allocation-awareness.html[shard allocation awareness] to
  250. ensure that each shard has copies in more than one availability zone.
  251. * Do not span a cluster across regions. {es} expects that node-to-node
  252. connections within a cluster are reasonably reliable and offer high bandwidth
  253. and low latency, and these properties do not hold for connections between
  254. regions. Although an {es} cluster will behave correctly when node-to-node
  255. connections are unreliable or slow, it is not optimised for this case and its
  256. performance may suffer. If you wish to geographically distribute your data, you
  257. should provision multiple clusters and use features such as
  258. {ref}/modules-cross-cluster-search.html[cross-cluster search] and
  259. {stack-ov}/xpack-ccr.html[cross-cluster replication].
  260. ===== Other recommendations
  261. * If you have split your nodes into roles, consider
  262. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[tagging the
  263. EC2 instances] by role to make it easier to filter and view your EC2 instances
  264. in the AWS console.
  265. * Consider
  266. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination[enabling
  267. termination protection] for all of your data and master-eligible nodes. This
  268. will help to prevent accidental termination of these nodes which could
  269. temporarily reduce the resilience of the cluster and which could cause a
  270. potentially disruptive reallocation of shards.
  271. * If running your cluster using one or more
  272. https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html[auto-scaling
  273. groups], consider protecting your data and master-eligible nodes
  274. https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-termination.html#instance-protection-instance[against
  275. termination during scale-in]. This will help to prevent automatic termination
  276. of these nodes which could temporarily reduce the resilience of the cluster and
  277. which could cause a potentially disruptive reallocation of shards. If these
  278. instances are protected against termination during scale-in then you can use
  279. {ref}/shard-allocation-filtering.html[shard allocation filtering] to gracefully
  280. migrate any data off these nodes before terminating them manually.