51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

elasticsearch 工具 curator(保留7天的索引)

elasticsearch-curator

项目地址:https://gitcode.com/elastic/curator

elasticsearch 使用curator管理索引_source: creation_date-CSDN博客

Curator是Elastic社区的一个重要补充工具,它允许用户执行一系列预定义的任务,如清理旧索引、分配节点、关闭或打开索引等。通过提供命令行接口和API,Curator使复杂的Elasticsearch维护工作变得简单易行

核心功能

索引生命周期管理 (ILM): Curator可以帮助你根据日期模板自动删除旧索引,确保你的集群不会被过时的数据填满。
热温冷架构管理: 它可以动态地将索引重新分配到不同的数据节点,适应不同的硬件配置,以优化读写性能。
健康检查与调整: 可以监测集群状态,执行恢复操作,平衡节点的文档数,或者根据需要关闭和打开索引。

应用场景

  • 日志分析:在日志数据分析场景中,Curator可以定期清理过期的日志索引,节省存储空间。

  • 实时监控:对于需要实时数据的系统,Curator可以帮助保持系统轻量,只保留最新的数据。

  • 大数据处理:在大数据环境中,它可以用于周期性地整理和归档数据,优化查询性能。

elasticsearch官方工具,能实现诸如数据只保留前七天的数据的功能。

地址:https://pypi.python.org/pypi/elasticsearch-curator

另外 ES6.3(还未上线) 有一个 Index LifeCycle Management 可以很方便的管理索引的保存期限。

1- 安装

pip install elasticsearch-curator

pip 安装-白眉大叔 (baimeidashu.com)

2-

官方 curator 文档

Configuration File | Curator Reference [4.2] | Elastic

mkdir /etc/curator

3- 编辑一个 config.yml 文件

cd /etc/curator

官方配置:

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

client:
 hosts: 10.0.0.208
 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: /var/log/curator.log
 logformat: default
 blacklist: ['elasticsearch', 'urllib3']

查看日志

 tailf /var/log/curator.log

4- action.yml

官方案例:

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

这是删除一个 索引 nginx-2024.04.01 , 类似这样的, 7天前的。

actions:
  1:
    action: delete_indices
    description: >-
      Delete indices older than 45 days (based on index name), for logstash-
      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
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: nginx-
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 7

disable_action: False 才生效的。

5- 执行

curator --config  /etc/curator/config.yml  /etc/curator/action.yml

6-定时执行

欢迎来撩 :汇总all

赞(3)
未经允许不得转载:工具盒子 » elasticsearch 工具 curator(保留7天的索引)