用于删除旧索引的索引生命周期策略
Index Lifecycle policy for deleting old indices
我已阅读以下教程:
在多次关注它的阶段之后,我仍然遇到同样的错误。
我想自动删除特定年龄的旧索引。
我在 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]
我不知道我做错了什么,并尝试重复教程但没有成功。
我错过了什么?
编辑:
我已经尝试将 filebeat 别名添加到索引模板中。
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]
您 filebeat
创建的 alias
似乎没有指向您要在异常消息中作为 high-lighted 删除的索引。
index.lifecycle.rollover_alias [filebeat] does not point to index
[filebeat-log-centralization-ds-test-2020.08.09]
您可以使用 GET alias API to confirm that and if not link use update alias API 到 link 您的 filebeat
别名到您的 filebeat-log-centralization-ds-test-2020.08.09
。
我无法解决这个问题,但使用 curator 解决了它,因为我的主要目标是删除旧索引。
创建一个名为 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
我已阅读以下教程:
在多次关注它的阶段之后,我仍然遇到同样的错误。 我想自动删除特定年龄的旧索引。
我在 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]
我不知道我做错了什么,并尝试重复教程但没有成功。 我错过了什么?
编辑:
我已经尝试将 filebeat 别名添加到索引模板中。
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]
您 filebeat
创建的 alias
似乎没有指向您要在异常消息中作为 high-lighted 删除的索引。
index.lifecycle.rollover_alias [filebeat] does not point to index [filebeat-log-centralization-ds-test-2020.08.09]
您可以使用 GET alias API to confirm that and if not link use update alias API 到 link 您的 filebeat
别名到您的 filebeat-log-centralization-ds-test-2020.08.09
。
我无法解决这个问题,但使用 curator 解决了它,因为我的主要目标是删除旧索引。
创建一个名为 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