elasticsearch curator安装及应用

curator与elasticsearch版本的兼容性列表:Version Compatibility | Curator Reference [5.8] | Elastic

测试使用的elasticsearch是6.6版本的,所以这里安装curator5.

centos7+curator5.2.0环境rpm包下载:https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.2.0-1.x86_64.rpm

下载完成之后把包放到linux中,安装该rpm包:

[root@localhost elk-kafka]# rpm -ivh elasticsearch-curator-5.2.0-1.x86_64.rpm

验证是否安装成功:

[root@localhost elk-kafka]# curator --version
curator, version 5.2.0

默认的安装路径:

/opt/elasticsearch-curator

curator中需要使用到两个配置文件:config.yml(用于连接es的配置)和action.yml(用于表明要做哪些操作)。文件名可以自定义,因为在命令中会指定这些配置文件。这里我把配置文件写在了elasticsearch-curator目录下 。

先创建一个logfile的目录:

[root@localhost elasticsearch-curator]# mkdir log
[root@localhost elasticsearch-curator]# cd log
[root@localhost log]# touch wyh-curator.log

创建my-config.yml:

[root@localhost elasticsearch-curator]# cat my-config.yml
---
# Remember,leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 192.168.184.128
  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: /opt/elasticsearch-curator/log/wyh-curator.log
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

先查看一下现有的Index:

http://192.168.184.128:9200/_cat/indices

这次应用想使用curator实现根据Index名称中的日期来删除6个月之前的index。

创建my-action.yml:

[root@localhost elasticsearch-curator]# cat my-action.yml
---
# 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: >-
      Delete metric indices older than 6 months (based on index name), for
      wyh-elk-index-2019.03.15
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.
    options:
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: regex
      value: '^(wyh-elk-index-).*$'
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: months
      unit_count: 6

运行:

[root@localhost elasticsearch-curator]# curator --config /opt/elasticsearch-curator/my-config.yml /opt/elasticsearch-curator/my-action.yml

运行成功之后,再去查看index就会发现6个月之前的index已经被删除了。

这样就实现了一个简单的curator管理indexde应用。

=================其他配置说明======================

这里特别要注意的是option选项,在多action,并且没有互相依赖的情况下,一定要设置ignore_empty_list: True。这里代表的是,如果filter没有找到符合查询条件的index,略过。如果设置成false。则第一个action,没有找到匹配的index,整个curator会被abort。

在action.yml文件中,不同序号的配置,是顺序执行的,如果前面一个匹配的是一个空列表,会导致后续的不再执行,这时候为了防止这种情况,需要将ignore_empty_list设置为True。

source: 从哪里来获取索引时间。当user_age为True时,该配置为必填项。可以为name、creation_date、field_stats。

name: 来源为索引名称,此时必须指定timestring来匹配索引名称中的日期。
creation_date: 来源为索引的创建时间,ES内部会保存每个索引创建的具体时间,可通过http://127.0.0.1:9200/my_index_name*?pretty查看。
filed_stats: 来源为索引数据中某个日期字段,这个字段必须时ES能识别的日期字段,Curator会通过ES API获取每个索引中这个字段的最大值跟最小值。
timestring: 当source为name时必须配置,用于匹配索引名称中的日期,如 '%Y-%m-%d',也可以是 '%Y.%m.%d'格式。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QYHuiiQ

听说打赏的人工资翻倍~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值