elastic索引日誌清理不及時,很容易產生磁盤緊張,官網給出curl -k -XDELETE
能夠清理不須要的索引日誌。bash
#!/bin/bash #Author: 648403020@qq.com #date: 2019.03.28 # 須要清理幾天之前的索引日誌 CLEAN_DAY=7 # 獲取N天之前的年月日 YEAR=$(date -d "$(date -I) -$CLEAN_DAY"day"" +%Y) MONTH=$(date -d "$(date -I) -$CLEAN_DAY"day"" +%m) DAY=$(date -d "$(date -I) -$CLEAN_DAY"day"" +%d) # 獲取須要過濾N天前的ES索引數據 DATA=`curl -sk https://esadmin:your_password@10.124.56.120:9200/_cat/indices?v \ |awk '/[0-9]{4}-[0-9]{2}-[0-9]{2}/ {print $3}' |awk -F- '{s2=mktime($(NF-2)" "$(NF-1)" "$NF" 0 0 0");\ s1=systime()}{if(s1-s2 >= 86400*"'$CLEAN_DAY'") print $0}'` echo "即將清理"$YEAR'-'$MONTH'-'$DAY"前ES索引數據>>>>>>>>" echo "清理數據爲: "$DATA # 執行清理工做 for i in $DATA do sleep 3 curl -k -XDELETE https://esadmin:your_password@10.124.56.120:9200/$i done echo "=======================" echo "執行完成" echo "======================="
crontab -e 00 03 * * * sh /apps/sh/ESindex_clean_v3.sh > /dev/null 2>&1
查看索引列表
curl -k https://your_username:your_password@10.124.10.27:9200/_cat/indices?vapp
查詢集羣是否健康
curl -k https://your_username:your_password@10.124.10.27:9200/_cluster/healthcurl
查看全部shard
curl -k https://your_username:your_password@10.124.10.27:9200/_cat/shardselasticsearch
啓動命令
/usr/local/elasticsearch/bin/elasticsearch -durl