http://127.0.0.1:9200/_cat/indices?v
-
-
#删除ELK30天前的日志
-
-
DATE=`date -d "30 days ago" +%Y.%m.%d`
-
-
curl -s -XGET http://127.0.0.1:9200/_cat/indices?v| grep $DATE | awk -F '[ ]+' '{print $3}' >/tmp/elk.log
-
-
for elk in `cat /tmp/elk.log`
-
-
do
-
-
curl -XDELETE "http://127.0.0.1:9200/$elk"
-
-
done
二:加入到定时任务
-
# crontab -e
-
-
#每天凌晨1点定时清理elk索引
-
-
00 01 * * * bash /server/scripts/elk.sh &>/dev/null
注意:保证crond服务是启动的
[root@server scripts]# service crond status
crond (pid 1999) is running...
++++++脚本2未验证++++++++++++++++++++++++++++++
脚本2
#/bin/bash
#es-index-clear
#只保留7天内的日志索引
LAST_DATA=`date -d "-7 days" "+%Y.%m.%d"`
#删除上个月份所有的索引
curl -u elastic:xxxx(密码) -XDELETE 'http://192.168.12.31:9200/*-'${LAST_DATA}'*'