ES Curator的使用及其配置

  1. Curator

    Curator 是elasticsearch 官方的一个索引管理工具,可以通过配置文件的方式帮助我们对指定的一批索引进行创建/删除、打开/关闭、快照/恢复等管理操作。

  2. ES版本为6.5.4,Curator版本为5.6
  3. ES和Curator版本对应关系
  4. Curator source安装方式:
  5. https://www.elastic.co/guide/en/elasticsearch/client/curator/5.6/python-source.html
  6. Curator的配置
  7. https://www.elastic.co/guide/en/elasticsearch/client/curator/5.6/configuration.html
  8. 装完之后测试curator_cli --help
  9. 使用curator_cli显示索引
  10. curat_cli --host 47.112.11.147 --port 9200 show_indices
  11. curator有curator_cli和curator,curator反人类操作,不用了,直接上curator
  12. curator语法格式为:
  13. curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML
  14. --dry-run该参数只是测试,并不真的做操作
  15. CONFIG.YML是配置文件,用于配置ES集群信息。
  16. config.yml官网配置参数:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/configfile.html
  17. ---
    # Remember, leave a key empty if there is no value.  None will be a string,
    # not a Python "NoneType"
    client:
      hosts:
        - 47.112.11.147
      port: 9200
      url_prefix:
      use_ssl: False
      certificate:
      client_cert:
      client_key:
      ssl_no_validate: False
      http_auth:
      timeout: 30
      master_only: False
    
    logging:
      loglevel: INFO
      logfile: /home/soft/elk/log/curator.log
      logformat: default
      blacklist: ['elasticsearch', 'urllib3']
    
  18. action.yml官网配置参数:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actionfile.html

  19. 这里只演示删除操作,例如删除10之外的日期,同时匹配前缀名为:filebeat-6.5.4-

  20. ---
    # Remember, leave a key empty if there is no value.  None will be a string,
    # not a Python "NoneType"
    #
    # Also remember that all examples have 'disable_action' set to True.  If you
    # want to use this action as a template, be sure to set this to False after
    # copying it.
    actions:
      1:
        action: delete_indices
    #    description: "删除过期索引"
        description: "delete_expire_index"
        options:
          # action开关,为True表示不执行这个action,默认False
          disable_action: False
          # 如果为True,则在filters空列表时,继续下一个action处理而不是退出程序。
          ignore_empty_list: True
          # 发现错误后,继续执行下一个索引操作,默认False
          continue_if_exception: True
        filters:
        # 是否排除隐藏索引,如.kibana
        - filtertype: kibana
          exclude: True
        # 是否排除open状态的索引
        - filtertype: opened
          exclude: False
        #前缀匹配
        - filtertype: pattern
          kind: prefix
          value: filebeat-6.5.4-
          exclude: False
        # 处理10天前的索引
        - filtertype: age
          source: name
          direction: older
          timestring: '%Y.%m.%d'
          unit: days
          unit_count: 10
          exclude: False

     

  21.  执行:curator --config config.yml action.yml 

  22. 新建一些索引但是不包含今天(2019.03.14)的索引如图:

  23. ///

  24. 删除失败description: "删除过期索引"不能有中文

  25. ///

  26. 修改为英文之后,测试,显示执行成功,查看日志,显示

  27. 很明显的看出来:filtertype该属性相当于and条件

  28. 删除的索引剩余数量可以看出,他删除的是从今天(2019.03.14)算起的。不是按照索引名字的最后一天删除的

  29. 做成Linux定时任务

  30. crontab命令用于设置周期性被执行的指令。该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行

  31. 编写sh脚本:curator-delete-index.sh

  32. #!/bin/sh
    /usr/local/bin/curator --config /home/soft/elk/config.yml /home/soft/elk/action.yml
    echo "delete index success"
  33. 注意:最好使用命令的全路径名,否则可能找不到

  34. 赋予权限

    1. chmod 777 /home/elk/curator-delete-index.sh
  35. 创建定时任务:crontab 
    1. crontab -e:打开了vi,输入:
      1. 30 16 * * * /home/elk/curator-delete-index.sh,之后保存退出vi
    2. crontab -l:查看所有的root用户的定时任务
  36. 附:crontab文件的基本格式
  37. *  *  *  *  *  command 
  38. 分  时  日   月  周        命令 
    1. 第1列表示分钟1~59 每分钟用*或者 */1表示 
    2. 第2列表示小时1~23(0表示0点) 
    3. 第3列表示日期1~31 
    4. 第4列表示月份1~12 
    5. 第5列标识号星期0~6(0表示星期天) 
    6. 第6列要运行的命令 
    7.  “*”代表取值范围内的数字,
        “/”代表”每”,
        “-”代表从某个数字到某个数字,
        “,”分开几个离散的数字
  39. 用法:
  40. cat /etc/crontab    查看/etc/crontab文件
  41. crontab -e   或者以root用户运行:crontab -u root -e
  42. 如果要每周一到周六的8点执行一次命令:
  43. 0  8  *  *  1-6   你要运行的命令 >> /你的路径/create-Index.log 2>&1  
  44. 例如:每分钟执行一次curator --config /root/.curator/curator.yml  /root/.curator/action_file.yml命令:
  45. PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
  46. */1 * * * * curator --config /root/.curator/curator.yml /root/.curator/action_file.yml>>/root/.curator/create-Index.log 2>&1
  47. //将日志打印到/root/.curator/目录下的create-Index.log中,其中2>&1 表示执行结果及错误信息
  48. :wq存盘退出
  49. 列出某个用户cron服务的详细内容:crontab -l
  50. 重启:service crond restart
  51. 删除所有任务调度工作:crontab -r  
  52. //问题///
  53. 查看日志报:
  54. 出现该问题为xxx.sh文件我是在window上写的,解决方式查看
  55. https://blog.csdn.net/qq_39669058/article/details/88579134
  56. 修改完成之后
  57. 显示成功,该成功是定时任务执行成功,不是curator执行成功
  58. 查看curator日志
  59. curator删除索引执行成功

参考:

官网:Curator Reference

Elastic Curator 的配置和运行

干货 | Elasticsearch索引管理利器——Curator深入详解

附9 elasticsearch-curator + Linux定时任务

ES索引管理curator

 

 

 

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Elasticsearch Curator是一个用于管理Elasticsearch集群的工具。它提供了两种接口:curator_cli命令行模式和curator API模式。curator_cli命令行模式可以使用各种命令来执行不同的操作,比如关闭索引、删除索引、创建快照等。curator API模式则可以通过编写脚本来调用Elasticsearch的API来实现相同的功能。\[1\] 在生产环境中,推荐先关闭一段时间观察索引的状态,然后再删除数据。这样可以避免意外删除数据而导致恢复困难。可以使用curator_cli命令行模式的close命令来关闭索引,使用delete_indices命令来删除索引。\[2\] 当数据量达到一定量级时,为了节省内存或磁盘空间,通常会选择关闭或删除一定时间之前的索引。为了方便管理,可以编写脚本并定期执行,使用Elasticsearch的API来实现这些操作。使用curator API模式可以更好地管理和维护这些脚本。\[3\] #### 引用[.reference_title] - *1* *2* [Elasticsearch集群管理工具curator详解-curator_cli](https://blog.csdn.net/kjh2007abc/article/details/85149030)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [【Elasticsearch】Curator 从入门到实战](https://blog.csdn.net/qq_21383435/article/details/119081462)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值