curator與elasticsearch版本的兼容性列表:https://www.elastic.co/guide/en/elasticsearch/client/curator/current/version-compatibility.html
測試使用的elasticsearch是6.6版本的,所以這裏安裝curator5.
centos7+curator5.2.0環境rpm包下載:https://packages.elastic.co/curator/5/centos/7/Packages/elasticsearch-curator-5.2.0-1.x86_64.rpm
下載完成之後把包放到linux中,安裝該rpm包:
[root@localhost elk-kafka]# rpm -ivh elasticsearch-curator-5.2.0-1.x86_64.rpm
驗證是否安裝成功:
[root@localhost elk-kafka]# curator --version
curator, version 5.2.0
默認的安裝路徑:
/opt/elasticsearch-curator
curator中需要使用到兩個配置文件:config.yml(用於連接es的配置)和action.yml(用於表明要做哪些操作)。文件名可以自定義,因爲在命令中會指定這些配置文件。這裏我把配置文件寫在了elasticsearch-curator目錄下 。
先創建一個logfile的目錄:
[root@localhost elasticsearch-curator]# mkdir log
[root@localhost elasticsearch-curator]# cd log
[root@localhost log]# touch wyh-curator.log
創建my-config.yml:
[root@localhost elasticsearch-curator]# cat my-config.yml
---
# Remember,leave a key empty if there is no value. None will be a string,
# not a Python "NoneType"
client:
hosts:
- 192.168.184.128
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: /opt/elasticsearch-curator/log/wyh-curator.log
logformat: default
blacklist: ['elasticsearch', 'urllib3']
先查看一下現有的Index:
http://192.168.184.128:9200/_cat/indices
這次應用想使用curator實現根據Index名稱中的日期來刪除6個月之前的index。
創建my-action.yml:
[root@localhost elasticsearch-curator]# cat my-action.yml
---
# 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: delete_indices
description: >-
Delete metric indices older than 6 months (based on index name), for
wyh-elk-index-2019.03.15
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
filters:
- filtertype: pattern
kind: regex
value: '^(wyh-elk-index-).*$'
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: months
unit_count: 6
運行:
[root@localhost elasticsearch-curator]# curator --config /opt/elasticsearch-curator/my-config.yml /opt/elasticsearch-curator/my-action.yml
運行成功之後,再去查看index就會發現6個月之前的index已經被刪除了。
這樣就實現了一個簡單的curator管理indexde應用。
=================其他配置說明======================
這裏特別要注意的是option選項,在多action,並且沒有互相依賴的情況下,一定要設置ignore_empty_list: True
。這裏代表的是,如果filter沒有找到符合查詢條件的index,略過。如果設置成false。則第一個action,沒有找到匹配的index,整個curator會被abort。
在action.yml文件中,不同序號的配置,是順序執行的,如果前面一個匹配的是一個空列表,會導致後續的不再執行,這時候爲了防止這種情況,需要將ignore_empty_list設置爲True。
source: 從哪裏來獲取索引時間。當user_age爲True時,該配置爲必填項。可以爲name、creation_date、field_stats。
name: 來源爲索引名稱,此時必須指定timestring來匹配索引名稱中的日期。
creation_date: 來源爲索引的創建時間,ES內部會保存每個索引創建的具體時間,可通過http://127.0.0.1:9200/my_index_name*?pretty查看。
filed_stats: 來源爲索引數據中某個日期字段,這個字段必須時ES能識別的日期字段,Curator會通過ES API獲取每個索引中這個字段的最大值跟最小值。
timestring: 當source爲name時必須配置,用於匹配索引名稱中的日期,如 '%Y-%m-%d',也可以是 '%Y.%m.%d'格式。