ES历史索引清理:脚本&手动

您所在的位置:网站首页 es索引数据删除 ES历史索引清理:脚本&手动

ES历史索引清理:脚本&手动

2024-01-13 09:03| 来源: 网络整理| 查看: 265

文章有所更新,可以移步查看此篇ES历史索引清理-总结

方法一:脚本清理

删除15天以前的索引(索引仅保存15天) 思路:拿到索引名 -> 输出到指定文件内 -> 通过接口对文件内的索引进行删除

#/bin/bash #指定日期(15天前) Clear_Time=`date -d "15 days ago" +%Y.%m.%d` Today=`date` #拿到15天以前的索引,输出到以15天为时间命名的文件中 如:index.2021.10.12 curl -s -XGET 'http://192.xxx.xxx.51:9200/_cat/indices' |awk '{print $3}'|grep $Clear_Time > /opt/clear_index/index.$Clear_Time #声明清理动作 (最终会在crontab定义的/opt/ES_Timing_Clear/es_clear.log日志中看到操作) echo "In $Today start to clear "$Clear_Time" 's old indices>>>>>>>>" #对新输出到index.2021.10.12文件内的索引 进行删除 for i in `cat /opt/clear_index/index.$Clear_Time` do sleep 3 curl -s -XDELETE http://192.xxx.xxx.51:9200/$i done echo "=======================" echo "清理完成" echo "=======================" #每天凌晨3点执行 crontab -e 0 03 * * * /bin/bash /opt/ES_Timing_Clear/ES_clear.sh >> /opt/ES_Timing_Clear/es_clear.log 方法二: for 循环临时清理

思路:拿到索引名 -> 输出到某个文件内 -> for循环删除

2.1 过滤某个索引名,输出到指定文件|如果是针对所有的把grep去掉即可 curl -s -XGET 'http://192.xxx.xxx.51:9200/_cat/indices' |grep prophet-filebeat-6.5.1|sort -u|awk '{print $3}' >> a.es.log 2.2 for循环删除 for i in `cat a.es.log`;do curl -s -XDELETE http://192.xxx.xxx.51:9200/$i;done

Tips,先在测试环境跑一下脚本,跑通后再放到生产环境运行,以免删错索引。 方法一中拿到索引那一步,需要注意怎样才能匹配到想要删除的索引名

本文参考: https://blog.csdn.net/qq_36196879/article/details/103040226?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.control



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3