Study
Elasticsearch + GCS repository
minung14
2020. 1. 28. 14:42
엘라스틱 서치에서 gcs 레포지토리를 등록하고 해당 레포지토리에 스냅샷을 생성, restore 하는 과정을 나타냄.
플러그인 설치와 키 등록은 엘라스틱 서치의 모든 노드에서 실행해주어야 함.
- 엘라스틱 서치에서 플러그인 설치
# repository-gcs 플러그인 설치
bin/elasticsearch-plugin install repository-gcs
- 버킷을 생성하고 key 파일 다운로드
- 해당 키 파일을 엘라스틱 서치 내의 폴더에 복사해두고 키 파일 등록
# keystore 사용하여 key file 등록
bin/elasticsearch-keystore add-file gcs.client.default.credentials_file 키파일경로
# 등록된 key 는 아래 명령어로 확인 가능
bin/elasticsearch-keystore list
- 엘라스틱 서치의 secure 셋팅 reload
curl -XPOST 'host:port/_nodes/reload_secure_settings'
# http://192.168.0.131:9200
- 엘라스틱 서치 모든 노드 재시작
# 도커로 엘라스틱을 띄웠기 때문에, 도커를 재시작 했음
docker-compose stop
docker-compose up
- 레포지토리 생성
curl -XPUT 'http://192.168.0.131:9200/_snapshot/gcs_repo[레포지토리명]' -d \
{
"type": "gcs", #레포지토리 타입
"settings": {
"bucket": "qa-elastic", #버킷이름
"client": "default",
"base_path": "qa" #버킷 내 경로
}
}
# 이렇게 하면 gcs_repo 라는 이름으로 repository 가 엘라스틱서치에서 등록이 되고,
# qa-elastic 이라는 버킷 내부에 qa 폴더 밑에 스냅샷이 저장이 된다.
- 스냅샷 생성
# index를 지정하여 스냅샷을 생성할 경우
curl -XPUT 'http://192.168.0.131:9200/_snapshot/레포지토리명/스냅샷이름' -d \
{
"indices": "embeddings", # 스냅샷으로 뜰 index
"ignore_unavailable": true,
"include_global_state": true
}
# fully index 로 스냅샷을 생성할 경우
curl -XPUT 'http://192.168.0.131:9200/_snapshot/레포지토리명/스냅샷이름'
8. 새로운 엘라스틱서치에 스냅샷 restore
curl -XPOST '새로운 host:port/_snapshot/레포지토리명/스냅샷명/_restore'
새로운 엘라스틱서치에서 스냅샷을 restore 하기 전에, 해당 gcs repository를 등록해야한다.
따라서 1-6 의 과정 필요함