功能:
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索引一起使用。
兼容性:
安装:
支持windows、linux、mac下的软件包安装,pip安装和源码包安装
使用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
# pip list
Package Version
--------------------- --------
boto3 1.9.159
botocore 1.12.159
certifi 2019.3.9
chardet 3.0.4
click 6.7
docutils 0.14
elasticsearch 7.0.2
elasticsearch-curator 5.7.6
idna 2.8
jmespath 0.9.4
pip 19.1.1
python-dateutil 2.8.0
PyYAML 3.12
requests 2.22.0
requests-aws4auth 0.9
s3transfer 0.2.0
setuptools 39.2.0
six 1.12.0
urllib3 1.24.3
voluptuous 0.11.5
版本查询:
# curator --version
curator, version 5.7.6
# curator_cli --version
curator_cli, version 5.7.6
# curator --help
Usage: curator [OPTIONS] ACTION_FILE
Curator for Elasticsearch indices.
See http://elastic.co/guide/en/elasticsearch/client/curator/current
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_cli --help
Usage: curator_cli [OPTIONS] COMMAND [ARGS]...
Options:
--config PATH Path to configuration file. Default: ~/.curator/curator.yml
--host TEXT Elasticsearch host.
--url_prefix TEXT Elasticsearch http url prefix.
--port TEXT Elasticsearch port.
--use_ssl Connect to Elasticsearch through SSL.
--certificate TEXT Path to certificate to use for SSL validation.
--client-cert TEXT Path to file containing SSL certificate for client auth.
--client-key TEXT Path to file containing SSL key for client auth.
--ssl-no-validate Do not validate SSL certificate
--http_auth TEXT Use Basic Authentication ex: user:pass
--timeout INTEGER Connection timeout in seconds.
--master-only Only operate on elected master node.
--dry-run Do not perform any changes.
--loglevel TEXT Log level
--logfile TEXT log file
--logformat TEXT Log output format [default|logstash|json].
--version Show the version and exit.
--help Show this message and exit.
Commands:
alias Add/Remove Indices to/from Alias
allocation Shard Routing Allocation
close Close Indices
delete_indices Delete Indices
delete_snapshots Delete Snapshots
forcemerge forceMerge Indices (reduce segment count)
open Open Indices
replicas Change Replica Count
restore Restore Indices
rollover Rollover Index associated with Alias
show_indices Show Indices
show_snapshots Show Snapshots
shrink Shrink Indices to --number_of_shards
snapshot Snapshot Indices
使用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 --version
curator, version 5.7.6
# curator_cli --version
curator_cli, version 5.7.6
YUM安装的目录:
或者通过RPM直接安装:
https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.7.6-1.x86_64.rpm
退出代码:
Exit codes will indicate success or failure.
0 — Success
1 — Failure
-1 - Exception raised that does not result in a 1 exit code.
运行方式:
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']
参考:
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/examples.html
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actions.html
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html