• 使用curator 来管理elasticsearch的index


    这里我们参考官网安装curator

    https://www.cookiesinn.org/elasticsearch_curator_delete_indices/

    https://www.elastic.co/guide/en/elasticsearch/client/curator/5.4/installation.html

    https://blog.csdn.net/u013613428/article/details/78229090

    https://blog.csdn.net/zou79189747/article/details/80526221

    这里我们使用yum 的方式来安装

    先说 一下我的环境:

    centos 7

    es 5.6.9

    https://www.elastic.co/guide/en/elasticsearch/client/curator/5.4/yum-repository.html

    cd /data/package sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch cd /etc/yum.repos.d vim elasticsearch.repo [curator-5] name=CentOS/RHEL 7 repository for Elasticsearch Curator 5.x packages baseurl=https://packages.elastic.co/curator/5/centos/7 gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 sudo yum install elasticsearch-curator

     正题看下面:

    curator由python研发的非常轻量级的工具.

    curator不仅仅可以删除多余的索引其实还有其他功能也能使用比如:添加别名、创建快照、删除快照、添加索引、删除索引、索引设置等等内容。并且可以将这些设置定义在YAML风格的配置文件

    我们目前用到的是对index的过期删除,这里我们要注意的是,我们的index的命名最好是有规范的。这样对我们的index管理起来是方便的。最好是  “业务-服务-date”

    1、下载rpm包并且安装Elasticsearch-curator:

    cd /data/tools
    
    wget https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.3.0-1.x86_64.rpm
    
    sudo yum install -y elasticsearch-curator-5.2.0-1.x86_64.rpm #安装会安装在/opt目录下

    我们常用的是curator和curator_cli,具体的参见官网:

    https://www.elastic.co/guide/en/elasticsearch/client/curator/5.3/filtertype_age.html

    curator_cli --host 127.0.0.1 --port 9200 show_indices --verbose

    这样我们直接上正题:直接删除过期的index

    mkdir

    /data/package/curator

    这里我们在编写配置文件的时候,一定要注意缩进,yml 语法对这个要求很严格

    首先我们配置vim config.yml

    client:
      hosts:
        - 10.10.124.125
        - 10.10.96.46
      port: 9200
      url_prefix:
      use_ssl: False
      certificate:
      client_cert:
      client_key:
      aws_key:
      aws_secret_key:
      aws_region:
      ssl_no_validate: False
      http_auth:
      timeout: 30
      master_only: False
    
    logging:
      loglevel: INFO
      logfile:
      logformat: default
      blacklist: ['elasticsearch', 'urllib3']
    

    现在我们上清理索引的配置:

    这里我是删除了所有的超过七天的index,同时我们也可以使用 filtertype: pattern 匹配规则来删除相应的index,这里就提现出我们在命名index的是有规则是有多么的重要

    actions:
     1:
       action: delete_indices
       description: "Delect all index"
       options:
         ignore_empty_list: True
         disable_action: False
       filters:
    #   - filtertype: pattern
    #     kind: regex
    #     value: test2
       - filtertype: age
         source: creation_date
         direction: older
         unit: days
         unit_count: 7

    一个索引进行匹配只能定义在一个任务中,除非是像我上面一样,直接就是根据filtertype: age来。

    注意:再次提示,这里最好不要复制粘贴文件,可能一不小心就把缩进给弄乱了,真想复制粘贴可以复制官网上的,这样格式不会乱(大笑)(大笑)(大笑)

    这里我们调试使用的命令是:
    
     curator --config config.yml delete_index.yml --dry-run
    
    真正执行的命令是:
    
     curator --config config.yml delete_index.yml 

    真正上线的时候我们结合crontab 一起使用,这样我们就可以实现定时的去清理elasticsearch index 的目的了,妈妈在用不用担心我们磁盘满了,
    以前都是用脚本处理的,因为以前的elasticsearch的index数据文件是有规则的,现在是一串字符串,不好用脚本处理,发现了这个开源工具,真的很好用。强烈推荐
  • 相关阅读:
    <转>WCF中出现死锁或者超时
    无连接服务器与面向连接的服务器
    Linux系统调用
    vim文本删除方法 Linux
    深入了解C指针
    linux下c语言实现双进程运行
    *p++、(*p)++、*++p、++*p 的区别
    快速了解yuv4:4:4 yuv4:2:2 yuv 4:1:1 yuv 4:2:0四种YUV格式区别
    文件通过svn updata更新不到,并且svn st显示被删除的解决办法
    [非常重要的总结] Linux C相关函数
  • 原文地址:https://www.cnblogs.com/smail-bao/p/9224342.html
Copyright © 2020-2023  润新知