ELK定時刪除30天前日志


http://127.0.0.1:9200/_cat/indices?v

 
 
  1. #!/bin/bash
  2. #刪除ELK30天前的日志
  3.  
  4. DATE=`date -d "30 days ago" +%Y.%m.%d`
  5.  
  6. curl -s -XGET http://127.0.0.1:9200/_cat/indices?v| grep $DATE | awk -F '[ ]+' '{print $3}' >/tmp/elk.log
  7.  
  8. for elk in `cat /tmp/elk.log`
  9.  
  10. do
  11.  
  12. curl -XDELETE "http://127.0.0.1:9200/$elk"
  13.  
  14. done

二:加入到定時任務

  1. # crontab -e
  2.  
  3. #每天凌晨1點定時清理elk索引
  4.  
  5. 00 01 * * * bash /server/scripts/elk.sh &>/dev/null

注意:保證crond服務是啟動的

[root@server scripts]# service crond status

crond (pid 1999) is running...

 

 

 

 

 

 

 

 

 

 

 

 

++++++腳本2未驗證++++++++++++++++++++++++++++++

腳本2

 

#/bin/bash
#es-index-clear
#只保留7天內的日志索引
LAST_DATA=`date -d "-7 days" "+%Y.%m.%d"`
#刪除上個月份所有的索引
curl -u elastic:xxxx(密碼) -XDELETE 'http://192.168.12.31:9200/*-'${LAST_DATA}'*'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM