环境:
window10
elasticsearch 7.16.3
jdk 11
目录
需求:想要定时删除几天前es的索引数据
一、介绍
Curator是elasticsearch 官方的一个索引管理工具,可以通过配置文件的方式帮助我们对指定的一批索引进行创建/删除、打开/关闭、快照/恢复等管理操作
二、配置
官方配置示例:https://github.com/elastic/curator/tree/master/examples
1、创建 curator.yml
注意:文件中出现中文
修改hosts节点,为自己的es地址
client:
hosts:
- localhost
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']
2、创建 delete_indices.yml
注意:文件中出现中文
unit_count这里我设置为3天, value匹配filebeat前缀的索引
# 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
description: >-
Delete indices older than 3 days (based on index name), for test-
prefixed indices. Ignore the error if the filter does not result in an
actionable list of indices (ignore_empty_list) and exit cleanly.
options:
ignore_empty_list: True
timeout_override:
continue_if_exception: True
disable_action: False
filters:
- filtertype: kibana
exclude: True
- filtertype: opened
exclude: False
- filtertype: pattern
kind: prefix
value: filebeat-
exclude:
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 3
exclude: false
说明:
ignore_empty_list : 如果为True,则在filters空列表时,继续下一个action处理而不是退出程序。
disable_action :action开关,为True表示不执行这个action,默认False
continue_if_exception :发现错误后,继续执行下一个索引操作,默认False
- filtertype: kibana : 是否排除隐藏索引,如.kibana
- filtertype: opened :是否排除open状态的索引
- filtertype: pattern :前缀匹配
- filtertype: age :处理多少天前的索引
三、运行
cmd运行:
curator --config curator.yml delete_indices.yml