repository-s3.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. [[repository-s3-install]]
  7. [float]
  8. ==== Installation
  9. This plugin can be installed using the plugin manager:
  10. [source,sh]
  11. ----------------------------------------------------------------
  12. sudo bin/elasticsearch-plugin install repository-s3
  13. ----------------------------------------------------------------
  14. The plugin must be installed on every node in the cluster, and each node must
  15. be restarted after installation.
  16. [[repository-s3-remove]]
  17. [float]
  18. ==== Removal
  19. The plugin can be removed with the following command:
  20. [source,sh]
  21. ----------------------------------------------------------------
  22. sudo bin/elasticsearch-plugin remove repository-s3
  23. ----------------------------------------------------------------
  24. The node must be stopped before removing the plugin.
  25. [[repository-s3-usage]]
  26. ==== Getting started with AWS
  27. The plugin will default to using
  28. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Role]
  29. credentials for authentication. These can be overridden by, in increasing
  30. order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`,
  31. environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the
  32. elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key` or
  33. if you wish to set credentials specifically for s3 `cloud.aws.s3.access_key` and `cloud.aws.s3.secret_key`:
  34. [source,yaml]
  35. ----
  36. cloud:
  37. aws:
  38. access_key: AKVAIQBF2RECL7FJWGJQ
  39. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  40. ----
  41. [[repository-s3-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. s3:
  52. protocol: http
  53. ec2:
  54. protocol: https
  55. ----
  56. In addition, a proxy can be configured with the `proxy.host`, `proxy.port`, `proxy.username` and `proxy.password` settings
  57. (note that protocol can be `http` or `https`):
  58. [source,yaml]
  59. ----
  60. cloud:
  61. aws:
  62. protocol: https
  63. proxy:
  64. host: proxy1.company.com
  65. port: 8083
  66. username: myself
  67. password: theBestPasswordEver!
  68. ----
  69. You can also set different proxies for `ec2` and `s3`:
  70. [source,yaml]
  71. ----
  72. cloud:
  73. aws:
  74. s3:
  75. proxy:
  76. host: proxy1.company.com
  77. port: 8083
  78. username: myself1
  79. password: theBestPasswordEver1!
  80. ec2:
  81. proxy:
  82. host: proxy2.company.com
  83. port: 8083
  84. username: myself2
  85. password: theBestPasswordEver2!
  86. ----
  87. [[repository-s3-usage-region]]
  88. ===== Region
  89. The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`.
  90. You can specifically set it for s3 only using `cloud.aws.s3.region`.
  91. The available values are:
  92. * `us-east` (`us-east-1`) for US East (N. Virginia)
  93. * `us-west` (`us-west-1`) for US West (N. California)
  94. * `us-west-2` for US West (Oregon)
  95. * `ap-south-1` for Asia Pacific (Mumbai)
  96. * `ap-southeast` (`ap-southeast-1`) for Asia Pacific (Singapore)
  97. * `ap-southeast-2` for Asia Pacific (Sydney)
  98. * `ap-northeast` (`ap-northeast-1`) for Asia Pacific (Tokyo)
  99. * `ap-northeast-2` (`ap-northeast-2`) for Asia Pacific (Seoul)
  100. * `eu-west` (`eu-west-1`) for EU (Ireland)
  101. * `eu-central` (`eu-central-1`) for EU (Frankfurt)
  102. * `sa-east` (`sa-east-1`) for South America (São Paulo)
  103. * `cn-north` (`cn-north-1`) for China (Beijing)
  104. [[repository-s3-usage-signer]]
  105. ===== S3 Signer API
  106. If you are using a S3 compatible service, they might be using an older API to sign the requests.
  107. You can set your compatible signer API using `cloud.aws.signer` (or `cloud.aws.s3.signer`) with the right
  108. signer to use.
  109. If you are using a compatible S3 service which do not support Version 4 signing process, you may need to
  110. use `S3SignerType`, which is Signature Version 2.
  111. [[repository-s3-repository]]
  112. ==== S3 Repository
  113. The S3 repository is using S3 to store snapshots. The S3 repository can be created using the following command:
  114. [source,js]
  115. ----
  116. PUT _snapshot/my_s3_repository
  117. {
  118. "type": "s3",
  119. "settings": {
  120. "bucket": "my_bucket_name",
  121. "region": "us-west"
  122. }
  123. }
  124. ----
  125. // CONSOLE
  126. // TEST[skip:we don't have s3 set up while testing this]
  127. The following settings are supported:
  128. `bucket`::
  129. The name of the bucket to be used for snapshots. (Mandatory)
  130. `region`::
  131. The region where bucket is located. Defaults to US Standard
  132. `endpoint`::
  133. The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note
  134. that setting a region overrides the endpoint setting.
  135. `protocol`::
  136. The protocol to use (`http` or `https`). Defaults to value of
  137. `cloud.aws.protocol` or `cloud.aws.s3.protocol`.
  138. `base_path`::
  139. Specifies the path within bucket to repository data. Defaults to
  140. value of `repositories.s3.base_path` or to root directory if not set.
  141. `access_key`::
  142. The access key to use for authentication. Defaults to value of
  143. `cloud.aws.access_key`.
  144. `secret_key`::
  145. The secret key to use for authentication. Defaults to value of
  146. `cloud.aws.secret_key`.
  147. `chunk_size`::
  148. Big files can be broken down into chunks during snapshotting if needed.
  149. The chunk size can be specified in bytes or by using size value notation,
  150. i.e. `1gb`, `10mb`, `5kb`. Defaults to `1gb`.
  151. `compress`::
  152. When set to `true` metadata files are stored in compressed format. This
  153. setting doesn't affect index files that are already compressed by default.
  154. Defaults to `false`.
  155. `server_side_encryption`::
  156. When set to `true` files are encrypted on server side using AES256
  157. algorithm. Defaults to `false`.
  158. `buffer_size`::
  159. Minimum threshold below which the chunk is uploaded using a single
  160. request. Beyond this threshold, the S3 repository will use the
  161. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  162. to split the chunk into several parts, each of `buffer_size` length, and
  163. to upload each part in its own request. Note that setting a buffer
  164. size lower than `5mb` is not allowed since it will prevents the use of the
  165. Multipart API and may result in upload errors. Defaults to `100mb`.
  166. `max_retries`::
  167. Number of retries in case of S3 errors. Defaults to `3`.
  168. `use_throttle_retries`::
  169. Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`).
  170. `read_only`::
  171. Makes repository read-only. Defaults to `false`.
  172. `canned_acl`::
  173. The S3 repository supports all http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3 canned ACLs]
  174. : `private`, `public-read`, `public-read-write`, `authenticated-read`, `log-delivery-write`,
  175. `bucket-owner-read`, `bucket-owner-full-control`. Defaults to `private`.
  176. You could specify a canned ACL using the `canned_acl` setting. When the S3 repository
  177. creates buckets and objects, it adds the canned ACL into the buckets and objects.
  178. `storage_class`::
  179. Sets the S3 storage class type for the backup files. Values may be
  180. `standard`, `reduced_redundancy`, `standard_ia`. Defaults to `standard`.
  181. Due to the extra complexity with the Glacier class lifecycle, it is not
  182. currently supported by the plugin. For more information about the
  183. different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide]
  184. `path_style_access`::
  185. Activate path style access for [virtual hosting of buckets](http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html).
  186. The default behaviour is to detect which access style to use based on the configured endpoint (an IP will result
  187. in path-style access) and the bucket being accessed (some buckets are not valid DNS names).
  188. Note that you can define S3 repository settings for all S3 repositories in `elasticsearch.yml` configuration file.
  189. They are all prefixed with `repositories.s3.`. For example, you can define compression for all S3 repositories
  190. by setting `repositories.s3.compress: true` in `elasticsearch.yml`.
  191. The S3 repositories use the same credentials as the rest of the AWS services
  192. provided by this plugin (`discovery`). See <<repository-s3-usage>> for details.
  193. Multiple S3 repositories can be created. If the buckets require different
  194. credentials, then define them as part of the repository settings.
  195. [[repository-s3-permissions]]
  196. ===== Recommended S3 Permissions
  197. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  198. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  199. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  200. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  201. [source,js]
  202. ----
  203. {
  204. "Statement": [
  205. {
  206. "Action": [
  207. "s3:ListBucket",
  208. "s3:GetBucketLocation",
  209. "s3:ListBucketMultipartUploads",
  210. "s3:ListBucketVersions"
  211. ],
  212. "Effect": "Allow",
  213. "Resource": [
  214. "arn:aws:s3:::snaps.example.com"
  215. ]
  216. },
  217. {
  218. "Action": [
  219. "s3:GetObject",
  220. "s3:PutObject",
  221. "s3:DeleteObject",
  222. "s3:AbortMultipartUpload",
  223. "s3:ListMultipartUploadParts"
  224. ],
  225. "Effect": "Allow",
  226. "Resource": [
  227. "arn:aws:s3:::snaps.example.com/*"
  228. ]
  229. }
  230. ],
  231. "Version": "2012-10-17"
  232. }
  233. ----
  234. // NOTCONSOLE
  235. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  236. [source,js]
  237. ----
  238. {
  239. "Statement": [
  240. {
  241. "Action": [
  242. "s3:ListBucket",
  243. "s3:GetBucketLocation",
  244. "s3:ListBucketMultipartUploads",
  245. "s3:ListBucketVersions"
  246. ],
  247. "Condition": {
  248. "StringLike": {
  249. "s3:prefix": [
  250. "foo/*"
  251. ]
  252. }
  253. },
  254. "Effect": "Allow",
  255. "Resource": [
  256. "arn:aws:s3:::snaps.example.com"
  257. ]
  258. },
  259. {
  260. "Action": [
  261. "s3:GetObject",
  262. "s3:PutObject",
  263. "s3:DeleteObject",
  264. "s3:AbortMultipartUpload",
  265. "s3:ListMultipartUploadParts"
  266. ],
  267. "Effect": "Allow",
  268. "Resource": [
  269. "arn:aws:s3:::snaps.example.com/foo/*"
  270. ]
  271. }
  272. ],
  273. "Version": "2012-10-17"
  274. }
  275. ----
  276. // NOTCONSOLE
  277. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  278. registration will fail. If you want elasticsearch to create the bucket instead, you can add the permission to create a
  279. specific bucket like this:
  280. [source,js]
  281. ----
  282. {
  283. "Action": [
  284. "s3:CreateBucket"
  285. ],
  286. "Effect": "Allow",
  287. "Resource": [
  288. "arn:aws:s3:::snaps.example.com"
  289. ]
  290. }
  291. ----
  292. // NOTCONSOLE
  293. [[repository-s3-endpoint]]
  294. ===== Using other S3 endpoint
  295. If you are using any S3 api compatible service, you can set a global endpoint by setting `cloud.aws.s3.endpoint`
  296. to your URL provider. Note that this setting will be used for all S3 repositories.
  297. Different `endpoint`, `region` and `protocol` settings can be set on a per-repository basis
  298. See <<repository-s3-repository>> for details.
  299. [[repository-s3-aws-vpc]]
  300. [float]
  301. ==== AWS VPC Bandwidth Settings
  302. 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.
  303. 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.
  304. [[repository-s3-testing]]
  305. ==== Testing AWS
  306. Integrations tests in this plugin require working AWS configuration and therefore disabled by default. Three buckets
  307. and two iam users have to be created. The first iam user needs access to two buckets in different regions and the final
  308. bucket is exclusive for the other iam user. To enable tests prepare a config file elasticsearch.yml with the following
  309. content:
  310. [source,yaml]
  311. ----
  312. cloud:
  313. aws:
  314. access_key: AKVAIQBF2RECL7FJWGJQ
  315. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  316. repositories:
  317. s3:
  318. bucket: "bucket_name"
  319. region: "us-west-2"
  320. private-bucket:
  321. bucket: <bucket not accessible by default key>
  322. access_key: <access key>
  323. secret_key: <secret key>
  324. remote-bucket:
  325. bucket: <bucket in other region>
  326. region: <region>
  327. external-bucket:
  328. bucket: <bucket>
  329. access_key: <access key>
  330. secret_key: <secret key>
  331. endpoint: <endpoint>
  332. protocol: <protocol>
  333. ----
  334. Replace all occurrences of `access_key`, `secret_key`, `endpoint`, `protocol`, `bucket` and `region` with your settings.
  335. Please, note that the test will delete all snapshot/restore related files in the specified buckets.
  336. To run test:
  337. [source,sh]
  338. ----
  339. mvn -Dtests.aws=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  340. ----