discovery-ec2.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 will default to using
  10. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Role]
  11. credentials for authentication. These can be overridden by, in increasing
  12. order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`,
  13. environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the
  14. elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key`:
  15. [source,yaml]
  16. ----
  17. cloud:
  18. aws:
  19. access_key: AKVAIQBF2RECL7FJWGJQ
  20. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  21. ----
  22. [[discovery-ec2-usage-security]]
  23. ===== Transport security
  24. By default this plugin uses HTTPS for all API calls to AWS endpoints. If you wish to configure HTTP you can set
  25. `cloud.aws.protocol` in the elasticsearch config. You can optionally override this setting per individual service
  26. via: `cloud.aws.ec2.protocol` or `cloud.aws.s3.protocol`.
  27. [source,yaml]
  28. ----
  29. cloud:
  30. aws:
  31. protocol: https
  32. ec2:
  33. protocol: https
  34. ----
  35. In addition, a proxy can be configured with the `proxy.host`, `proxy.port`, `proxy.username` and `proxy.password` settings
  36. (note that protocol can be `http` or `https`):
  37. [source,yaml]
  38. ----
  39. cloud:
  40. aws:
  41. protocol: https
  42. proxy:
  43. host: proxy1.company.com
  44. port: 8083
  45. username: myself
  46. password: theBestPasswordEver!
  47. ----
  48. You can also set different proxies for `ec2` and `s3`:
  49. [source,yaml]
  50. ----
  51. cloud:
  52. aws:
  53. s3:
  54. proxy:
  55. host: proxy1.company.com
  56. port: 8083
  57. username: myself1
  58. password: theBestPasswordEver1!
  59. ec2:
  60. proxy:
  61. host: proxy2.company.com
  62. port: 8083
  63. username: myself2
  64. password: theBestPasswordEver2!
  65. ----
  66. [[discovery-ec2-usage-region]]
  67. ===== Region
  68. The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`.
  69. The available values are:
  70. * `us-east` (`us-east-1`) for US East (N. Virginia)
  71. * `us-east-2` for US East (Ohio)
  72. * `us-west` (`us-west-1`) for US West (N. California)
  73. * `us-west-2` for US West (Oregon)
  74. * `ap-south` (`ap-south-1`) for Asia Pacific (Mumbai)
  75. * `ap-southeast` (`ap-southeast-1`) for Asia Pacific (Singapore)
  76. * `ap-southeast-2` for Asia Pacific (Sydney)
  77. * `ap-northeast` (`ap-northeast-1`) for Asia Pacific (Tokyo)
  78. * `ap-northeast-2` (`ap-northeast-2`) for Asia Pacific (Seoul)
  79. * `eu-west` (`eu-west-1`) for EU (Ireland)
  80. * `eu-west-2` (`eu-west-2`) for EU (London)
  81. * `eu-central` (`eu-central-1`) for EU (Frankfurt)
  82. * `sa-east` (`sa-east-1`) for South America (São Paulo)
  83. * `cn-north` (`cn-north-1`) for China (Beijing)
  84. * `ca-central` (`ca-central-1`) for Canada (Central)
  85. [[discovery-ec2-usage-signer]]
  86. ===== EC2 Signer API
  87. If you are using a compatible EC2 service, they might be using an older API to sign the requests.
  88. You can set your compatible signer API using `cloud.aws.signer` (or `cloud.aws.ec2.signer`)
  89. with the right signer to use.
  90. ===== Read timeout
  91. Read timeout determines the amount of time to wait for data to be transferred over an established,
  92. open connection before the connection is timed out. Defaults to AWS SDK default value (`50 s`).
  93. It can be configured with `cloud.aws.read_timeout` (or `cloud.aws.ec2.read_timeout`) setting:
  94. [source, yaml]
  95. ----
  96. cloud.aws.read_timeout: 30s
  97. ----
  98. [[discovery-ec2-discovery]]
  99. ==== EC2 Discovery
  100. ec2 discovery allows to use the ec2 APIs to perform automatic discovery (similar to multicast in non hostile multicast
  101. environments). Here is a simple sample configuration:
  102. [source,yaml]
  103. ----
  104. discovery:
  105. zen.hosts_provider: ec2
  106. ----
  107. You must also set `cloud.aws.region` if you are not using default AWS region. See <<discovery-ec2-usage-region>> for details.
  108. The ec2 discovery is using the same credentials as the rest of the AWS services provided by this plugin (`repositories`).
  109. See <<discovery-ec2-usage>> for details.
  110. The following are a list of settings (prefixed with `discovery.ec2`) that can further control the discovery:
  111. `groups`::
  112. Either a comma separated list or array based list of (security) groups.
  113. Only instances with the provided security groups will be used in the
  114. cluster discovery. (NOTE: You could provide either group NAME or group
  115. ID.)
  116. `host_type`::
  117. +
  118. --
  119. The type of host type to use to communicate with other instances. Can be
  120. one of `private_ip`, `public_ip`, `private_dns`, `public_dns` or `tag:TAGNAME` where
  121. `TAGNAME` refers to a name of a tag configured for all EC2 instances. Instances which don't
  122. have this tag set will be ignored by the discovery process.
  123. For example if you defined a tag `my-elasticsearch-host` in ec2 and set it to `myhostname1.mydomain.com`, then
  124. setting `host_type: tag:my-elasticsearch-host` will tell Discovery Ec2 plugin to read the host name from the
  125. `my-elasticsearch-host` tag. In this case, it will be resolved to `myhostname1.mydomain.com`.
  126. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[Read more about EC2 Tags].
  127. Defaults to `private_ip`.
  128. --
  129. `availability_zones`::
  130. Either a comma separated list or array based list of availability zones.
  131. Only instances within the provided availability zones will be used in the
  132. cluster discovery.
  133. `any_group`::
  134. If set to `false`, will require all security groups to be present for the
  135. instance to be used for the discovery. Defaults to `true`.
  136. `node_cache_time`::
  137. How long the list of hosts is cached to prevent further requests to the AWS API.
  138. Defaults to `10s`.
  139. [IMPORTANT]
  140. .Binding the network host
  141. ==============================================
  142. It's important to define `network.host` as by default it's bound to `localhost`.
  143. You can use {ref}/modules-network.html[core network host settings] or
  144. <<discovery-ec2-network-host,ec2 specific host settings>>:
  145. ==============================================
  146. [[discovery-ec2-network-host]]
  147. ===== EC2 Network Host
  148. When the `discovery-ec2` plugin is installed, the following are also allowed
  149. as valid network host settings:
  150. [cols="<,<",options="header",]
  151. |==================================================================
  152. |EC2 Host Value |Description
  153. |`_ec2:privateIpv4_` |The private IP address (ipv4) of the machine.
  154. |`_ec2:privateDns_` |The private host of the machine.
  155. |`_ec2:publicIpv4_` |The public IP address (ipv4) of the machine.
  156. |`_ec2:publicDns_` |The public host of the machine.
  157. |`_ec2:privateIp_` |equivalent to `_ec2:privateIpv4_`.
  158. |`_ec2:publicIp_` |equivalent to `_ec2:publicIpv4_`.
  159. |`_ec2_` |equivalent to `_ec2:privateIpv4_`.
  160. |==================================================================
  161. [[discovery-ec2-permissions]]
  162. ===== Recommended EC2 Permissions
  163. EC2 discovery requires making a call to the EC2 service. You'll want to setup
  164. an IAM policy to allow this. You can create a custom policy via the IAM
  165. Management Console. It should look similar to this.
  166. [source,js]
  167. ----
  168. {
  169. "Statement": [
  170. {
  171. "Action": [
  172. "ec2:DescribeInstances"
  173. ],
  174. "Effect": "Allow",
  175. "Resource": [
  176. "*"
  177. ]
  178. }
  179. ],
  180. "Version": "2012-10-17"
  181. }
  182. ----
  183. // NOTCONSOLE
  184. [[discovery-ec2-filtering]]
  185. ===== Filtering by Tags
  186. The ec2 discovery can also filter machines to include in the cluster based on tags (and not just groups). The settings
  187. to use include the `discovery.ec2.tag.` prefix. For example, setting `discovery.ec2.tag.stage` to `dev` will only
  188. filter instances with a tag key set to `stage`, and a value of `dev`. Several tags set will require all of those tags
  189. to be set for the instance to be included.
  190. One practical use for tag filtering is when an ec2 cluster contains many nodes that are not running elasticsearch. In
  191. this case (particularly with high `discovery.zen.ping_timeout` values) there is a risk that a new node's discovery phase
  192. will end before it has found the cluster (which will result in it declaring itself master of a new cluster with the same
  193. name - highly undesirable). Tagging elasticsearch ec2 nodes and then filtering by that tag will resolve this issue.
  194. [[discovery-ec2-attributes]]
  195. ===== Automatic Node Attributes
  196. Though not dependent on actually using `ec2` as discovery (but still requires the `discovery-ec2` plugin installed), the
  197. plugin can automatically add node attributes relating to ec2. In the future this may support other attributes, but this will
  198. currently only add an `aws_availability_zone` node attribute, which is the availability zone of the current node. Attributes
  199. can be used to isolate primary and replica shards across availability zones by using the
  200. {ref}/allocation-awareness.html[Allocation Awareness] feature.
  201. In order to enable it, set `cloud.node.auto_attributes` to `true` in the settings. For example:
  202. [source,yaml]
  203. ----
  204. cloud.node.auto_attributes: true
  205. cluster.routing.allocation.awareness.attributes: aws_availability_zone
  206. ----
  207. [[discovery-ec2-endpoint]]
  208. ===== Using other EC2 endpoint
  209. If you are using any EC2 api compatible service, you can set the endpoint you want to use by setting
  210. `cloud.aws.ec2.endpoint` to your URL provider.
  211. [[cloud-aws-best-practices]]
  212. ==== Best Practices in AWS
  213. Collection of best practices and other information around running Elasticsearch on AWS.
  214. ===== Instance/Disk
  215. When selecting disk please be aware of the following order of preference:
  216. * 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.
  217. * 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.
  218. * 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.
  219. 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.
  220. ===== Networking
  221. * 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`.
  222. * Multicast is not supported, even when in an VPC; the aws cloud plugin which joins by performing a security group lookup.
  223. * 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.
  224. * Do not span a cluster across regions. If necessary, use a tribe node.
  225. ===== Misc
  226. * 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.
  227. * 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.