curator-4.1 版本使用

旧版使用--host的选项来操作elastic。新版使用接YAML的配置文件来定义配置文件。

安装方法

1
2
3
yum install python-pip  -y
pip install --upgrade pip
pip install elasticsearch-curator -y

命令格式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# curator --help
Usage: curator [OPTIONS] ACTION_FILE
Curator for Elasticsearch indices.

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.yml(服务器的配置文件)
## 编写action.yml(执行的命令)
/bin/curator --config curator.yml action.yml

编写服务器配置文件

vim curator.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
client: ##配置要连接的客户端
hosts:
- 192.168.56.11
- 192.168.56.12
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
logfile:
logformat: default
blacklist: ['elasticsearch', 'urllib3']

实例

删除五天前的log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
actions:
1:
action: delete_indices
description: >-
Delete indices older than 45 days (based on index name), for logstash-
prefixed indices. Ignore the error if the filter does not result in an
actionable list of indices (ignore_empty_list) and exit cleanly.
options:
ignore_empty_list: True
timeout_override:
continue_if_exception: False
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: chuye-adcounter-
exclude: True ##默认为False,如果为True,表示排除。
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 5
exclude:

### 代码解释
第一步:指定要做的动作(delete_indices)删除索引。
第二步:使用filters过滤出要删除的参数。
第三步:使用filter:pathern模块,匹配要删除索引的名称,exclude=True表示排除。
第四步: 使用filter:age模块,匹配时间,删除多久。

创建备份镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
actions:
1:
action: snapshot
description: >-
Snapshot logstash- prefixed indices older than 1 day (based on index
creation_date) with the default snapshot name pattern of
'curator-%Y%m%d%H%M%S'. Wait for the snapshot to complete. Do not skip
the repository filesystem access check. Use the other options to create
the snapshot.
options:
repository: search-backup ##备份到那个仓库
name: search-%Y%m%d%H%M%S ## 备份服务器的时间
ignore_unavailable: False
include_global_state: True
partial: False
wait_for_completion: True
skip_repo_fs_check: False
timeout_override:
continue_if_exception: False
disable_action: False
filters:
- filtertype: pattern ## 匹配要备份的分片
kind: regex
value: .*
exclude:
- filtertype: age ## 设置要备份的时间范围
source: creation_date
direction: older
unit: days
unit_count: 1
exclude:

帮助文档

官方文档