如何管理索引的生命周期?
答:
方法一:
- 新建policy
- 新建template & 关联policy (
"index.lifecycle.name": "datastream_policy"
) - 创建索引—走模板—应用策略
方法二:
- 索引已经存在,模板已经存在
- 修改模板关联policy
- 通过模板创建的新索引将应用该policy
方法三:
- 索引已经存在
- 直接对索引加policy,立即生效
这时,policy的各个phase的min_age都会被比较,然后哪个匹配上了,就执行哪些action
PUT mylogs-pre-ilm*/_settings
{
"index": {
"lifecycle": {
"name": "mylogs_policy_existing"
}
}
}
如何关联ILM policy到具体的索引?
答:
一、可以关联到模板,在rollover使用该模板创建新的索引时,应用该policy,
二、在单独创建索引时,在settings中进行配置
1:新建模板
PUT _template/datastream_template
{
"index_patterns": [“datastream-demo*"],
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index.lifecycle.name": “xxxx",
"index.lifecycle.rollover_alias": “datastream-demo”,
}
}
##匹配全部的datastream-*的索引
2:这个时候不要配置滚动策略,只针对当前索引就行了,因为滚动后产生的索引不会继承这个lifecycle的属性
PUT test-index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index.lifecycle.name": "my_policy"
}
}
——————————————————————————————
ES Policy的phases & actions
1.index的phases都有哪几种?
答:
四种,hot(一直被写入的),warm(只读的),cold(不写入了,查询也很慢了),delete(不再需要可以删除的)
- hot:The index is actively being written to
- warm:The index is generally not being written to, but is still queried
- cold:The index is no longer being updated and is seldom queried. The information still needs to be searchable, but it’s okay if those queries are slower.
- delete:The index is no longer needed and can safely be deleted
2.Policy的参数
min_age: 从索引创建到现在经过的时间,如果发生了滚动,那就是从滚动到现在的时间
(时间检查的配置:indices.lifecycle.poll_interval=0默认,时间单位:
d-Days,h-Hours,m-Minutes,s-Seconds,ms-Milliseconds,micros-Microseconds,nanos-Nanoseconds)
actions:https://www.elastic.co/guide/en/elasticsearch/reference/7.4/_actions.html
——————————————————————————————
Metricbeat采集数据,采用自定义的Template,并配置日期、大小滚动和自动删除