티스토리 뷰

728x90

안녕하세요. 개발개입니다.

 

위키북스에서 나온 <엘라스틱서치 실무 가이드>를 공부하면서
정리한 부분을 다음과 같은 목차에 따라 공유합니다.

(설치와 관련된 포스트는 많기 때문에 따로 작성하지 않았습니다.)

 

  1. 엘라스틱서치의 이해 (1)

  2. 엘라스틱서치의 이해 (2)

  3. 데이터 모델링

  4. 엘라스틱서치 분석기

  5. 커스텀 분석기

 

이번 글은 엘라스틱서치의 이해에 대한 두 번째 포스팅입니다.

목차
- 엘라스틱서치 설정
- snapshot 만들기
- snapshot 복구하기

 

오타, 오류 혹은 기타 의견은 언제든지 환영합니다.

 

 

 

 


 

 

1. 엘라스틱서치 설정

설정 파일 위치

  • [elasticsearch디렉토리]\config\elasticsearch.yml

주요 항목 정보

  • cluster.name

    여러 노드를 묶기 위한 클러스터명

  • node.name

    노드명

  • path.data

    인덱스 경로

    디폴트는 /path/to/data

  • path.logs

    노드와 클러스터에서 생성되는 로그 저장 경로

    디폴트는 /path/to/logs

  • path.repo

    인덱스를 백업하기 위한 스냅숏 경로

  • network.host

    특정 IP만 접근 허용하기 위한 설정

    모든 IP 허용할 경우 : 0.0.0.0

  • http.port

    엘라스틱서치 API 호출을 위한 포트번호

    디폴트는 9200

  • transport.tcp.port

    엘라스틱서치 클라이언트가 접근할 수 있는 TCP 포트

    디폴트는 9300

  • discovery.zen.ping.unicast.hosts
    클러스터로 묶인 노드의 IP 지정
    e.g. [1.1.1.1, 2.2.2.2]

  • discovery.zen.minimum_master_nodes
    마스터 노드의 선출 기준이 되는 노드수 지정
    단일 노드는 설정 불필요

  • node.master
    마스터 노드로써 동작 여부 (true/false)

  • node.data
    데이터 노드로써 동작 여부 (true/false)

(참고)

노드의 종류
마스터 노드 (Master Node) 노드 추가/제거와 같은 전반적인 클러스터 관리
데이터 노드 (Data Node) 실질적인 데이터 저장 및 데이터 작업(검색/통계)을 수행
코디네이팅 노드 (Coordinating Node) 들어온 요청을 단순히 라운드로빈 방식으로 분산시킴
인제스트 노드 (Ingest Node) 전처리 작업. 인덱스 생성 전 문서 형식을 변경할 수 있음

 

 

 

2. snapshot 만들기

테스트 내용

elasticsearch.yml 파일 내 path.repo에 snapshot 데이터의 위치를 선언한다.
(여기서는 C:/Users/Public/backup/search_example와 C:/Users/Public/backup/agg_example)

search_example 폴더의 내용은 the-dev, agg_example 폴더의 내용은 web-log라는 이름으로 snapshot을 생성한다.

 

테스트 환경

  • Windows

  • elasticsearch-6.8.6

  • elasticsearch.yml 내 설정

path.repo: ["C:/Users/Public/backup/search_example", "C:/Users/Public/backup/agg_example"]

 

 

1.

cmd 실행 > elasticsearch 설치 폴더 내 bin 폴더로 이동 > elasticsearch.bat 실행 > 로그 중 Started 확인

 

2.

elasticsearch가 실행중인 cmd 창을 닫지 말고 새로 cmd 실행 > snapshot 추가 명령어 실행하여 결과 확인

 

- 명령어

curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/_snapshot/the-dev" -d "{\"type\": \"fs\", \"settings\": {\"location\":\"C:/Users/Public/backup/search_example\", \"compress\": true}}"

- 결과

{"acknowledged":true}

  > elasticsearch가 실행중인 cmd 창에서도 결과 확인

  (새로 추가된 경우 put, 기존에 있던 내용을 수정한 경우 update)

 

3. 

snapshot 추가 명령어 cmd에서 확인 명령어 실행하여 결과 확인

 

- 명령어

curl -XGET "http://localhost:9200/_snapshot/_all"

- 결과

{"the-dev":{"type":"fs","settings":{"compress":"true","location":"C:/Users/Public/backup/search_example"}},"web-log":{"type":"fs","settings":{"compress":"true","location":"C:/Users/Public/backup/agg_example"}}}

 > the-dev와 web-log로 생성한 레파지토리가 모두 확인됨

 > 해당 location에 백업 인덱스가 있었다면 다음과 같은 각 명령어 실행하여 정보 확인 가능

 

- the-dev 스냅샷 확인 명령어

curl -XGET "http://localhost:9200/_snapshot/the-dev/_all"

- 결과

{"snapshots":[{"snapshot":"movie-search","uuid":"Kz5k4fusS7KBZy55wLeZ0Q","version_id":6040399,"version":"6.4.3","indices":["movie_search"],"include_global_state":false,"state":"SUCCESS","start_time":"2019-03-23T16:01:04.910Z","start_time_in_millis":1553356864910,"end_time":"2019-03-23T16:01:05.342Z","end_time_in_millis":1553356865342,"duration_in_millis":432,"failures":[],"shards":{"total":5,"failed":0,"successful":5}}]}

- web-log 스냅샷 확인 명령어

curl -XGET "http://localhost:9200/_snapshot/web-log/_all"

- 결과

{"snapshots":[{"snapshot":"default","uuid":"yzmzEx6uSMS55j60z4buBA","version_id":6040399,"version":"6.4.3","indices":["apache-web-log"],"include_global_state":false,"state":"SUCCESS","start_time":"2019-03-23T16:03:50.351Z","start_time_in_millis":1553357030351,"end_time":"2019-03-23T16:03:50.604Z","end_time_in_millis":1553357030604,"duration_in_millis":253,"failures":[],"shards":{"total":5,"failed":0,"successful":5}},{"snapshot":"applied-mapping","uuid":"SgXhqApiSHiauC6fbjSHMw","version_id":6040399,"version":"6.4.3","indices":["apache-web-log-applied-mapping"],"include_global_state":false,"state":"SUCCESS","start_time":"2019-03-23T16:05:46.038Z","start_time_in_millis":1553357146038,"end_time":"2019-03-23T16:05:46.364Z","end_time_in_millis":1553357146364,"duration_in_millis":326,"failures":[],"shards":{"total":5,"failed":0,"successful":5}}]}

 (해당 location이 빈 디렉토리였다면 빈 데이터가 리턴됨)

 

 

 

3. snapshot 복구하기

1.

cmd에서 생성한 snapshot 확인

- 명령어

curl -XGET "http://localhost:9200/_snapshot/the-dev/_all?pretty"

- 결과

{
  "snapshots" : [
    {
      "snapshot" : "movie-search",
      "uuid" : "Kz5k4fusS7KBZy55wLeZ0Q",
      "version_id" : 6040399,
      "version" : "6.4.3",
      "indices" : [
        "movie_search"
      ],
      "include_global_state" : false,
      "state" : "SUCCESS",
      "start_time" : "2019-03-23T16:01:04.910Z",
      "start_time_in_millis" : 1553356864910,
      "end_time" : "2019-03-23T16:01:05.342Z",
      "end_time_in_millis" : 1553356865342,
      "duration_in_millis" : 432,
      "failures" : [ ],
      "shards" : {
        "total" : 5,
        "failed" : 0,
        "successful" : 5
      }
    }
  ]
}

2.

"indices" 안 index명과 동일한 index가 있다면 먼저 삭제

- 명령어

curl -XDELETE "http://localhost:9200/movie_search"

- 결과 (동일한 index가 있어서 삭제한 경우. 없으면 404에러가 리턴됨)

{
  "acknowledged" : true
}

3.

cmd에서 snapshot 복구

- 명령어

curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/_snapshot/the-dev/movie-search/_restore"

- 결과

{"accepted":true}

 

 

 

다음 이야기 : [Elasticsearch] - 3. 데이터 모델링

 

 

 

 


 

 

 

본 글은 다음을 참고하여 작성되었습니다.

 

권택환 외, 엘라스틱서치 실무가이드, 위키북스

 

 

 

 

 

728x90
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
04-29 08:39