discovery-ec2.asciidoc 15 KB

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