discovery-ec2.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. [[discovery-ec2]]
  2. === EC2 Discovery Plugin
  3. The EC2 discovery plugin uses the https://github.com/aws/aws-sdk-java[AWS API] for unicast discovery.
  4. *If you are looking for a hosted solution of Elasticsearch on AWS, please visit http://www.elastic.co/cloud.*
  5. :plugin_name: discovery-ec2
  6. include::install_remove.asciidoc[]
  7. [[discovery-ec2-usage]]
  8. ==== Getting started with AWS
  9. The plugin provides a hosts provider for zen discovery named `ec2`. This hosts
  10. provider finds other Elasticsearch instances in EC2 through AWS metadata.
  11. Authentication is done using
  12. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM
  13. Role] credentials by default. To enable the plugin, set the unicast host
  14. provider for Zen discovery to `ec2`:
  15. [source,yaml]
  16. ----
  17. discovery.zen.hosts_provider: ec2
  18. ----
  19. ==== Settings
  20. EC2 host discovery supports a number of settings.
  21. Some settings are sensitive and must be stored in the {ref}/secure-settings.html[elasticsearch keystore].
  22. For example, to use explicit AWS access keys:
  23. [source,sh]
  24. ----
  25. bin/elasticsearch-keystore add discovery.ec2.access_key
  26. bin/elasticsearch-keystore add discovery.ec2.secret_key
  27. ----
  28. The following are the available discovery settings. All should be prefixed with `discovery.ec2.`.
  29. Those that must be stored in the keystore are marked as `Secure`.
  30. `access_key`::
  31. An ec2 access key. The `secret_key` setting must also be specified. (Secure)
  32. `secret_key`::
  33. An ec2 secret key. The `access_key` setting must also be specified. (Secure)
  34. `session_token`::
  35. An ec2 session token. The `access_key` and `secret_key` settings must also
  36. be specified. (Secure)
  37. `endpoint`::
  38. The ec2 service endpoint to connect to. See
  39. http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region. This
  40. defaults to `ec2.us-east-1.amazonaws.com`.
  41. `protocol`::
  42. The protocol to use to connect to ec2. Valid values are either `http`
  43. or `https`. Defaults to `https`.
  44. `proxy.host`::
  45. The host name of a proxy to connect to ec2 through.
  46. `proxy.port`::
  47. The port of a proxy to connect to ec2 through.
  48. `proxy.username`::
  49. The username to connect to the `proxy.host` with. (Secure)
  50. `proxy.password`::
  51. The password to connect to the `proxy.host` with. (Secure)
  52. `read_timeout`::
  53. The socket timeout for connecting to ec2. The value should specify the unit. For example,
  54. a value of `5s` specifies a 5 second timeout. The default value is 50 seconds.
  55. `groups`::
  56. Either a comma separated list or array based list of (security) groups.
  57. Only instances with the provided security groups will be used in the
  58. cluster discovery. (NOTE: You could provide either group NAME or group
  59. ID.)
  60. `host_type`::
  61. +
  62. --
  63. The type of host type to use to communicate with other instances. Can be
  64. one of `private_ip`, `public_ip`, `private_dns`, `public_dns` or `tag:TAGNAME` where
  65. `TAGNAME` refers to a name of a tag configured for all EC2 instances. Instances which don't
  66. have this tag set will be ignored by the discovery process.
  67. For example if you defined a tag `my-elasticsearch-host` in ec2 and set it to `myhostname1.mydomain.com`, then
  68. setting `host_type: tag:my-elasticsearch-host` will tell Discovery Ec2 plugin to read the host name from the
  69. `my-elasticsearch-host` tag. In this case, it will be resolved to `myhostname1.mydomain.com`.
  70. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[Read more about EC2 Tags].
  71. Defaults to `private_ip`.
  72. --
  73. `availability_zones`::
  74. Either a comma separated list or array based list of availability zones.
  75. Only instances within the provided availability zones will be used in the
  76. cluster discovery.
  77. `any_group`::
  78. If set to `false`, will require all security groups to be present for the
  79. instance to be used for the discovery. Defaults to `true`.
  80. `node_cache_time`::
  81. How long the list of hosts is cached to prevent further requests to the AWS API.
  82. Defaults to `10s`.
  83. *All* secure settings of this plugin are {ref}/secure-settings.html#reloadable-secure-settings[reloadable].
  84. After you reload the settings, an aws sdk client with the latest settings
  85. from the keystore will be used.
  86. [IMPORTANT]
  87. .Binding the network host
  88. ==============================================
  89. It's important to define `network.host` as by default it's bound to `localhost`.
  90. You can use {ref}/modules-network.html[core network host settings] or
  91. <<discovery-ec2-network-host,ec2 specific host settings>>:
  92. ==============================================
  93. [[discovery-ec2-network-host]]
  94. ===== EC2 Network Host
  95. When the `discovery-ec2` plugin is installed, the following are also allowed
  96. as valid network host settings:
  97. [cols="<,<",options="header",]
  98. |==================================================================
  99. |EC2 Host Value |Description
  100. |`_ec2:privateIpv4_` |The private IP address (ipv4) of the machine.
  101. |`_ec2:privateDns_` |The private host of the machine.
  102. |`_ec2:publicIpv4_` |The public IP address (ipv4) of the machine.
  103. |`_ec2:publicDns_` |The public host of the machine.
  104. |`_ec2:privateIp_` |equivalent to `_ec2:privateIpv4_`.
  105. |`_ec2:publicIp_` |equivalent to `_ec2:publicIpv4_`.
  106. |`_ec2_` |equivalent to `_ec2:privateIpv4_`.
  107. |==================================================================
  108. [[discovery-ec2-permissions]]
  109. ===== Recommended EC2 Permissions
  110. EC2 discovery requires making a call to the EC2 service. You'll want to setup
  111. an IAM policy to allow this. You can create a custom policy via the IAM
  112. Management Console. It should look similar to this.
  113. [source,js]
  114. ----
  115. {
  116. "Statement": [
  117. {
  118. "Action": [
  119. "ec2:DescribeInstances"
  120. ],
  121. "Effect": "Allow",
  122. "Resource": [
  123. "*"
  124. ]
  125. }
  126. ],
  127. "Version": "2012-10-17"
  128. }
  129. ----
  130. // NOTCONSOLE
  131. [[discovery-ec2-filtering]]
  132. ===== Filtering by Tags
  133. The ec2 discovery can also filter machines to include in the cluster based on tags (and not just groups). The settings
  134. to use include the `discovery.ec2.tag.` prefix. For example, setting `discovery.ec2.tag.stage` to `dev` will only
  135. filter instances with a tag key set to `stage`, and a value of `dev`. Several tags set will require all of those tags
  136. to be set for the instance to be included.
  137. One practical use for tag filtering is when an ec2 cluster contains many nodes that are not running Elasticsearch. In
  138. this case (particularly with high `discovery.zen.ping_timeout` values) there is a risk that a new node's discovery phase
  139. will end before it has found the cluster (which will result in it declaring itself master of a new cluster with the same
  140. name - highly undesirable). Tagging Elasticsearch ec2 nodes and then filtering by that tag will resolve this issue.
  141. [[discovery-ec2-attributes]]
  142. ===== Automatic Node Attributes
  143. Though not dependent on actually using `ec2` as discovery (but still requires the `discovery-ec2` plugin installed), the
  144. plugin can automatically add node attributes relating to ec2. In the future this may support other attributes, but this will
  145. currently only add an `aws_availability_zone` node attribute, which is the availability zone of the current node. Attributes
  146. can be used to isolate primary and replica shards across availability zones by using the
  147. {ref}/allocation-awareness.html[Allocation Awareness] feature.
  148. In order to enable it, set `cloud.node.auto_attributes` to `true` in the settings. For example:
  149. [source,yaml]
  150. ----
  151. cloud.node.auto_attributes: true
  152. cluster.routing.allocation.awareness.attributes: aws_availability_zone
  153. ----
  154. [[cloud-aws-best-practices]]
  155. ==== Best Practices in AWS
  156. Collection of best practices and other information around running Elasticsearch on AWS.
  157. ===== Instance/Disk
  158. When selecting disk please be aware of the following order of preference:
  159. * https://aws.amazon.com/efs/[EFS] - Avoid as the sacrifices made to offer durability, shared storage, and grow/shrink come at performance cost, such file systems have been known to cause corruption of indices, and due to Elasticsearch being distributed and having built-in replication, the benefits that EFS offers are not needed.
  160. * https://aws.amazon.com/ebs/[EBS] - Works well if running a small cluster (1-2 nodes) and cannot tolerate the loss all storage backing a node easily or if running indices with no replicas. If EBS is used, then leverage provisioned IOPS to ensure performance.
  161. * http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html[Instance Store] - When running clusters of larger size and with replicas the ephemeral nature of Instance Store is ideal since Elasticsearch can tolerate the loss of shards. With Instance Store one gets the performance benefit of having disk physically attached to the host running the instance and also the cost benefit of avoiding paying extra for EBS.
  162. Prefer https://aws.amazon.com/amazon-linux-ami/[Amazon Linux AMIs] as since Elasticsearch runs on the JVM, OS dependencies are very minimal and one can benefit from the lightweight nature, support, and performance tweaks specific to EC2 that the Amazon Linux AMIs offer.
  163. ===== Networking
  164. * Networking throttling takes place on smaller instance types in both the form of https://lab.getbase.com/how-we-discovered-limitations-on-the-aws-tcp-stack/[bandwidth and number of connections]. Therefore if large number of connections are needed and networking is becoming a bottleneck, avoid https://aws.amazon.com/ec2/instance-types/[instance types] with networking labeled as `Moderate` or `Low`.
  165. * Multicast is not supported, even when in an VPC; the aws cloud plugin which joins by performing a security group lookup.
  166. * When running in multiple http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html[availability zones] be sure to leverage {ref}/allocation-awareness.html[shard allocation awareness] so that not all copies of shard data reside in the same availability zone.
  167. * Do not span a cluster across regions. If necessary, use a cross cluster search.
  168. ===== Misc
  169. * If you have split your nodes into roles, consider https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[tagging the EC2 instances] by role to make it easier to filter and view your EC2 instances in the AWS console.
  170. * Consider https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination[enabling termination protection] for all of your instances to avoid accidentally terminating a node in the cluster and causing a potentially disruptive reallocation.