discovery-ec2.asciidoc 11 KB

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