'2017/08/03'에 해당되는 글 1건

  1. 2017.08.03 [Elasticsearch] Snapshot and Restore 알아보기

[Elasticsearch] Snapshot and Restore 알아보기

Elastic/Elasticsearch 2017. 8. 3. 11:23

Elasticsearch 에서 제공하는 Snapshot과 Restore 기능에 대해서 정리합니다.


Snapshot과 Restore 기능에 대한 정의와 설명은 아래 본문에 잘 나와 있습니다.


[원본 문서]

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

https://www.elastic.co/guide/en/elasticsearch/guide/current/backing-up-your-cluster.html


※ 각 API의 상세 옵션과 설명은 원본 문서 참고 하시면 됩니다.


[발췌]

The snapshot and restore module allows to create snapshots of individual indices or an entire cluster into a remote repository like shared file system, S3, or HDFS. These snapshots are great for backups because they can be restored relatively quickly but they are not archival because they can only be restored to versions of Elasticsearch that can read the index. That means that:


  • A snapshot of an index created in 2.x can be restored to 5.x.
  • A snapshot of an index created in 1.x can be restored to 2.x.
  • A snapshot of an index created in 1.x can not be restored to 5.x.

글에서도 보시는 것 처럼 snapshot type 은 아래와 같이 지원 합니다.
  • fs
  • s3
  • hdfs
  • gcs

각 type을 지정하고 사용하기 위해서는 아래와 같은 추가 작업이 필요 합니다.


fs)

클러스터 내 모든 노드에 path.repo 설정 후 재시작 합니다.

- elasticsearch.yml

반드시 shared file system 적용을 해주셔야 합니다. 


s3)

클러스터 내 모든 노드에 plugin 설치를 해주셔야 합니다.

aws의 s3를 사용하기 위해서는 repository plugin 을 설치해야 합니다.


2.x)

bin/plugin install cloud-aws


5.x)

bin/elasticsearch-pluin install repository-s3


hdfs)

https://github.com/elastic/elasticsearch-hadoop/tree/master/repository-hdfs


클러스터 내 모든 노드에 plugin 설치를 해주셔야 합니다.

hadoop file system을 사용하기 위해서는 repository plugin 을 설치해야 합니다.


2.x)

bin/plugin install elasticsearch-repository-hdfs


5.x)

bin/elasticsearch-pluin install repository-hdfs


gcs)

클러스터 내 모든 노드에 plugin 설치를 해주셔야 합니다.

google cloud storage를 사용하기 위해서는 repository plugin 을 설치해야 합니다.


5.x)

bin/elasticsearch-pluin install repository-gcs


azure)

https://github.com/elastic/elasticsearch-cloud-azure


클러스터 내 모든 노드에 plugin 설치를 해주셔야 합니다.

azure repository를 사용하기 위해서는 repository plugin 을 설치해야 합니다.


2.x)

bin/plugin install elasticsearch/elasticsearch-cloud-azure


5.x)

bin/elasticsearch-pluin install repository-azure


이 중 2.X 클러스터에서 제가 추천 하는 것은 fs, s3 입니다.

이유는 다른건 제가 경험이 없어서 좋은지 나쁜지는 모릅니다.


fs, s3 에 대한 예제를 가지고 snapshot 과정과 restore 과정을 살펴 보겠습니다.


[fs]

step 1)

snapshot 기능을 수행 하기 위한 snapshot 저장소를 생성 합니다.


$ curl -XPUT 'localhost:9200/_snapshot/fs_snapshot?pretty' -d '{

    "type": "fs",

    "settings": {

        "location": "/mount/snapshot",

        "compress": true

    }

}'


step 2)

snapshot 할 대상을 선정하고 실행 합니다.


$ curl -XPUT 'localhost:9200/_snapshot/fs_snapshot/logstash_20170803?pretty' -d '

{

  "indices": "logstash-web-20170803,logstash-app-20170803",

  "ignore_unavailable": true,

  "include_global_state": false

}'


step 3)

이제 restore 해보겠습니다.


$ curl -XPOST 'localhost:9200/_snapshot/fs_snapshot/logstash_20170803/_restore'


[s3]

step 1)

snapshot 기능을 수행 하기 위한 snapshot 저장소를 생성 합니다.


$ curl -XPUT 'localhost:9200/_snapshot/s3_snapshot?pretty' -d '{

    "type": "s3",

    "settings": {

        "bucket": "s3-bucket",

        "region": "ap-northeast-2"

    }

}'


step 2)

snapshot 할 대상을 선정하고 실행 합니다.


$ curl -XPUT 'localhost:9200/_snapshot/s3_snapshot/logstash_20170803?pretty' -d '

{

  "indices": "logstash-web-20170803,logstash-app-20170803",

  "ignore_unavailable": true,

  "include_global_state": false

}'


step 3)

이제 restore 해보겠습니다.


$ curl -XPOST 'localhost:9200/_snapshot/s3_snapshot/logstash_20170803/_restore'


하나의 클러스터 내 여러개의 snapshot repository 를 등록해서 사용 하셔도 되기 때문에 목적에 맞게 사용 하시면 좋을 것 같습니다.


이 과정들은 모두 background 로 동작 하기 때문에 실행 후 바로 acknowledged/accepted 가 전달 됩니다.

그렇기 때문에 실행한 snapshot 의 상태 점검을 하셔야 합니다.


$ curl -XGET 'localhost:9200/_snapshot/s3_snapshot/logstash_20170803/_status'


추가적으로 사용하시면서 약간의 주의점 공유 드립니다.

- 더이상 색인 작업이 발생 하지 않는 index 들에 대해서 snapshot 작업을 수행하시면 좋습니다.

- restore 시는 대상 index 가 없거나 close 되어 있어야 하기 때문에 지속적인 색인 작업이 발생 하는 index에 대한 snapshot은 추천 하지 않지만, 아직 필요한 경우를 찾지는 못했습니다.


: