博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ELK批量删除索引
阅读量:5058 次
发布时间:2019-06-12

本文共 3955 字,大约阅读时间需要 13 分钟。

存在问题

用了一段时间elk发现如果索引长时间不删除,elk会越来越慢,重启elasticsearch服务器节点之前同步时间也会很长

解决方法

第一步:在elasticsearch节点上使用curl -XGET 'http://192.168.X.XX:9200/_cat/shards'查看索引

[root@192-168-X-XXX ~]#  curl -XGET 'http://192.168.X.X:9200/_cat/shards' |more  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100 57452  100 57452    0     0   467k      0 --:--:-- --:--:-- --:--:--  471klaravel-oms26-online-2017.08.02              1 r STARTED     48 101.8kb 192.168.X.X node2-192.168.X.Xlaravel-oms26-online-2017.08.02              1 p STARTED     48 101.8kb 192.168.X.XX node1-192.168.X.XXlaravel-oms26-online-2017.08.02              4 r STARTED     65 118.1kb 192.168.X.XXX node3-192.168.X.XXXlaravel-oms26-online-2017.08.02              4 p STARTED     65 118.1kb 192.168.X.XX node1-192.168.X.XXlaravel-oms26-online-2017.08.02              2 p STARTED     42  61.4kb 192.168.X.X node2-192.168.X.Xlaravel-oms26-online-2017.08.02              2 r STARTED     42  61.4kb 192.168.X.XXX node3-192.168.X.XXXlaravel-oms26-online-2017.08.02              3 r STARTED     52 130.5kb 192.168.X.XXX node3-192.168.X.XXXlaravel-oms26-online-2017.08.02              3 p STARTED     52 130.5kb 192.168.X.XX node1-192.168.X.XXlaravel-oms26-online-2017.08.02              0 p STARTED     37 105.2kb 192.168.X.X node2-192.168.X.Xlaravel-oms26-online-2017.08.02              0 r STARTED     37 105.2kb 192.168.X.XX node1-192.168.X.XXetl213-online-2017.08.01                     1 r STARTED    649 244.6kb 192.168.X.XXX node3-192.168.X.XXXetl213-online-2017.08.01                     1 p STARTED    649 244.6kb 192.168.X.XX node1-192.168.X.XXetl213-online-2017.08.01                     4 r STARTED    673 295.3kb 192.168.X.X node2-192.168.X.Xetl213-online-2017.08.01                     4 p STARTED    673 295.3kb 192.168.X.XXX node3-192.168.X.XXXetl213-online-2017.08.01                     2 r STARTED    663 264.1kb 192.168.X.X node2-192.168.X.Xetl213-online-2017.08.01                     2 p STARTED    663 264.1kb 192.168.X.XX node1-192.168.X.XXetl213-online-2017.08.01                     3 p STARTED    640   280kb 192.168.X.X node2-192.168.X.Xetl213-online-2017.08.01                     3 r STARTED    640   280kb 192.168.X.XX node1-192.168.X.XXetl213-online-2017.08.01                     0 r STARTED    670 286.2kb 192.168.X.XXX node3-192.168.X.XXXetl213-online-2017.08.01                     0 p STARTED    670 286.2kb 192.168.X.XX node1-192.168.X.XX

 

第二步:过滤出想要删除的索引存到临时文件里面 curl -XGET 'http://192.168.X.X:9200/_cat/shards' |grep "2017\.08\.01" |grep 192.168.X.XX |awk '{print $1}' | uniq >  elk-index.tmp

[root@192-168-X-XXX ~]# curl -XGET 'http://192.168.X.X:9200/_cat/shards' |grep "2017.08\.01" |grep 192.168.X.XX |awk '{print $1}' | uniq > elk-index.tmp  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100 57452  100 57452    0     0   123k      0 --:--:-- --:--:-- --:--:--  123k[root@192-168-X-XXX ~]# cat elk-index.tmp wcf.core50-online-2017.08.01etl211-online-2017.08.01laravel-dujia-online-2017.08.01dms217-online-2017.08.01laravel-oms27-online-2017.08.01

第三步:删除过滤出来的索引

for i in `cat elk-index.tmp`   do       curl -XDELETE  http://192.168.X.X:9200/$i done

第四步为了方便可以在计划任务里面加定时任务删除五天之前的日志索引

[root@192-168-X-XXX ~]# crontab -l0 3 * * * bash /home/scripts/del_elasticseatch_index.sh

查看脚本文件内容cat  /home/scripts/del_elasticseatch_index.sh

#!/bin/bash#The index five days agocurl -XGET 'http://192.168.X.X:9200/_cat/shards' |grep 192.168.X.X |awk '{print $1}' |grep `date -d "5 days ago" +%Y.%m.%d` |uniq > /tmp/index_name.tmpfor index_name in `cat /tmp/index_name.tmp`  do    curl -XDELETE  http://192.168.X.X:9200/$index_name    echo "${
index_name} delete success" >> /home/scripts/del_elasticseatch_index.log done

 

转载于:https://www.cnblogs.com/xiewenming/p/7275283.html

你可能感兴趣的文章
如何增强你的SharePoint 团队网站首页
查看>>
FZU 1914 Funny Positive Sequence(线性算法)
查看>>
oracle 报错ORA-12514: TNS:listener does not currently know of service requested in connec
查看>>
基于grunt构建的前端集成开发环境
查看>>
MySQL服务读取参数文件my.cnf的规律研究探索
查看>>
java string(转)
查看>>
__all__有趣的属性
查看>>
BZOJ 5180 [Baltic2016]Cities(斯坦纳树)
查看>>
写博客
查看>>
利用循环播放dataurl的视频来防止锁屏:NoSleep.js
查看>>
python3 生成器与迭代器
查看>>
java编写提升性能的代码
查看>>
ios封装静态库技巧两则
查看>>
Educational Codeforces Round 46 (Rated for Div. 2)
查看>>
Abstract Factory Pattern
查看>>
C# 实现Bresenham算法(vs2010)
查看>>
基于iSCSI的SQL Server 2012群集测试(一)--SQL群集安装
查看>>
list 容器 排序函数.xml
查看>>
存储开头结尾使用begin tran,rollback tran作用?
查看>>
Activity启动过程中获取组件宽高的五种方式
查看>>