discovery-ec2.asciidoc 12 KB

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