← 返回文章列表ES 索引生命周期管理
本文字数:230阅读时长 ≈ 1 分钟阅读次数:--ActPi
需求
- 使用 es 采集 nginx 访问日志,系统日志,备份日志等
- 滚动更新,保留指定时期文档,自动删除旧的索引
- 不使用额外的脚本,尽量用 es 自带功能实现
思路与实践
- 配置生命周期策略
- ES 配置索引模板,加载生命周期策略到索引(模板不要配置 rollover_alias )
- filebeat 采集多个日志源,分别输出为不同索引 index
- 对生成的 index 索引添加别名,使其能被策略调用
对已存在的 index 索引添加别名
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "test1", "alias" : "alias1" } }
]
}
filebeat 模块配置排除
- module: nginx
# Access logs
access:
input:
exclude_lines: ['POST']
enabled: true
结果
- 能正常按需生成不同索引,
- 生命周期策略待观察
— 能生成新的 index -000002
— 不能往新的索引里写数据,仍然是写到 index -000001