Search

OpenSearch 인덱스 자동 정리

생성일
2024/08/13 14:18
Category
Devops 엔지니어
태그
Monitoring
OpenSearch

배경

인덱스 자동 삭제에 대해 정리한다.

내용

로그 모니터링은 수집도 중요하지만 로그 삭제 정리도 굉장히 중요하다.
OpenSearch 의 경우 로그 정리가 되지 않으면, 클러스터의 샤드 갯수 초과로 로그가 수집 되지 않는 등의 문제가 발생 할 수 있다.
즉, 주기적인 로그 정리는 필수적인 조건이라고 할 수 있다.
하지만 이걸 매일매일 수동으로 정리하려면 할 수 있겠는가?
은근히 신경 쓸것도 많고 시간도 걸릴 수 있기 때문에 이런건 자동화로 진행 하는 것이 효율 적이다.

정리

OpenSearch 대시보드에서 State management policies 메뉴로 들어간다.
Create policy 를 클릭한다.
JSON editor 를 선택한다.
Name plicy 에는 Policy 명을 적절하게 넣고, Define policy 에는 아래 코드를 넣는다.
{ "id": "alpha-policy-1", "seqNo": 1, "primaryTerm": 1, "policy": { "policy_id": "alpha-policy-1", "description": "delete old indexes", "last_updated_time": 1684390688243, "schema_version": 16, "error_notification": null, "default_state": "hot", "states": [ { "name": "hot", "actions": [], "transitions": [ { "state_name": "delete", "conditions": { "min_index_age": "5d" } } ] }, { "name": "delete", "actions": [ { "retry": { "count": 3, "backoff": "exponential", "delay": "1m" }, "notification": { "destination": { "slack": { "url": "https://hooks.slack.com/services/xxx/xxxx/xxx" } }, "message_template": { "source": "The index {{ctx.index}} is being deleted", "lang": "mustache" } } }, { "retry": { "count": 3, "backoff": "exponential", "delay": "1m" }, "delete": {} } ], "transitions": [] } ], "ism_template": [ { "index_patterns": [ "platform-alpha-log*" ], "priority": 0, "last_updated_time": 1684390359447 } ] } }
JSON
복사
slack.url 에는 Slack 으로 알림을 받기 위해 Hook url 을 넣었고, index_patterns 에 원하는 인덱스를 넣어주면 된다.