云搜索服务 CSS-通过索引生命周期管理实现Elasticsearch集群存算分离:通过索引生命周期管理实现存算分离

时间:2025-02-12 15:03:40

通过索引生命周期管理实现存算分离

  1. 登录 云搜索服务 管理控制台。
  2. 在左侧导航栏,选择对应的集群类型,进入集群列表页面。
  3. 在集群列表页面中,单击集群操作列的“Kibana”登录Kibana页面。
  4. 在Kibana的左侧导航中选择“Dev Tools”,进入命令执行页面。
  5. 创建生命周期策略“hot_warm_policy”。

    策略定义:当索引创建3天后,自动调用冻结索引API将数据转储到OBS;当索引创建6天后关闭索引,7天后归档索引;当索引创建满30天,删除该索引。

    PUT _opendistro/_ism/policies/hot_warm_policy{  "policy": {    "description": "hot warm archive delete workflow",    "error_notification": null,    "default_state": "hot",    "states": [      {        "name": "hot",        "actions": [],        "transitions": [          {            "state_name": "warm",            "conditions": {              "min_index_age": "3d"            }          }        ]      },      {        "name": "warm",        "actions": [          {            "freeze_low_cost": {}          }        ],        "transitions": [          {            "state_name": "close",            "conditions": {              "min_index_age": "6d"            }          }        ]      },      {        "name": "close",        "actions": [          {            "close": {}          }        ],        "transitions": [          {            "state_name": "archive",            "conditions": {              "min_index_age": "7d"            }          }        ]      },      {        "name": "archive",        "actions": [          {            "freeze_archive": {}          }        ],        "transitions": [          {            "state_name": "delete",            "conditions": {              "min_index_age": "30d"            }          }        ]      },      {        "name": "delete",        "actions": [          {            "delete": {}          }        ],        "transitions": []      }    ]  }}
  6. 新建索引模板“template_hot_warm”。

    模板定义:新建的所有“data”开头的索引会自动关联上生命周期策略“hot_warm_policy”。

    PUT _template/template_hot_warm{  "index_patterns": "data*",  "settings": {    "number_of_replicas": 5,    "number_of_shards": 1,    "opendistro.index_state_management.policy_id": "hot_warm_policy"  },  "mappings": {    "properties": {      "name": {        "type": "text"      }    }  }}
    表1 参数说明

    参数

    说明

    number_of_shards

    索引分片数。

    number_of_replicas

    索引分片副本数。

    opendistro.index_state_management.policy_id

    生命周期的策略名。

  7. 新建一个索引“data-2022-06-06”,该索引会自动应用索引模板“template_hot_warm”,并通过索引模板的配置与生命周期策略“hot_warm_policy”相关联,实现索引在创建3天后冻结,6天后关闭,7天后归档,30天后删除。
    POST data-2022-06-06/_bulk{"index":{}}{"name":"name1"}{"index":{}}{"name":"name2"}{"index":{}}{"name":"name3"}{"index":{}}{"name":"name4"}{"index":{}}{"name":"name5"}{"index":{}}{"name":"name6"}
  8. 查询数据,确认数据是否实现自动存算分离。
    • 在索引创建3天后查看冻结的索引:
      GET _cat/freeze_indices?s=i&v

      正常情况下会显示3天以前的索引已经被冻结:

      health status index                  uuid                   pri rep docs.count docs.deleted store.size pri.store.sizegreen  open   data-2022-06-06  x8ab5NX6T3Ox_xoGUanogQ    1   1          6            0      7.6kb          3.8kb
    • 在创建索引7天后,查看索引情况:
      GET _cat/archive_indices?v

      正常情况下会显示7天以前的索引已经被归档:

      health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size       close  data-2022-06-06 M0uRAWj_SKydjg0dFzyJow                                                          
    • 在索引创建30天后,查看索引情况,正常情况下30天以前的索引已经被删除。
support.huaweicloud.com/usermanual-css/css_01_0022.html