티스토리 뷰

ELK

[ELK] Curator - Elasticsearch 로그 관리

Network && Devops 2020. 7. 14. 15:31
반응형

Elasticsearch를 관리자는 관리자 입장에서 또 하나 중요한 부분은 로그에 대한 관리이다. 매일 수십~수백만건이상의 로그를 수집할 경우 언젠간 로그서버의 데이터는 용량 부족으로인한 문제가 발생할 수 있다.

  관리자가 주기적으로 오래된 로그를 삭제해 주면 되지만 자동으로 오래된 데이터를 삭제하고 관리할수 있는 Qurator(큐레이터)를 사용하여 자동으로 로그 데이터를 삭제해 주는 시스템을 구축할 수 있다. 

  1. Curator 설치

pip install elasticsearch-curator

    ※ 만약 pip 이 설치되어 있지 않다면, epel 저장소를 추가한 후 python-pip을 설치해 주면 된다.
       yum install epel-release 
       yum install python-pip

 - curator 버전 확인.
    curator는 현재 5.8버전까지 release 되었으며 최신 버전이 설치된것을 확인 할 수 있다

[root@localhost]# curator --version
curator, version 5.8.1

2. Curator Config 파일 작성(curator-config.yml)
  - vi /path/to/curator/curator-config.yml 

---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 127.0.0.1
  port: 9200
  url_prefix:
  use_ssl: False
  certificate:
  client_cert:
  client_key:
  ssl_no_validate: False
  http_auth:
  timeout: 30
  master_only: False

logging:
  loglevel: INFO
  logfile:
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

 - YAML 형식으로 구성된 파일이며, 최상위에 client / logging 키 값이 정의 되어 있어야 한다. 
  구성파일에 대한 세부 항목에 대한 설정 정보 및 구성 방법은 아래 elastic 사이트에서 확인이 가능하다.
  https://www.elastic.co/guide/en/elasticsearch/client/curator/5.8/configfile.html#aws_region

 

3. Action 파일 생성
  - vi /path/to/curator/delete.yml

  - Action파일은 Curator가 Elasticsearch 인덱스에서 실제 수행할 작업내용이 들어있다. 수행할 인덱스 및 삭제할 데이터의 일자등을 정해 줄 수 있다.
 아래는 "logstash-", "switch-"  로 시작하는 인덱스에 대해서 90일 이상 지난 데이터를 삭제하는 설정 이다.
 인덱스가 여러개일 경우 id(숫자)를 추가해서 작성해 주면 된다. 

---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True.  If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
  1:
   action: delete_indices
   options:
     ignore_empty_list: True
     disable_action: False 
   filters:
   - filtertype: pattern
     kind: prefix
     value: logstash-
     exclude:
   - filtertype: age
     source: name
     direction: older
     timestring: '%Y.%m.%d'
     unit: days
     unit_count: 90
     exclude:
     
  2:
   action: delete_indices
   options:
     ignore_empty_list: True
     disable_action: False 
   filters:
   - filtertype: pattern
     kind: prefix
     value: switch-
     exclude:
   - filtertype: age
     source: name
     direction: older
     timestring: '%Y.%m.%d'
     unit: days
     unit_count: 90
     exclude:

 

4. Curator action 파일 실행
  - config 파일, Action 파일 작성이 완료되었으면 아래와 같이 실행하면 90일 이상 지난 파일은 삭제가 된다. 

 /usr/bin/curator --config /path/to/curator/curator-config.yml --dry-run /path/to/curator/delete.yml

 ◼ DRY-RUN 
  - dry-run 명령어를 사용하면 에러 확인 및 삭제예정인 파일에 대해서 미리 확인해 볼수 있다. 
    작성일자(2020년 7월 15일) 기준 90일 이전 파일을 삭제하도록 설정하여 2020년 4월 16일 이전 데이터는 삭제가 된다는걸 확인 할 수 있다.  

/usr/bin/curator --config /path/to/curator/curator-config.yml --dry-run /path/to/curator/delete.yml

/usr/bin/curator --config /path/to/curator/curator-config.yml --dry-run /path/to/curator/delete.yml

2020-07-15 11:21:07,832 INFO      Preparing Action ID: 1, "delete_indices"
2020-07-15 11:21:07,833 INFO      Creating client object and testing connection
2020-07-15 11:21:08,008 INFO      Instantiating client object
2020-07-15 11:21:08,027 INFO      Testing client connectivity
2020-07-15 11:21:08,204 INFO      Successfully created Elasticsearch client object with provided settings
2020-07-15 11:21:08,210 INFO      Trying Action ID: 1, "delete_indices": No description given
2020-07-15 11:21:08,976 INFO      DRY-RUN MODE.  No changes will be made.
2020-07-15 11:21:08,977 INFO      (CLOSED) indices may be shown that may not be acted on by action "delete_indices".
2020-07-15 11:21:08,977 INFO      DRY-RUN: delete_indices: logstash-2020.04.15 with arguments: {}
2020-07-15 11:21:08,977 INFO      DRY-RUN: delete_indices: switch-2020.04.16 with arguments: {}
2020-07-15 11:21:08,982 INFO      Action ID: 1, "delete_indices" completed.
2020-07-15 11:21:08,982 INFO      Job completed.

dry-run 옵션을 빼고 실행하면 실제 삭제가 완료 된다. 

/usr/bin/curator --config /path/to/curator/curator-config.yml --dry-run /path/to/curator/delete.yml

2020-07-15 12:30:36,761 INFO      Preparing Action ID: 1, "delete_indices"
2020-07-15 12:30:36,762 INFO      Creating client object and testing connection
2020-07-15 12:30:36,763 INFO      Instantiating client object
2020-07-15 12:30:36,765 INFO      Testing client connectivity
2020-07-15 12:30:36,771 INFO      Successfully created Elasticsearch client object with provided settings
2020-07-15 12:30:36,774 INFO      Trying Action ID: 1, "delete_indices": No description given
2020-07-15 12:30:37,466 INFO      Deleting 2 selected indices: [u'switch-2020.04.16', u'switch-2020.04.15']
2020-07-15 12:30:37,466 INFO      ---deleting index logstash-2020.04.16
2020-07-15 12:30:37,466 INFO      ---deleting index logstash-2020.04.15
2020-07-15 12:30:37,650 INFO      Action ID: 1, "delete_indices" completed.
2020-07-15 12:30:37,650 INFO      Job completed.

 

5. Cron 등록 및 스케줄링 Job 생성

0 3 * * * /usr/bin/curator --config /path/to/curator/curator-config.yml /path/to/curator/delete.yml

※ 매일 새벽 3시에 curator를 실행하여 데이터를 삭제하도록 설정

 

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 31
글 보관함