discovery-ec2.asciidoc 12 KB

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