使用Elasticsearch Curator配置crontab自动删除指定时间前的索引

下载
https://packages.elastic.co/GPG-KEY-elasticsearch
https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.8.1-1.x86_64.rpm

上传到服务器并安装
rpm --import GPG-KEY-elasticsearch
rpm -ivh elasticsearch-curator-5.8.1-1.x86_64.rpm

建立配置文件保存目录
mkdir -p /etc/elasticsearch-curator


下载实例配置文件
下载 https://github.com/elastic/curator
curator-master.zip
解压curator-master.zip
将examples目录下的内容
上传到服务器
# tree /etc/elasticsearch-curator
/etc/elasticsearch-curator
—— actions
—— —— alias.yml
—— —— allocation.yml
—— —— close.yml
—— —— create_index.yml
—— —— delete_indices.yml
—— —— delete_snapshots.yml
—— —— forcemerge.yml
—— —— freeze.yml
—— —— open.yml
—— —— replicas.yml
—— —— restore.yml
—— —— shrink.yml
—— —— snapshot.yml
—— —— unfreeze.yml
—— curator.yml

修改配置,启用删除设置
# vi delete_indices.yml
修改disable_action设置值为False
disable_action: False

直接测试运行删除45天前的value: logstash-开头索引
# /usr/bin/curator --config /etc/elasticsearch-curator/curator.yml /etc/elasticsearch-curator/actions/delete_indices.yml

自定义删除时间
# vi delete_indices.yml
修改unit_count设置值为30,删除30天前的索引
unit_count: 30

配置计划任务,自动执行
# crontab -e
30 2 * * * /usr/bin/curator --config /etc/elasticsearch-curator/curator.yml /etc/elasticsearch-curator/actions/delete_indices.yml >>/var/log/curator.log 2>&1
# crontab -l
30 2 * * * /usr/bin/curator --config /etc/elasticsearch-curator/curator.yml /etc/elasticsearch-curator/actions/delete_indices.yml >>/var/log/curator.log 2>&1

猜你喜欢

转载自blog.csdn.net/allway2/article/details/108867158
今日推荐