ActPi向阳技术栈
← 返回文章列表

ES 索引生命周期管理

文章目录
  1. 需求
  2. 思路与实践
  3. 对已存在的 index 索引添加别名
  4. filebeat 模块配置排除
  5. 结果

需求

  1. 使用 es 采集 nginx 访问日志,系统日志,备份日志等
  2. 滚动更新,保留指定时期文档,自动删除旧的索引
  3. 不使用额外的脚本,尽量用 es 自带功能实现

思路与实践

  1. 配置生命周期策略
  2. ES 配置索引模板,加载生命周期策略到索引(模板不要配置 rollover_alias )
  3. filebeat 采集多个日志源,分别输出为不同索引 index
  4. 对生成的 index 索引添加别名,使其能被策略调用

对已存在的 index 索引添加别名

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } }
    ]
}

filebeat 模块配置排除

- module: nginx
  # Access logs
  access:
    input:
      exclude_lines: ['POST']
    enabled: true

结果

  1. 能正常按需生成不同索引,
  2. 生命周期策略待观察 — 能生成新的 index -000002 — 不能往新的索引里写数据,仍然是写到 index -000001