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

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

一、存在问题

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

二、解决方法(定期删除索引)

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

[root@192-168-x-x scripts]# 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  Speed  0  0   0   0  0   0   0   0 --:--:-- --:--:-- --:--:--     0freetrip-2019.01.29   2 r STARTED   34  59kb 192.168.x.x node3-192.168.x.xfreetrip-2019.01.29                2 p STARTED     34    59kb 192.168.x.x node1-192.168.x.xfreetrip-2019.01.29                1 p STARTED     47 122.7kb 192.168.x.x node3-192.168.x.xfreetrip-2019.01.29                1 r STARTED     47 122.7kb 192.168.x.x node1-192.168.x.xfreetrip-2019.01.29                3 p STARTED     58  90.5kb 192.168.x.x node2-192.168.x.xfreetrip-2019.01.29                3 r STARTED     58  90.5kb 192.168.x.x node1-192.168.x.xfreetrip-2019.01.29                4 r STARTED     41  45.5kb 192.168.x.x node2-192.168.x.xfreetrip-2019.01.29                4 p STARTED     41  45.5kb 192.168.x.x node3-192.168.x.xfreetrip-2019.01.29                0 p STARTED     36  97.9kb 192.168.x.x node2-192.168.x.xfreetrip-2019.01.29                0 r STARTED     36  97.9kb 192.168.x.x node3-192.168.x.x

2.将过滤出来要删除的索引存到临时文件夹里面

[root@192-168-x-x ~]# curl -XGET 'http://192.168.x.x:9200/_cat/shards' | grep 192.168.x.x | grep 2018 | awk '{print $1}' |uniq > elk-index.tmp  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100 81832  100 81832    0     0   142k      0 --:--:-- --:--:-- --:--:--  142k[root@192-168-3-163 ~]# cat elk-index.tmp otter-canal-195-2018.12.10logstash-nginx-chm-accesslog-2018.11.20logstash-nginx-oms-accesslog-2018.10.14laravel-chm248-online-2018.12.10otter-canal-195-2018.11.20logstash-nginx-oms-accesslog-2018.11.20otter-communication-195-2018.11.23otter-communication-195-2018.12.10otter-node-195-2018.12.10logstash-nginx-chvisa-accesslog-2018.10.14wanmei219-online-2018.10.14logstash-nginx-chm-accesslog-2018.11.19otter-canal-195-2018.11.23otter-canal-195-2018.11.19logstash-nginx-oms-accesslog-2018.11.19laravel-chm248-online-2018.11.19logstash-nginx-oms-accesslog-2018.12.10otter-manager-195-2018.12.10logstash-nginx-chvisa-accesslog-2018.11.20wanmei219-online-2018.12.10logstash-nginx-chvisa-accesslog-2018.11.19otter-communication-195-2018.11.19otter-communication-195-2018.11.20laravel-chm248-online-2018.11.20laravel-chm248-online-2018.10.14logstash-nginx-chm-accesslog-2018.12.10wanmei219-online-2018.11.19logstash-nginx-chvisa-accesslog-2018.12.10wanmei219-online-2018.11.20logstash-nginx-chm-accesslog-2018.10.14

3. 删除过滤出来的索引文件

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

4. 使用脚本加定时任务,每一天删除前三天的索引

[root@192-168-x-x ~]# cat /home/scripts/del_elasticseatch_index.sh #!/bin/bashcurl -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   echo $index_name    curl -XDELETE  http://192.168.x.x:9200/$index_name    echo "${index_name} delete success" >> /home/scripts/del_elasticseatch_index.logdone

5. 定时任务

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

 

转载于:https://www.cnblogs.com/cyleon/p/10334155.html

你可能感兴趣的文章
spring集合类型注入
查看>>
EnumMap 两种使用方式的比较
查看>>
smarty课程---smarty3的安装和使用
查看>>
m_Orchestrate learning system---mo系统权限思考(如何实现以及注意什么)
查看>>
Dcloud课程8 开心一刻应用如何实现
查看>>
html5--2.9新的布局元素(5)-hgroup/address
查看>>
jar包和war包的介绍和区别
查看>>
jQuery.获取过滤点
查看>>
64位Windows系统下32位应用程序连接MySql
查看>>
js 类似发微博或者微信朋友圈的时间显示 刚刚 几天前
查看>>
Oracle10gr2 开机自启动脚本
查看>>
netty websocket
查看>>
SpringMVC单文件上传、多文件上传、文件列表显示、文件下载
查看>>
sql server T-SQL 基础
查看>>
private static
查看>>
Java面试不得不知的程序(二)
查看>>
检测数据类型的几种方式
查看>>
Core Dump解析(1)
查看>>
PAT顶级 1002. Business (35)
查看>>
【jenkins】jenkins 持续集成本地项目(win)
查看>>