IT/elasticsearch

elasticsearch - ilm 설정하기

할일없는라이프 2022. 8. 30. 15:02

elasticsearch 에서는 시계열 인덱스 저장 관리를 hot, warm, cold 로 진행을 할수 있다 이는 서버의 자원을 효율적으로 쓰기위한 방법이라고 생각하면 된다 서버 자원이 전부 좋다고 한다면 hot 혹은 그냥 data_contant 노드에 넣어두면 되나 우리는 조금이라도 서버를 효율적으로 사용해야 하기 때문에  ILM을 설정해서 운영하는것이 효율적이라 할 수 있다 

* 추가로 같은 종류의 노드를 운영하는 서버는 스펙이 같은게 좋습니다. 서능이 낮은 서버가 있다면 해당 인덱스의 속도는 하향 평준화 됩니다. 

참고 자료 

https://www.elastic.co/guide/en/elasticsearch/reference/8.4/index-lifecycle-management.html

 

ILM: Manage the index lifecycle | Elasticsearch Guide [8.4] | Elastic

To automatically back up your indices and manage snapshots, use snapshot lifecycle policies.

www.elastic.co

ILM의 노드 및 관리 개념

  • Hot: The index is actively being updated and queried. / 항시 업데이트와 쿼리를 진행하는 인덱스 노드 
  • Warm: The index is no longer being updated but is still being queried. /  업데이트는 없지만 쿼리자 자주 진행되는 인덱스 노드 
  • Cold: The index is no longer being updated and is queried infrequently. The information still needs to be searchable, but it’s okay if those queries are slower. /  업데이트 없으며 , 쿼리 요청도 가끔 있는 인덱스 노드 , 쿼리가 있더라도 속도가 느린노드 
  • Frozen: The index is no longer being updated and is queried rarely. The information still needs to be searchable, but it’s okay if those queries are extremely slow. / 업데이트 없으며 쿼리는 정말 가끔 있는 인덱스 노드, 정보를 보관하나 속도가 매우 느린 노드 
  • Delete: The index is no longer needed and can safely be removed. /  불필요 인덱스를 삭제 한다 

서버의 NODE tier 설정 (8.x 기준) 

서버의 config 설을을 오픈후 node role을 설정해주면 됩니다. 
서버의 설정파일은 설치된 운영 경로 아래 config/elasticsearch.yml 파일입니다.

#node1
node.roles: [data, master, data_hot]

#node2
node.roles: [data, data_warm]

#node3
node.roles: [data, data_cold, data_frozen]

 

lim 설정 (kibana)

메뉴 : manager > stack management > Index Lifecycle Policies 

  1.  create  policy 
  2. poilcy name 설정 
  3. 정책 설정
    1. hot phase 설정
      - Rollover 설정 : 인덱스 보관 조건? 을 설정할 수 있습니다. 기본 30일 50G 보관이나 사이트의 특성에 맞게 설정 가능 
         shard의 사이즈, primary shard의 행수, index의 사이즈 , index의 문서수, 인덱스 생성일을 기준으로 설정 가능 
      - Shrink : 인덱스의 샤드 수 or 사이즈 를 변경 
    2. warm phase 설정
      - Move data into phase when : 인덱스가 Rollover후 얼마나 있다 warm노드에 받아 드리겠는가에 대한 설정 
      -Replicas  : 레플리카 샤드의 수를 변경할수 있음 
      - Shrink : 인덱스의 샤드 수 or 사이즈 를 변경 
    3. cold phase 설정
      - Move data into phase when : 인덱스가 Rollover후  얼마나 있다 cold 노드에 받아 드리겠는가에 대한 설정 
      - Replicas  : 레플리카 샤드의 수를 변경할수 있음 
    4. Frozen or delete phase 설정
      - move date into phase when : 인덱스가 Rollover후  얼마나 있다  삭제되는가 

 

lim 설정(devtool)

PUT _ilm/policy/test001
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "30m",
        "actions": {
          "set_priority": {
            "priority": 100
          },
          "rollover": {
            "max_age": "20m"
          }
        }
      },
      "warm": {
        "min_age": "0s",
        "actions": {
          "set_priority": {
            "priority": 50
          },
          "allocate": {
            "number_of_replicas": 1
          },
          "shrink": {
            "number_of_shards": 2
          }
        }
      },
      "cold": {
        "min_age": "5m",
        "actions": {
          "set_priority": {
            "priority": 0
          },
          "allocate": {
            "number_of_replicas": 2
          }
        }
      },
      "delete": {
        "min_age": "15m",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

해당 스크립트는  ILM을 커멘드로 입력한 내용이며 내용은 
HOT 노드 20분 rollover 후  warm노드로 이동, 5분뒤 콜드 노드로 이동  15분뒤 삭제를 하는 ILM을 작성했다 
이렇게 kibana ui 나 curl을 이용해서 ILM정책을 만든뒤에  템플릿을 이용해서 ILM을 적용하면 인덱스 생성시 ILM이 적용된것을 확인할수 있다