discovery-ec2.asciidoc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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/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/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`)
  87. * `us-west` (`us-west-1`)
  88. * `us-west-1`
  89. * `us-west-2`
  90. * `ap-southeast` (`ap-southeast-1`)
  91. * `ap-southeast-1`
  92. * `ap-southeast-2`
  93. * `ap-northeast` (`ap-northeast-1`)
  94. * `eu-west` (`eu-west-1`)
  95. * `eu-central` (`eu-central-1`)
  96. * `sa-east` (`sa-east-1`)
  97. * `cn-north` (`cn-north-1`)
  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. `ping_timeout`::
  133. How long to wait for existing EC2 nodes to reply during discovery.
  134. Defaults to `3s`. If no unit like `ms`, `s` or `m` is specified,
  135. milliseconds are used.
  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. [[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 `ping_timeout` values) there is a risk that a new node's discovery phase will end
  191. before it has found the cluster (which will result in it declaring itself master of a new cluster with the same name
  192. - 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.