奥德赛F9 发表于 2019-1-29 06:10:08

elasticsearch优化

  

1、删除历史索引

导出所有的索引

curl-u   USER:PASSWORD   http://IP:9200/_cat/indices?v > indices.20140127
基于导出的索引删除

curl-XDELETE-u USER:PASSWORD   http://IP:9200/nginx-access-2018.01.*
2、关闭冷索引

curl-XPOST -u USER:PASSWORDhttp://IP:9200/nginx-access-2018.01.*/_close
3、打开冷索引

curl-XPOST -u USER:PASSWORDhttp://IP:9200/nginx-access-2018.01.*/_open
4、优化searchguard恢复速度

curl -u USER:PASSWORD   http://IP:9200/searchguard/_settings| python -m json.tool
curl -XPUT -uUSER:PASSWORD   http://ip:9200/searchguard/_settings -d '{"index.priority": 10}'

查看所有的索引

curl -u USER:PASS http://IP:9200/_cat/indices?v > indices.copy
查看所有项目,项目一天一个索引
  索引app-app1-com-production-2018.07.28 这种形式命令,会过滤掉.kibana,searchguard,wather三类索引

sort -k3 indices.copy | awk '{print $3}'| cut -d "." -f1| awk -F"-"'OFS="-"{$NF="";print}' |sed 's@\-$@@g'| uniq
查看gb大小的索引,并降序排序

grep "gb$" indices.copy |sort -k10nr| less

删除垃圾数据:

curl-XDELETE-u "USER:PASS"   http://IP:9200/%25%7B%5B%40metadata%5D%5Bes_index%5D%7D-2018.06.*
curl-XDELETE-u "USER:PASS"   http://IP:9200/%25%7B%5B%40metadata%5D%5Bes_index%5D%7D-2018.07.*
%{[@metadata]}-2018.07.27 -> %25%7B%5B%40metadata%5D%5Bes_index%5D%7D-2018.07.27

查看备份:

curl'http://IP:9200/_snapshot/backup_repository/backup-日期?pretty'
查询出大于1g的索引

curl-u "USER:PASS"http://IP:9200/_cat/indices?v > indices # 查看所有的索引
sort -k3 indices > indices.sort
grep "gb$" indices.sort > 1g_indices
sort -k3 1g_indices | awk '{print $3}'| cut -d "." -f1| awk -F"-"'OFS="-"{$NF="";print}'|uniq| grep -v "^$" > index.txt # 打印出索引的前缀

关闭15天前大于1g的索引,每周执行一次

#!/bin/bash
cat index.txt|while read line
do
for i in `seq 17 30`;
do
echocurl-XPOST -u USER:PASShttp://IP:9220/$line`date -d "$i days ago"+%Y.%m.%d`/_close
curl-XPOST -u USER:PASS http://IP:9220/$line`date -d "$i days ago"+%Y.%m.%d`/_close
sleep 10
done
done


页: [1]
查看完整版本: elasticsearch优化