discovery-ec2.asciidoc 15 KB

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