安装配置参考文档:
https://blog.51cto.com/michaelkang/2333586

curator 接口模式使用介绍

curator的命令行语法如下:

curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML

--config : 之后跟上配置文件

--dry-run :调试参数,测试脚本运行是否正常;

ACTION_FILE.YML :action文件中可以包含一连串的action,curator接口集中式的config和action管理,可以方便我们重用变量,更利于维护和阅读。

环境初始化也可以至通过 curator [--config CONFIG.YML] 直接指定

#### linux 默认查找路径:

~/.curator/curator.yml

环境初始化也可以至通过 curator [--config CONFIG.YML] 直接指定


#### 初始化系统环境

配置 [--config CONFIG.YML]

mkdir -p  ~/.curator/

vim ~/.curator/curator.yml
---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 172.20.11.32     《== 集群节点IP地址,可以写多个
  port: 9200           《== datanode 接口
  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:  《== 输出日志到文件
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

重要选项介绍

loglevel 支持 :

CRITICAL will only display critical messages.
ERROR will only display error and critical messages.
WARNING will display error, warning, and critical messages.
INFO will display informational, error, warning, and critical messages.
DEBUG will display debug messages, in addition to all of the above.

logfile 支持:

default, json, logstash 或者留空;

blacklist 支持:
那些关键字开头索引日志不输出,默认即可。

ACTION_FILE.YML 介绍

action
每个action由三部分组成: 
- action,具体执行什么操作 
- option, 配置哪些可选项 
- filter, 过滤条件,哪些index需要执行action

支持的动作如下:

Alias
Allocation
Close
Cluster Routing
Create Index
Delete Indices
Delete Snapshots
forceMerge
Index Settings
Open
Reindex
Replicas
Restore
Rollover
Shrink
Snapshot

option: 选项 ,filter:过滤条件,哪些index需要执行action,详细参考官网;

https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actions.html

实例

实例1 :定期删除旧index

more delete_indices-eslog-ptlog.yml
actions:
  1:
    action: delete_indices
    description: >-
      删除超过20天的索引(基于索引名称),monitoring-*
      前缀索引。如果过滤器没有导致错误,请忽略错误
      可操作的索引列表(ignore_empty_list)并彻底退出.
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: regex
      value: '^(\.monitoring-(es|kibana|logstash)-).*$'
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 20
  2:
    action: delete_indices
    description: >-
      删除超过10天的索引(基于索引名称ptlog)
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 10

实例2:reindex每天生成的index文件到月index文件

将所有每天生成的ptlog-dd-trace-prod-app-gateway-2018.11.文件汇总到 ptlog-dd-trace-prod-app-gateway-2018.11 月日志文件,然后删除 ptlog-dd-trace-prod-app-gateway-2018.11. 的日志文件。

用于合并琐碎index文件,减少集群分片数;

awsesbak-reindex.yml 
---
actions:
  1:
    description: >-
       Reindex 11月份每天生成的index数据到 ptlog-$name-2018.11
    action: reindex
    options:
      disable_action: False
      wait_interval: 9
      max_wait: -1
      request_body:
        source:
          index: REINDEX_SELECTION
        dest:
          index: ptlog-dd-trace-prod-app-gateway-2018.11
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog-dd-trace-prod-app-gateway-2018.11.
  2:
    action: delete_indices
    description: >-
       删除已经完成合并的索引
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog-dd-trace-prod-app-gateway-2018.11.