全部产品
Search
文档中心

检索分析服务Elasticsearch版:Curator操作指南

更新时间:Jun 15, 2023

Curator是Elasticsearch官方提供的一个索引管理工具,提供了删除、创建、关闭、段合并索引等功能。本文介绍Curator的使用方法,包括安装Curator、单命令行接口、crontab定时执行、冷热数据分离实践以及跨节点迁移索引。

安装Curator

前提条件

  • 创建阿里云Elasticsearch实例。

    详情请参见创建阿里云Elasticsearch实例

  • 创建阿里云ECS实例,并准备Python环境。

    本文以CentOS 7.3 64位的ECS为例,所购买的实例需要与阿里云ES实例在同一地域和可用区,以及同一专有网络VPC(Virtual Private Cloud)下。详情请参见自定义购买实例

操作步骤

  1. 连接ECS实例。具体操作请参见通过密码或密钥认证登录Linux实例

    说明

    本文档以普通用户权限为例。

  2. 执行以下命令安装Curator。

    sudo pip install elasticsearch-curator
    说明
    • 建议您安装5.6.0版本的Curator,它可以支持阿里云ES 5.5.3和6.3.2版本。关于Curator版本与Elasticsearch版本的兼容性,请参见Version Compatibility

    • 更多关于Curator的详细说明请参见Curator

  3. 安装成功后,执行以下命令查看Curator版本。

    sudo curator --version

    正常情况下,返回结果如下。

    curator, version 5.6.0

单命令行接口

您可以使用curator_cli命令执行单个操作,使用方式请参见Singleton Command Line Interface

说明
  • curator_cli命令只能执行一个操作。

  • 并不是所有的操作都适用于单命令行执行,例如Alias和Restore操作。

crontab定时执行

您可以通过crontab和curator命令实现定时执行一系列操作。

curator命令格式如下。

curator [OPTIONS] ACTION_FILE
Options:
  --config PATH  Path to configuration file. Default: ~/.curator/curator.yml
  --dry-run      Do not perform any changes.
  --version      Show the version and exit.
  --help         Show this message and exit.

执行curator命令时需要指定config.yml文件和action.yml文件,详情请参见config.yml官方文档action.yml官方文档

冷热数据分离实践

详细操作方法请参见使用Curator进行冷热数据迁移

将索引从hot节点迁移到warm节点

  1. /usr/curator/路径下创建config.yml文件,配置内容参考如下示例。

    client:
      hosts:
        - http://es-cn-0pxxxxxxxxxxxx234.elasticsearch.aliyuncs.com
      port: 9200
      url_prefix:
      use_ssl: False
      certificate:
      client_cert:
      client_key:
      ssl_no_validate: False
      http_auth: user:password
      timeout: 30
      master_only: False
    logging:
      loglevel: INFO
      logfile:
      logformat: default
      blacklist: ['elasticsearch', 'urllib3']
    • hosts:替换为对应阿里云ES实例的私网或外网地址(此处以私网地址为例)。

    • http_auth:替换为对应阿里云ES实例的账号和密码。

  2. /usr/curator/路径下创建action.yml文件,配置内容参考如下示例。

    actions:
      1:
        action: allocation
        description: "Apply shard allocation filtering rules to the specified indices"
        options:
          key: box_type
          value: warm
          allocation_type: require
          wait_for_completion: true
          timeout_override:
          continue_if_exception: false
          disable_action: false
        filters:
        - filtertype: pattern
          kind: prefix
          value: logstash-
        - filtertype: age
          source: creation_date
          direction: older
          timestring: '%Y-%m-%dT%H:%M:%S'
          unit: minutes
          unit_count: 30

    以上示例按照索引创建时间,将30分钟前创建在hot节点以logstash-开头的索引迁移到warm节点中。您也可以根据实际场景自定义配置action.yml文件。

  3. 执行以下命令,验证curator命令能否正常执行。

    sudo curator --config /usr/curator/config.yml /usr/curator/action.yml

    正常情况下会返回类似如下所示的信息。

    2019-02-12 20:11:30,607 INFO      Preparing Action ID: 1, "allocation"
    2019-02-12 20:11:30,612 INFO      Trying Action ID: 1, "allocation": Apply shard allocation filtering rules to the specified indices
    2019-02-12 20:11:30,693 INFO      Updating index setting {'index.routing.allocation.require.box_type': 'warm'}
    2019-02-12 20:12:57,925 INFO      Health Check for all provided keys passed.
    2019-02-12 20:12:57,925 INFO      Action ID: 1, "allocation" completed.
    2019-02-12 20:12:57,925 INFO      Job completed.
  4. 执行以下命令,使用crontab实现每隔15分钟定时执行curator命令。

    sudo */15 * * * * curator --config /usr/curator/config.yml /usr/curator/action.yml