用于删除旧索引的索引生命周期策略



我已经阅读了以下教程:

https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index-lifecycle-management.html

在多次遵循其阶段后,我仍然遇到相同的错误。 我想自动删除处于特定年龄的旧索引。

我在 AWS 上有几个实例,每个实例都在弹性搜索上写入自己的索引,例如: 索引名称 -

filebeat-log-centralization-ds-test-2020.08.09

映射到索引模板

{
"filebeat-template" : {
"order" : 0,
"index_patterns" : [
"filebeat-*"
],
"settings" : {
"index" : {
"lifecycle" : {
"name" : "logs-deletion-policy",
"rollover_alias" : "filebeat"
},
"number_of_shards" : "1",
"number_of_replicas" : "0"
}
},
"mappings" : {
"_meta" : { },
"_source" : { },
"properties" : { /*** some mappings ***/
"aliases" : { }
}
}

ILM 策略:

PUT _ilm/policy/logs-deletion-policy
{
"policy": {
"phases": {
"hot": {                      
"actions": {
"rollover": {
"max_size": "50GB",     
"max_age": "1m"
}
}
},
"delete": {
"min_age": "0d",           
"actions": {
"delete": {}              
}
}
}
}
}

我已经引导了翻转别名索引:

PUT filebeat-000001
{
"aliases": {
"filebeat": {
"is_write_index": true
}
}
}

filebeat-0000N 索引(我刚刚创建的翻转别名索引)正在滚动并被删除正常, 但是"filebeat-log-centralization-ds-test-2020.08.09"显示错误:

illegal_argument_exception: index.lifecycle.rollover_alias [filebeat] 
does not point to index [filebeat-log-centralization-ds-test-2020.08.09]

我不知道我做错了什么,并试图重复本教程但没有成功。 我错过了什么?

编辑:

我尝试将文件节拍别名添加到索引模板。

GET /filebeat-log-centralization-ds-test-2020.08.09/_alias/
{
"filebeat-log-centralization-ds-test-2020.08.09" : {
"aliases" : {
"filebeat" : { }
}
}
}

这会导致filebeat-log-centralization-ds-test-2020.08.09索引出错

illegal_argument_exception: Rollover alias [filebeat] can point to multiple indices, found duplicated alias [[filebeat]] in index template [filebeat-template]

我无法解决此问题,但确实使用策展人解决了它,因为我的主要目标是删除旧索引。

创建一个名为config.yml的文件

client:
hosts:
- 127.0.0.1
port: 9200
url_prefix:
use_ssl: False
certificate:
client_cert:
client_key:
ssl_no_validate: False
http_auth: username:password
timeout: 30
master_only: False
logging:
loglevel: INFO
logfile:  /var/log/curator/curator.log
logformat: default
blacklist: ['elasticsearch', 'urllib3']

策展人需要一个操作文件。创建一个名为delete_indices.yml的文件

actions:
1:
action: delete_indices
description: >-
Delete indices with age greater than 4 days(based on index name), for filebeat-*
prefixed indices.
options:
ignore_empty_list: True
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: filebeat-
- filtertype: age
source: creation_date
direction: older
unit: days
unit_count: 4

上面的配置删除了所有年龄大于 4 天的索引

现在您可以使用以下命令运行它 -

curator --config config.yml delete_indices.yml

由于我的配置需要自动删除旧索引,因此我使用crontab运行它。

crontab -e

这将打开您的个人 crontab(cron 配置文件)。

添加以下代码-

* * * * * /usr/local/bin/curator --config {config.yml location} {delete_indices.yml location} >/dev/null 2>&1

看起来alias由您创建的filebeat没有指向您要删除的索引,因为在异常消息中突出显示。

index.lifecycle.rollover_alias [文件节拍] 不指向索引 [文件节拍日志集中化-DS-测试-2020.08.09]

您可以使用 GET 别名 API 来确认这一点,如果没有链接,请使用更新别名 API 将filebeat别名链接到filebeat-log-centralization-ds-test-2020.08.09

最新更新