repository-s3.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. [[repository-s3]]
  2. === S3 Repository Plugin
  3. The S3 repository plugin adds support for using AWS S3 as a repository for
  4. {ref}/modules-snapshots.html[Snapshot/Restore].
  5. *If you are looking for a hosted solution of Elasticsearch on AWS, please visit
  6. http://www.elastic.co/cloud.*
  7. :plugin_name: repository-s3
  8. include::install_remove.asciidoc[]
  9. [[repository-s3-usage]]
  10. ==== Getting Started
  11. The plugin provides a repository type named `s3` which may be used when creating
  12. a repository. The repository defaults to using
  13. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html[ECS
  14. IAM Role] or
  15. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[EC2
  16. IAM Role] credentials for authentication. The only mandatory setting is the
  17. bucket name:
  18. [source,js]
  19. ----
  20. PUT _snapshot/my_s3_repository
  21. {
  22. "type": "s3",
  23. "settings": {
  24. "bucket": "my_bucket"
  25. }
  26. }
  27. ----
  28. // CONSOLE
  29. // TEST[skip:we don't have s3 setup while testing this]
  30. [[repository-s3-client]]
  31. ==== Client Settings
  32. The client that you use to connect to S3 has a number of settings available.
  33. The settings have the form `s3.client.CLIENT_NAME.SETTING_NAME`. By default,
  34. `s3` repositories use a client named `default`, but this can be modified using
  35. the <<repository-s3-repository,repository setting>> `client`. For example:
  36. [source,js]
  37. ----
  38. PUT _snapshot/my_s3_repository
  39. {
  40. "type": "s3",
  41. "settings": {
  42. "bucket": "my_bucket",
  43. "client": "my_alternate_client"
  44. }
  45. }
  46. ----
  47. // CONSOLE
  48. // TEST[skip:we don't have S3 setup while testing this]
  49. Most client settings can be added to the `elasticsearch.yml` configuration file
  50. with the exception of the secure settings, which you add to the {es} keystore.
  51. For more information about creating and updating the {es} keystore, see
  52. {ref}/secure-settings.html[Secure settings].
  53. For example, before you start the node, run these commands to add AWS access key
  54. settings to the keystore:
  55. [source,sh]
  56. ----
  57. bin/elasticsearch-keystore add s3.client.default.access_key
  58. bin/elasticsearch-keystore add s3.client.default.secret_key
  59. ----
  60. *All* client secure settings of this plugin are
  61. {ref}/secure-settings.html#reloadable-secure-settings[reloadable]. After you
  62. reload the settings, the internal `s3` clients, used to transfer the snapshot
  63. contents, will utilize the latest settings from the keystore. Any existing `s3`
  64. repositories, as well as any newly created ones, will pick up the new values
  65. stored in the keystore.
  66. NOTE: In-progress snapshot/restore tasks will not be preempted by a *reload* of
  67. the client's secure settings. The task will complete using the client as it was
  68. built when the operation started.
  69. The following list contains the available client settings. Those that must be
  70. stored in the keystore are marked as "secure" and are *reloadable*; the other
  71. settings belong in the `elasticsearch.yml` file.
  72. `access_key` ({ref}/secure-settings.html[Secure])::
  73. An S3 access key. The `secret_key` setting must also be specified.
  74. `secret_key` ({ref}/secure-settings.html[Secure])::
  75. An S3 secret key. The `access_key` setting must also be specified.
  76. `session_token` ({ref}/secure-settings.html[Secure])::
  77. An S3 session token. The `access_key` and `secret_key` settings must also be
  78. specified.
  79. `endpoint`::
  80. The S3 service endpoint to connect to. This defaults to `s3.amazonaws.com`
  81. but the
  82. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region[AWS
  83. documentation] lists alternative S3 endpoints. If you are using an
  84. <<repository-s3-compatible-services,S3-compatible service>> then you should
  85. set this to the service's endpoint.
  86. `protocol`::
  87. The protocol to use to connect to S3. Valid values are either `http` or
  88. `https`. Defaults to `https`.
  89. `proxy.host`::
  90. The host name of a proxy to connect to S3 through.
  91. `proxy.port`::
  92. The port of a proxy to connect to S3 through.
  93. `proxy.username` ({ref}/secure-settings.html[Secure])::
  94. The username to connect to the `proxy.host` with.
  95. `proxy.password` ({ref}/secure-settings.html[Secure])::
  96. The password to connect to the `proxy.host` with.
  97. `read_timeout`::
  98. The socket timeout for connecting to S3. The value should specify the unit.
  99. For example, a value of `5s` specifies a 5 second timeout. The default value
  100. is 50 seconds.
  101. `max_retries`::
  102. The number of retries to use when an S3 request fails. The default value is
  103. `3`.
  104. `use_throttle_retries`::
  105. Whether retries should be throttled (i.e. should back off). Must be `true`
  106. or `false`. Defaults to `true`.
  107. [float]
  108. [[repository-s3-compatible-services]]
  109. ===== S3-compatible services
  110. There are a number of storage systems that provide an S3-compatible API, and
  111. the `repository-s3` plugin allows you to use these systems in place of AWS S3.
  112. To do so, you should set the `s3.client.CLIENT_NAME.endpoint` setting to the
  113. system's endpoint. This setting accepts IP addresses and hostnames and may
  114. include a port. For example, the endpoint may be `172.17.0.2` or
  115. `172.17.0.2:9000`. You may also need to set `s3.client.CLIENT_NAME.protocol` to
  116. `http` if the endpoint does not support HTTPS.
  117. https://minio.io[Minio] is an example of a storage system that provides an
  118. S3-compatible API. The `repository-s3` plugin allows {es} to work with
  119. Minio-backed repositories as well as repositories stored on AWS S3. Other
  120. S3-compatible storage systems may also work with {es}, but these are not tested
  121. or supported.
  122. [[repository-s3-repository]]
  123. ==== Repository Settings
  124. The `s3` repository type supports a number of settings to customize how data is
  125. stored in S3. These can be specified when creating the repository. For example:
  126. [source,js]
  127. ----
  128. PUT _snapshot/my_s3_repository
  129. {
  130. "type": "s3",
  131. "settings": {
  132. "bucket": "my_bucket_name",
  133. "another_setting": "setting_value"
  134. }
  135. }
  136. ----
  137. // CONSOLE
  138. // TEST[skip:we don't have S3 set up while testing this]
  139. The following settings are supported:
  140. `bucket`::
  141. The name of the bucket to be used for snapshots. (Mandatory)
  142. `client`::
  143. The name of the <<repository-s3-client,S3 client>> to use to connect to S3.
  144. Defaults to `default`.
  145. `base_path`::
  146. Specifies the path within bucket to repository data. Defaults to value of
  147. `repositories.s3.base_path` or to root directory if not set. Previously,
  148. the base_path could take a leading `/` (forward slash). However, this has
  149. been deprecated and setting the base_path now should omit the leading `/`.
  150. `chunk_size`::
  151. Big files can be broken down into chunks during snapshotting if needed. The
  152. chunk size can be specified in bytes or by using size value notation, i.e.
  153. `1gb`, `10mb`, `5kb`. Defaults to `1gb`.
  154. `compress`::
  155. When set to `true` metadata files are stored in compressed format. This
  156. setting doesn't affect index files that are already compressed by default.
  157. Defaults to `true`.
  158. include::repository-shared-settings.asciidoc[]
  159. `server_side_encryption`::
  160. When set to `true` files are encrypted on server side using AES256
  161. algorithm. Defaults to `false`.
  162. `buffer_size`::
  163. Minimum threshold below which the chunk is uploaded using a single request.
  164. Beyond this threshold, the S3 repository will use the
  165. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS
  166. Multipart Upload API] to split the chunk into several parts, each of
  167. `buffer_size` length, and to upload each part in its own request. Note that
  168. setting a buffer size lower than `5mb` is not allowed since it will prevent
  169. the use of the Multipart API and may result in upload errors. It is also not
  170. possible to set a buffer size greater than `5gb` as it is the maximum upload
  171. size allowed by S3. Defaults to the minimum between `100mb` and `5%` of the
  172. heap size.
  173. `canned_acl`::
  174. The S3 repository supports all
  175. http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3
  176. canned ACLs] : `private`, `public-read`, `public-read-write`,
  177. `authenticated-read`, `log-delivery-write`, `bucket-owner-read`,
  178. `bucket-owner-full-control`. Defaults to `private`. You could specify a
  179. canned ACL using the `canned_acl` setting. When the S3 repository creates
  180. buckets and objects, it adds the canned ACL into the buckets and objects.
  181. `storage_class`::
  182. Sets the S3 storage class for objects stored in the snapshot repository.
  183. Values may be `standard`, `reduced_redundancy`, `standard_ia`
  184. and `intelligent_tiering`. Defaults to `standard`.
  185. Changing this setting on an existing repository only affects the
  186. storage class for newly created objects, resulting in a mixed usage of
  187. storage classes. Additionally, S3 Lifecycle Policies can be used to manage
  188. the storage class of existing objects. Due to the extra complexity with the
  189. Glacier class lifecycle, it is not currently supported by the plugin. For
  190. more information about the different classes, see
  191. http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS
  192. Storage Classes Guide]
  193. NOTE: The option of defining client settings in the repository settings as
  194. documented below is considered deprecated, and will be removed in a future
  195. version.
  196. In addition to the above settings, you may also specify all non-secure client
  197. settings in the repository settings. In this case, the client settings found in
  198. the repository settings will be merged with those of the named client used by
  199. the repository. Conflicts between client and repository settings are resolved
  200. by the repository settings taking precedence over client settings.
  201. For example:
  202. [source,js]
  203. ----
  204. PUT _snapshot/my_s3_repository
  205. {
  206. "type": "s3",
  207. "settings": {
  208. "client": "my_client_name",
  209. "bucket": "my_bucket_name",
  210. "endpoint": "my.s3.endpoint"
  211. }
  212. }
  213. ----
  214. // CONSOLE
  215. // TEST[skip:we don't have s3 set up while testing this]
  216. This sets up a repository that uses all client settings from the client
  217. `my_client_name` except for the `endpoint` that is overridden to
  218. `my.s3.endpoint` by the repository settings.
  219. [[repository-s3-permissions]]
  220. ===== Recommended S3 Permissions
  221. In order to restrict the Elasticsearch snapshot process to the minimum required
  222. resources, we recommend using Amazon IAM in conjunction with pre-existing S3
  223. buckets. Here is an example policy which will allow the snapshot access to an S3
  224. bucket named "snaps.example.com". This may be configured through the AWS IAM
  225. console, by creating a Custom Policy, and using a Policy Document similar to
  226. this (changing snaps.example.com to your bucket name).
  227. [source,js]
  228. ----
  229. {
  230. "Statement": [
  231. {
  232. "Action": [
  233. "s3:ListBucket",
  234. "s3:GetBucketLocation",
  235. "s3:ListBucketMultipartUploads",
  236. "s3:ListBucketVersions"
  237. ],
  238. "Effect": "Allow",
  239. "Resource": [
  240. "arn:aws:s3:::snaps.example.com"
  241. ]
  242. },
  243. {
  244. "Action": [
  245. "s3:GetObject",
  246. "s3:PutObject",
  247. "s3:DeleteObject",
  248. "s3:AbortMultipartUpload",
  249. "s3:ListMultipartUploadParts"
  250. ],
  251. "Effect": "Allow",
  252. "Resource": [
  253. "arn:aws:s3:::snaps.example.com/*"
  254. ]
  255. }
  256. ],
  257. "Version": "2012-10-17"
  258. }
  259. ----
  260. // NOTCONSOLE
  261. You may further restrict the permissions by specifying a prefix within the
  262. bucket, in this example, named "foo".
  263. [source,js]
  264. ----
  265. {
  266. "Statement": [
  267. {
  268. "Action": [
  269. "s3:ListBucket",
  270. "s3:GetBucketLocation",
  271. "s3:ListBucketMultipartUploads",
  272. "s3:ListBucketVersions"
  273. ],
  274. "Condition": {
  275. "StringLike": {
  276. "s3:prefix": [
  277. "foo/*"
  278. ]
  279. }
  280. },
  281. "Effect": "Allow",
  282. "Resource": [
  283. "arn:aws:s3:::snaps.example.com"
  284. ]
  285. },
  286. {
  287. "Action": [
  288. "s3:GetObject",
  289. "s3:PutObject",
  290. "s3:DeleteObject",
  291. "s3:AbortMultipartUpload",
  292. "s3:ListMultipartUploadParts"
  293. ],
  294. "Effect": "Allow",
  295. "Resource": [
  296. "arn:aws:s3:::snaps.example.com/foo/*"
  297. ]
  298. }
  299. ],
  300. "Version": "2012-10-17"
  301. }
  302. ----
  303. // NOTCONSOLE
  304. The bucket needs to exist to register a repository for snapshots. If you did not
  305. create the bucket then the repository registration will fail.
  306. Note: Starting in version 7.0, all bucket operations are using the path style
  307. access pattern. In previous versions the decision to use virtual hosted style or
  308. path style access was made by the AWS Java SDK.
  309. [[repository-s3-aws-vpc]]
  310. [float]
  311. ==== AWS VPC Bandwidth Settings
  312. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch
  313. instances reside in a private subnet in an AWS VPC then all traffic to S3 will
  314. go through that VPC's NAT instance. If your VPC's NAT instance is a smaller
  315. instance size (e.g. a t1.micro) or is handling a high volume of network traffic
  316. your bandwidth to S3 may be limited by that NAT instance's networking bandwidth
  317. limitations.
  318. Instances residing in a public subnet in an AWS VPC will connect to S3 via the
  319. VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.