repository-s3.asciidoc 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. [[repository-s3]]
  2. === S3 Repository Plugin
  3. The S3 repository plugin adds support for using 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 http://www.elastic.co/cloud.*
  6. :plugin_name: repository-s3
  7. include::install_remove.asciidoc[]
  8. [[repository-s3-usage]]
  9. ==== Getting started with AWS
  10. The plugin provides a repository type named `s3` which may be used when creating a repository.
  11. The repository defaults to using https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html[ECS IAM Role] or
  12. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[EC2 IAM Role]
  13. credentials for authentication. The only mandatory setting is the bucket name:
  14. [source,js]
  15. ----
  16. PUT _snapshot/my_s3_repository
  17. {
  18. "type": "s3",
  19. "settings": {
  20. "bucket": "my_bucket"
  21. }
  22. }
  23. ----
  24. // CONSOLE
  25. // TEST[skip:we don't have s3 setup while testing this]
  26. [[repository-s3-client]]
  27. ==== Client Settings
  28. The client used to connect to S3 has a number of settings available. Client setting names are of
  29. the form `s3.client.CLIENT_NAME.SETTING_NAME`. The default client name, which is looked up by
  30. an `s3` repository, is called `default`. It can be modified using the
  31. <<repository-s3-repository, repository setting>> `client`. For example:
  32. [source,js]
  33. ----
  34. PUT _snapshot/my_s3_repository
  35. {
  36. "type": "s3",
  37. "settings": {
  38. "bucket": "my_bucket",
  39. "client": "my_alternate_client"
  40. }
  41. }
  42. ----
  43. // CONSOLE
  44. // TEST[skip:we don't have s3 setup while testing this]
  45. Most client settings are specified inside `elasticsearch.yml`, but some are
  46. sensitive and must be stored in the {ref}/secure-settings.html[elasticsearch keystore].
  47. For example, before you start the node, run these commands to add AWS access
  48. key settings to the keystore:
  49. [source,sh]
  50. ----
  51. bin/elasticsearch-keystore add s3.client.default.access_key
  52. bin/elasticsearch-keystore add s3.client.default.secret_key
  53. ----
  54. *All* client secure settings of this plugin are
  55. {ref}/secure-settings.html#reloadable-secure-settings[reloadable]. After you
  56. reload the settings, the internal `s3` clients, used to transfer the snapshot
  57. contents, will utilize the latest settings from the keystore. Any existing `s3`
  58. repositories, as well as any newly created ones, will pick up the new values
  59. stored in the keystore.
  60. NOTE: In progress snapshot/restore tasks will not be preempted by a *reload*
  61. of the client's secure settings. The task will complete using the client as it
  62. was built when the operation started.
  63. The following is the list of all the available client settings.
  64. Those that must be stored in the keystore are marked as `Secure` and are *reloadable*.
  65. `access_key`::
  66. An s3 access key. The `secret_key` setting must also be specified. (Secure)
  67. `secret_key`::
  68. An s3 secret key. The `access_key` setting must also be specified. (Secure)
  69. `session_token`::
  70. An s3 session token. The `access_key` and `secret_key` settings must also
  71. be specified. (Secure)
  72. `endpoint`::
  73. The s3 service endpoint to connect to. This will be automatically
  74. figured out by the s3 client based on the bucket location, but
  75. can be specified explicitly. See http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region.
  76. `protocol`::
  77. The protocol to use to connect to s3. Valid values are either `http`
  78. or `https`. Defaults to `https`.
  79. `proxy.host`::
  80. The host name of a proxy to connect to s3 through.
  81. `proxy.port`::
  82. The port of a proxy to connect to s3 through.
  83. `proxy.username`::
  84. The username to connect to the `proxy.host` with. (Secure)
  85. `proxy.password`::
  86. The password to connect to the `proxy.host` with. (Secure)
  87. `read_timeout`::
  88. The socket timeout for connecting to s3. The value should specify the unit. For example,
  89. a value of `5s` specifies a 5 second timeout. The default value is 50 seconds.
  90. `max_retries`::
  91. The number of retries to use when an s3 request fails. The default value is 3.
  92. `use_throttle_retries`::
  93. Whether retries should be throttled (ie use backoff). Must be `true` or `false`. Defaults to `true`.
  94. [[repository-s3-repository]]
  95. ==== Repository Settings
  96. The `s3` repository type supports a number of settings to customize how data is stored in S3.
  97. These can be specified when creating the repository. For example:
  98. [source,js]
  99. ----
  100. PUT _snapshot/my_s3_repository
  101. {
  102. "type": "s3",
  103. "settings": {
  104. "bucket": "my_bucket_name",
  105. "another_setting": "setting_value"
  106. }
  107. }
  108. ----
  109. // CONSOLE
  110. // TEST[skip:we don't have s3 set up while testing this]
  111. The following settings are supported:
  112. `bucket`::
  113. The name of the bucket to be used for snapshots. (Mandatory)
  114. `client`::
  115. The name of the s3 client to use to connect to S3. Defaults to `default`.
  116. `base_path`::
  117. Specifies the path within bucket to repository data. Defaults to
  118. value of `repositories.s3.base_path` or to root directory if not set.
  119. Previously, the base_path could take a leading `/` (forward slash).
  120. However, this has been deprecated and setting the base_path now should
  121. omit the leading `/`.
  122. `chunk_size`::
  123. Big files can be broken down into chunks during snapshotting if needed.
  124. The chunk size can be specified in bytes or by using size value notation,
  125. i.e. `1gb`, `10mb`, `5kb`. Defaults to `1gb`.
  126. `compress`::
  127. When set to `true` metadata files are stored in compressed format. This
  128. setting doesn't affect index files that are already compressed by default.
  129. Defaults to `false`.
  130. `server_side_encryption`::
  131. When set to `true` files are encrypted on server side using AES256
  132. algorithm. Defaults to `false`.
  133. `buffer_size`::
  134. Minimum threshold below which the chunk is uploaded using a single
  135. request. Beyond this threshold, the S3 repository will use the
  136. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  137. to split the chunk into several parts, each of `buffer_size` length, and
  138. to upload each part in its own request. Note that setting a buffer
  139. size lower than `5mb` is not allowed since it will prevent the use of the
  140. Multipart API and may result in upload errors. It is also not possible to
  141. set a buffer size greater than `5gb` as it is the maximum upload size
  142. allowed by S3. Defaults to the minimum between `100mb` and `5%` of the heap size.
  143. `canned_acl`::
  144. The S3 repository supports all http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3 canned ACLs]
  145. : `private`, `public-read`, `public-read-write`, `authenticated-read`, `log-delivery-write`,
  146. `bucket-owner-read`, `bucket-owner-full-control`. Defaults to `private`.
  147. You could specify a canned ACL using the `canned_acl` setting. When the S3 repository
  148. creates buckets and objects, it adds the canned ACL into the buckets and objects.
  149. `storage_class`::
  150. Sets the S3 storage class type for the backup files. Values may be
  151. `standard`, `reduced_redundancy`, `standard_ia`. Defaults to `standard`.
  152. Due to the extra complexity with the Glacier class lifecycle, it is not
  153. currently supported by the plugin. For more information about the
  154. different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide]
  155. [[repository-s3-permissions]]
  156. ===== Recommended S3 Permissions
  157. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  158. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  159. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  160. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  161. [source,js]
  162. ----
  163. {
  164. "Statement": [
  165. {
  166. "Action": [
  167. "s3:ListBucket",
  168. "s3:GetBucketLocation",
  169. "s3:ListBucketMultipartUploads",
  170. "s3:ListBucketVersions"
  171. ],
  172. "Effect": "Allow",
  173. "Resource": [
  174. "arn:aws:s3:::snaps.example.com"
  175. ]
  176. },
  177. {
  178. "Action": [
  179. "s3:GetObject",
  180. "s3:PutObject",
  181. "s3:DeleteObject",
  182. "s3:AbortMultipartUpload",
  183. "s3:ListMultipartUploadParts"
  184. ],
  185. "Effect": "Allow",
  186. "Resource": [
  187. "arn:aws:s3:::snaps.example.com/*"
  188. ]
  189. }
  190. ],
  191. "Version": "2012-10-17"
  192. }
  193. ----
  194. // NOTCONSOLE
  195. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  196. [source,js]
  197. ----
  198. {
  199. "Statement": [
  200. {
  201. "Action": [
  202. "s3:ListBucket",
  203. "s3:GetBucketLocation",
  204. "s3:ListBucketMultipartUploads",
  205. "s3:ListBucketVersions"
  206. ],
  207. "Condition": {
  208. "StringLike": {
  209. "s3:prefix": [
  210. "foo/*"
  211. ]
  212. }
  213. },
  214. "Effect": "Allow",
  215. "Resource": [
  216. "arn:aws:s3:::snaps.example.com"
  217. ]
  218. },
  219. {
  220. "Action": [
  221. "s3:GetObject",
  222. "s3:PutObject",
  223. "s3:DeleteObject",
  224. "s3:AbortMultipartUpload",
  225. "s3:ListMultipartUploadParts"
  226. ],
  227. "Effect": "Allow",
  228. "Resource": [
  229. "arn:aws:s3:::snaps.example.com/foo/*"
  230. ]
  231. }
  232. ],
  233. "Version": "2012-10-17"
  234. }
  235. ----
  236. // NOTCONSOLE
  237. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  238. registration will fail.
  239. [[repository-s3-aws-vpc]]
  240. [float]
  241. ==== AWS VPC Bandwidth Settings
  242. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch instances reside in a private subnet in an AWS VPC then all traffic to S3 will go through that VPC's NAT instance. If your VPC's NAT instance is a smaller instance size (e.g. a t1.micro) or is handling a high volume of network traffic your bandwidth to S3 may be limited by that NAT instance's networking bandwidth limitations.
  243. Instances residing in a public subnet in an AWS VPC will connect to S3 via the VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.