ELK运维之路(定时清理索引)

因为公司的日志存储磁盘给的很小只有2T,索引的清理策略目前无法使用,所以使用curator对ES的所以进行定期清理。

1.1 创建文件夹

bash 复制代码
mkdir -p /root/ELK/curator
chmod 777 -R /root/ELK/curator
cd /root/ELK/curator

1.2 创建配置文件

yaml 复制代码
vi config.yml

client:
  hosts:
    - 172.31.51.0
  port: 9200
  url_prefix:
  use_ssl: False
  #certificate:
  #client_cert:
  #client_key:
  ssl_no_validate: False
  # 下面用户名密码修改为自己es的用户密码
  http_auth: elastic:xxxxxxx
  timeout:
  master_only: True
logging:
  loglevel: INFO
  logfile: /software/ELK/Curator/logs/curator.log #日志文件的位置自定义
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

1.2 创建配置文件

yaml 复制代码
vi action.yml

actions:
  1: # 操作1
..........
  2: # 操作 2
    action: delete_indices    # 这里执行操作类型为删除索引
    description: "delete index expire date"
    options:
      ignore_empty_list: True
      timeout_override:
      continue_if_exception: False
      disable_action: False
    filters:
    - filtertype: pattern
      kind: regex  #使用正则匹配想要清理的index
      value: '^(skywalking-9.4_segment-|skywalking-9.4_records-all-|skywalking-9.4_metrics-all-|skywalking-9.4_log-).*$'
      #value: '^(skywalking-9.4_log-).*$'
    # 这里匹配时间
    - filtertype: age
      source: name    # 这里不单可以根据name来匹配,还可以根据字段等,详见官方文档应该是index的名称
      direction: older
      # 这里定义的是days,还有weeks,months等,总时间为unit * unit_count
      unit: days #时间格式
      unit_count: 1 #时间定义
      timestring: '%Y%m%d'    # 这里是跟在logstash-后面的时间的格式

1.3 定时执行docker启动清理

bash 复制代码
[root@backproject126 curator]# crontab -l
# 定时任务
0 1 * * * docker run --rm --name index_clear -v /root/ELK/curator:/.curator untergeek/curator:9.0.0 --config /.curator/config.yml /.curator/action.yml
相关推荐
Elastic 中国社区官方博客1 小时前
基于 Jina OCR v1 与 Elasticsearch 的 PDF 智能混合检索与 RAG 系统实战指南
大数据·数据库·elasticsearch·搜索引擎·ocr·jina
Eloudy13 小时前
Qwen2.5-14B-Instruct-AWQ 模型文件结构分析
大数据·elasticsearch·搜索引擎
YIN_尹19 小时前
【git原理与使用】git初识与安装
大数据·git·elasticsearch
Elastic 中国社区官方博客1 天前
Elastic 在《Forrester Wave™:2026 年第四季度智能运维平台》报告中被评为强劲表现者
大数据·运维·数据库·elasticsearch·搜索引擎·全文检索
Elasticsearch1 天前
Elastic Cloud 无服务器服务审计日志:将审计记录发送到可观测性或安全解决方案
elasticsearch
zwjapple2 天前
skill总结
大数据·elasticsearch·搜索引擎
阿里云大数据AI技术2 天前
云栖实录|从代码上下文到千亿级文档:Qoder × 阿里云 Elasticsearch 落地生产级Agent向量检索
人工智能·elasticsearch
Elastic 中国社区官方博客2 天前
使用 OpenTelemetry 在 Elastic 中实现 Claude 平台的人工智能 agent 可观测性
大数据·运维·服务器·人工智能·elasticsearch·信息可视化·全文检索
Elastic 中国社区官方博客3 天前
Elastic 重大事件功能如何将 100 条日志样本转化为检测规则
大数据·运维·数据库·人工智能·elasticsearch·搜索引擎
Elasticsearch3 天前
使用 OpenTelemetry 在 Elastic 中实现 Claude 平台的人工智能 agent 可观测性
elasticsearch