ES Curator的使用及其配置

  1. Curator

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

  2. ES版本为6.5.4,Curator版本为5.6
  3. ES和Curator版本对应关系
  4. ES Curator的使用及其配置_第1张图片
  5. Curator source安装方式:
  6. https://www.elastic.co/guide/en/elasticsearch/client/curator/5.6/python-source.html
  7. Curator的配置
  8. https://www.elastic.co/guide/en/elasticsearch/client/curator/5.6/configuration.html
  9. 装完之后测试curator_cli --help
  10. ES Curator的使用及其配置_第2张图片
  11. 使用curator_cli显示索引
  12. curat_cli --host 47.112.11.147 --port 9200 show_indices
  13. ES Curator的使用及其配置_第3张图片
  14. curator有curator_cli和curator,curator反人类操作,不用了,直接上curator
  15. curator语法格式为:
  16. curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML
  17. --dry-run该参数只是测试,并不真的做操作
  18. CONFIG.YML是配置文件,用于配置ES集群信息。
  19. config.yml官网配置参数:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/configfile.html
  20. ---
    # 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']
    
  21. action.yml官网配置参数:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actionfile.html

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

  23. ---
    # 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

     

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

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

  26. ES Curator的使用及其配置_第4张图片

  27. ///////////////////////////////////////////////////////////////

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

  29. ///////////////////////////////////////////////////////////////

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

  31. ES Curator的使用及其配置_第5张图片

  32. ES Curator的使用及其配置_第6张图片

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

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

  35. 做成Linux定时任务

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

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

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

  40. 赋予权限

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

参考:

官网:Curator Reference

Elastic Curator 的配置和运行

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

附9 elasticsearch-curator + Linux定时任务

ES索引管理curator

 

 

 

 

 

你可能感兴趣的:(ELK)