Elasticsearch索引管理 Curator

来自Linux78|wiki

Elasticsearch curator 可以协助管理Elasticsearch的index,snapshot

1.从集群中获取索引(或快照)的完整列表

2.迭代用户定义的过滤器列表,根据需要逐步从此可操作列表中删除索引(或快照)。

3.对可保留在可操作列表中的项目 执行各种操作。


起源:

早期是一个脚本 clearESindices.py,唯一功能是删除索引,随后又被改名为logstash_index_cleaner.py。

一段时间之后功能被整合到 logstash 的 expire_logs功能下 随着作者Jordan Sissel被Elastic(当时仍然是Elasticsearch)聘用,专职完善功能Elasticsearch Curator。

Curator现在对您的Elasticsearch索引执行许多操作,从删除到快照到分片分配路由。

https://github.com/elastic/curator

文档:

https://curator.readthedocs.io/en/latest/

现在的功能:

允许对索引和快照执行许多不同的操作,包括:

从别名添加或删除索引(或两者!)

更改分片路由分配

关闭指数

创建索引

删除索引

删除快照

打开关闭index

强制合并index

reindex索引,包括来自远程集群的索引

更改索引的每个分片的副本数

翻滚指数

拍摄索引的快照(备份)

还原快照


提供了CLI和API接口

从Elasticsearch 6.6版开始,Elasticsearch 为至少具有基本许可的用户提供了 索引生命周期管理(或ILM)。

ILM为用户提供了许多最常见的索引管理功能,而不是执行时间分析(这是Curator的工作方式)。

自ES6.6开始,Elasticsearch提供了basic license的ILM功能,ILM为用户提供许多常见的索引管理功能。

ILM基于时间周期来管理索引数据:
Hot
Warm
Cold
Delete 
使用的策略行为包括:
Set Priority
Rollover
Unfollow
Allocate
Read-Only
Force Merge
Shrink
Freeze
Delete

使用ILM还是curator?

ILM提供管理索引生命周期的功能,并且您至少拥有基本许可证(basic license),越来越多的组件默认使用了ILM,请使用ILM替换到curator。

Beats:

从7.0版开始,Filebeat在连接到支持生命周期管理的集群时默认使用索引生命周期管理。Filebeat自动加载默认策略并将其应用于Filebeat创建的任何索引。

可以在Kibana的索引生命周期策略UI中查看和编辑策略。

logstash:

索引生命周期管理功能需要logstash-output-elasticsearch插件的9.3.1或更高版本 。

Logstash可以使用索引生命周期管理 来自动化索引的管理。

索引生命周期管理的使用由ilm_enabled设置控制。默认情况下,这将自动检测Elasticsearch实例是否支持ILM,并在可用时使用它。ilm_enabled也可以设置为 true或false覆盖自动检测,或禁用ILM。


ILM和curator:

注意:如果没有设置allow_ilm_indices,curator将不会对与ILM政策相关的任何索引采取行动 。

Curator and ILM can coexist. However, to prevent Curator from accidentally interfering, or colliding with 
ILM policies, any index associated with an ILM policy name is excluded by default. This is true 
whether you have a Basic license or not, or whether the ILM policy is enabled or not.

curator可以和ILM共存,但是为防止curator和ILM的意外干扰或策略冲突,默认会排除与ILM策略名称关联的任何索引。

无论是否有basic license,或是否开启ILM策略。

Curator can be configured to work with ILM-enabled indices by 
setting the allow_ilm_indices option to true for any action.

通过将参数allow_ilm_indices设置为true,curator可以配置为和ILM索引一起使用

pip安装

yum -y install python36 python36-devel python36-pip
pip install elasticsearch-curator  --默认安装最新的版本

pip install -U elasticsearch-curator  --升级到最新版本
pip install -U --user elasticsearch-curator==X.Y.Z --指定用户升级到指定版本
pip3 install --upgrade pip

rm -rf /usr/local/bin/pip3
ln -s /usr/local/lib/python3.6/site-packages/pip /usr/local/bin/pip3
pip3.6 -V
pip 19.1.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
pip install  elasticsearch-curator

yum安装

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

 cat /etc/yum.repos.d/curator.repo
[curator-5]
name=CentOS/RHEL 7 repository for Elasticsearch Curator 5.x packages
baseurl=https://packages.elastic.co/curator/5/centos/7
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

yum install elasticsearch-curator -y

运行方式

curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML
若不指定confg文件默认读取当期目录的配置文件
~/.curator/curator.yml
Linux下:
/home/username/.curator/curator.yml
windows下:
C:\Users\username\.curator\curator.yml
 
--dry-run 若指定了参数,Curator将模拟行为配置文件ACTION_FILE.YML定义的行为
 
ACTION_FILE.YAML文件格式:
---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True.  If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
  1:
    action: ACTION1
    description: OPTIONAL DESCRIPTION
    options:
      option1: value1
      ...
      optionN: valueN
      continue_if_exception: False
      disable_action: True
    filters:
    - filtertype: *first*
      filter_element1: value1
      ...
      filter_elementN: valueN
    - filtertype: *second*
      filter_element1: value1
      ...
      filter_elementN: valueN
  2:
    action: ACTION2
    description: OPTIONAL DESCRIPTION
    options:
      option1: value1
      ...
      optionN: valueN
      continue_if_exception: False
      disable_action: True
    filters:
    - filtertype: *first*
      filter_element1: value1
      ...
      filter_elementN: valueN
    - filtertype: *second*
      filter_element1: value1
      ...
      filter_elementN: valueN
  3:
    action: ACTION3
    ...
  4:
    action: ACTION4
    ...

The high-level elements of each numbered action are:
 
action
description
options
filters

配置文件内容:

# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 127.0.0.1
  port: 9200
  url_prefix:
  use_ssl: False
  certificate:
  client_cert:
  client_key:
  ssl_no_validate: False
  http_auth:
  timeout: 30
  master_only: False
 
logging:
  loglevel: INFO #可选参数CRITICAL, ERROR, WARNING, INFO, DEBUG, or left empty
  logfile:
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']