repository-s3.asciidoc 14 KB

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