repository-s3.asciidoc 14 KB

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