首先:
感謝博主:參考博客:https://www.orchome.com/477
對於針對性的索引清理定期數據可行方法:
1.手動清理
可基於kibana索引管理進行索引數據清理
2.api清理
curl -XDELETE 'http://ip:端口/索引'
3.腳本清理
#!/bin/sh
# example: sh delete_es_by_day.sh logstash-kettle-log logsdate 30
index_name=$1
daycolumn=$2
savedays=$3
format_day=$4
if [ ! -n "$savedays" ]; then
echo "the args is not right,please input again...."
exit 1
fi
if [ ! -n "$format_day" ]; then
format_day='%Y%m%d'
fi
sevendayago=`date -d "-${savedays} day " +${format_day}`
curl -X POST "ip:端口/${index_name}/_delete_by_query?pretty" -H "Content-Type: application/json" -d '
{
"query": {
"range": {
"'${daycolumn}'": {
"from": null,
"to": '${sevendayago}'
}
}
}
}'
echo "ok"
#/bin/bash
# 定時清理微服務子系統日志
# 只保留10天內的日志索引
savedays=$1
ip=$2
port=$3
LAST_DATA=`date -d "-${savedays} days" "+%Y.%m.%d"`
curl -XDELETE 'http://'${ip}':'${port}'/*-'${LAST_DATA}'*'
4.基於腳本定時任務清理數據
將腳本添加到定時任務,定期執行
修改crontab 編輯器: https://www.twle.cn/t/492
linux nano語法:https://www.cnblogs.com/wx170119/p/12084397.html
0 0 * * * root /opt/elk/cron/delete_log.sh ct-oa-operationlog createDate 15 05 0 * * * root /opt/elk/cron/delete_log.sh ct-oa-loginlog landingTime 30 10 0 * * * root /opt/elk/cron/delete_log.sh ct-dmp-operationlog createDate 15 30 0 * * * root /opt/elk/cron/es_index_clear.sh 15 ip 端口
5.基於elasticsearch-curator定時清理
https://www.cnblogs.com/java-zhao/p/5900590.html
6.基於索引生命周期ILM
