定期清理ES索引

问题

近期,kibana页面上出现Elasticsearch plugin is red错误信息,重启elasticsearch后又频繁出现该问题,观察elasticsearch发现各节点之间出现连接超时的现象.

解决方法

怀疑是索引条目太多,导致Elasticsearch性能下降造成的,通过查询api发现大量索引是yellow状态:
curl -XGET 'http://127.0.0.1:9200/_cat/indices/?v'

 

一、api删除

curl -XDELETE ‘http://127.0.0.1:9200/domain_log-2018-*
清理掉了所有 2018年domain的索引文件

二、脚本加api删除

[root@test es]#cat ES-index-clear.sh

#/bin/bash
#指定日期(7天前)
DATA=`date -d "1 week ago" +%Y-%m-%d`
 
#当前日期
time=`date`
 
#删除7天前的日志
curl -XGET "http://127.0.0.1:9200/_cat/indices/?v"|grep $DATA
if [ $? -eq 0 ];then
  curl -XDELETE "http://127.0.0.1:9200/*-${DATA}"
  echo "于 $time 清理 $DATA 索引!"
fi

添加到任务计划

#每天定时清理索引
0 1 * * * /bin/sh /root/shscript/ES-index-clear.sh >> /root/shscript/log/es-index-clear.log  

 

手动命令删除:

[root@iser-monitor01 /]# curl -XDELETE http://127.0.0.1:9200/*2021.*

 

posted @ 2021-07-09 17:09  香菜哥哥  阅读(561)  评论(0编辑  收藏  举报