elasticsearch 6.3.0 快照

install plugins and set client(all nodes of open source es)

install plugin

bin/elasticsearch-plugin install repository-s3

set up client

bin/elasticsearch-keystore add s3.client.default.access_key
bin/elasticsearch-keystore add s3.client.default.secret_key

vim /etc/elasticsearch/elasticsearch.yml
add configure

s3.client.default.endpoint: s3.cn-northwest-1.amazonaws.com.cn

create repository

open source es

PUT _snapshot/my_s3_repository
{
  "type": "s3",
  "settings": {
    "bucket": "iz.es.snapshot",
    "base_path": "20180919"
  }
}

aws es
if your es is aws es service, you should create a role for es with policy to s3

aws iam create-role --role-name es-s3-repository --assume-role-policy-document '{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "",
    "Effect": "Allow",
    "Principal": {
      "Service": "es.amazonaws.com"
    },
    "Action": "sts:AssumeRole"
  }]
}'

attach policy

{
    "Version":"2012-10-17",
    "Statement": [
        {
            "Action": [ "s3:ListBucket" ],
            "Effect": "Allow",
            "Resource": [ "arn:aws-cn:s3:::iz.es.snapshot" ]
        },
        {
            "Action": ["s3:GetObject",
                       "s3:PutObject",
                       "s3:DeleteObject",
                       "iam:PassRole"
                      ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws-cn:s3:::iz.es.snapshot/*"
            ]
        }
    ]
}

create repository by python script(aws cli should be configured)

import boto3
import requests
from requests_aws4auth import AWS4Auth


host = 'https://search-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.cn-northwest-1.es.amazonaws.com.cn'
region = 'cn-northwest-1'
service = 'es'
credentials = boto3.Session().get_credentials()
print(type(credentials))
print(credentials)
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)

# Register repository

path = '/_snapshot/my_s3_repository'
url = host + path

payload = {
  "type": "s3",
  "settings": {
    "bucket": "iz.es.snapshot",
    "region": "cn-northwest-1",
    "base_path": "20180919",
    "role_arn": "arn:aws-cn:iam::[your_account_id]:role/es-s3-repository"
  }
}

headers = {"Content-Type": "application/json"}

r = requests.put(url, auth=awsauth, json=payload, headers=headers)

print(r.status_code)
print(r.text)

create snapshot

all indices

PUT _snapshot/my_s3_repository/snapshot_20180919

particular indices

PUT _snapshot/my_s3_repository/snapshot_20180919
{
    "indices": "index_1,index_2"
}

monitor snapshot

GET _snapshot/my_s3_repository/_all
GET _snapshot/my_s3_repository/snapshot_20180919
GET _snapshot/my_s3_repository/snapshot_20180919/_status
DELETE _snapshot/my_s3_repository/snapshot_20180919

restore from a snapshot

POST _snapshot/my_s3_repository/snapshot_20180919/_restore
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章