ELKstack-数据过期自动清理

2017年12月25日18:30:09 发表评论 2,296 views
广告也精彩

一、数据过期自动清理脚本

1)创建脚本

[root@jump tmp]# cat /server/scripts/check_elk.sh
[root@jump tmp]# chmod +x /server/scripts/check_elk.sh

2)脚本如下:(保留最近7天的日志)

#!/bin/bash
##############################################################
# File Name: check_log.sh
# Version: V1.0
# Author: yuetao qiu
# Organization:http://blog.51cto.com
# Created Time : 2017-02-20 12:32:57 
##############################################################
#The index five days ago
IP=服务器ip
## 如果你的es 不是默认端口,请在IP后面添加端口号,例如“http://$IP:9222:”
curl -XGET "http://$IP/_cat/shards" |grep $IP |awk '{print $1}' |grep `date -d "7 days ago" +%Y.%m.%d` |uniq > /tmp/index_name.tmp

for index_name in `cat /tmp/index_name.tmp`
do
    curl -XDELETE  http://$IP:9200/$index_name
    echo "${index_name} delete success" >> /home/scripts/del_elasticseatch_index.log
done

二、添加定时(手动执行成功后)

[root@jump tmp]# crontab -l
####clear_elk###
00 1 * * * /server/scripts/check_elk.sh >/dev/null 2>&1

问题1

ELKstack-数据过期自动清理
ELK自动化平台-数据过期自动清理

处理:

将过期或损坏的分配进行移除,从新建立索引即可
ELKstack-数据过期自动清理

至此ELK自动化平台-数据过期自动清理

  • QQ精品交流群
  • weinxin
  • 微信公众号
  • weinxin
广告也精彩
admin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: