Elastic Curator 的配置和運(yùn)行
elasticsearch索引的管理工具curator4的配置和運(yùn)行詳解,這個(gè)是elastic官方提供的工具.
Singleton Command Line Interface
運(yùn)行:
curator_cli [OPTIONS] COMMAND [ARGS]...
# 如果用不指定的Options連接es,可以指定curator.yml配置文件讀取連接es和curator的參數(shù)
# 默認(rèn)配置文件~/.curator/curator.yml
curator_cli --config /PATH/TO/curator.yml COMMAND [ARGS]...
# 幫助命令
curator_cli --help
curator_cli show_indices --help
# 例子
curator_cli --host 192.168.1.36:9200 show_indices
新版的curator_cli命令行工具對(duì)條件的匹配已經(jīng)改了,
需要使用--filter_list JSON 的格式來過濾。(感覺已經(jīng)沒幫助可查了,用起來變得復(fù)雜- -!)
# 例如查看索引,需要使用--filter_list來過濾需要的索引
curator_cli --host 192.168.13.36:9200 show_indices --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":13},{"filtertype":"pattern","kind":"prefix","value":"logstash"}]'
這樣還不如就用這個(gè)了:
curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML
Command Line Interface
運(yùn)行:
curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML
--config CONFIG.YML curator配置文件,配置連接es等參數(shù),
默認(rèn)為~/.curator/curator.yml
--dry-run 測(cè)試運(yùn)行
ACTION_FILE.YML YAML actionfile指定執(zhí)行操作的文件
ACTION_FILE.YML
ACTION_FILE.YML文件用于配置curator需要執(zhí)行的操作。
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actionfile.html
curator_actions_cron.yml
主要用于配置curator定時(shí)執(zhí)行任務(wù),
將運(yùn)行命令放在crontab中在每日凌晨0點(diǎn)過后執(zhí)行,
用于清理和優(yōu)化es的索引。
---
actions:
1:
action: delete_indices
description: "刪除過期索引"
options:
# action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
disable_action: False
# 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
ignore_empty_list: True
# 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
continue_if_exception: True
filters:
# 是否排除隱藏索引,如.kibana
- filtertype: kibana
exclude: True
# 是否排除open狀態(tài)的索引
- filtertype: opened
exclude: True
# 處理30天前的索引
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 30
exclude: False
2:
action: allocation
description: "冷熱數(shù)據(jù)分離任務(wù):將非當(dāng)天索引從hot節(jié)點(diǎn)遷移到stale節(jié)點(diǎn)。"
options:
# action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
disable_action: False
# ignore_empty_list標(biāo)識(shí)忽略選項(xiàng),默認(rèn)False,
# 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
ignore_empty_list: True
# 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
continue_if_exception: True
allocation_type: include
key: zone
value: stale
wait_for_completion: False
filters:
# 是否排除隱藏索引,如.kibana
- filtertype: kibana
exclude: True
# 是否排除open狀態(tài)的索引
- filtertype: opened
exclude: False
# 處理1天前的索引
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 1
exclude: False
3:
action: forcemerge
description: "強(qiáng)制歸并索引segments,優(yōu)化es性能"
options:
# action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
disable_action: False
# ignore_empty_list標(biāo)識(shí)忽略選項(xiàng),默認(rèn)False,
# 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
ignore_empty_list: True
# 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
continue_if_exception: True
max_num_segments: 1
delay:
filters:
# 是否排除隱藏索引,如.kibana
- filtertype: kibana
exclude: False
# 是否排除open狀態(tài)的索引
- filtertype: opened
exclude: False
# 處理1天前的索引
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 2
exclude: False
4:
action: close
description: "關(guān)閉匹配的索引,減少es內(nèi)存占用"
options:
# action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
disable_action: False
# 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
ignore_empty_list: True
# 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
continue_if_exception: True
# close索引前是否刪除aliases
delete_aliases: False
filters:
# 是否排除隱藏索引,如.kibana
- filtertype: kibana
exclude: True
# 是否排除open狀態(tài)的索引
- filtertype: opened
exclude: False
# 處理7天前的索引
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 7
exclude: False
curator_actions_cmd.yml
主要用于需要手動(dòng)處理的es索引任務(wù)。
---
actions:
1:
action: open
description: "open匹配的索引"
options:
# action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False 【記得手動(dòng)開啟action】
disable_action: True
# 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
ignore_empty_list: True
# 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
continue_if_exception: True
# 下面開始匹配需要執(zhí)行的任務(wù)的索引 【記得手動(dòng)修改filters條件】
filters:
- filtertype: closed
exclude: False
# 是否排除open狀態(tài)的索引
- filtertype: opened
exclude: True
# 是否排除隱藏索引,如.kibana
- filtertype: kibana
exclude: True
# 主要在這里匹配索引的時(shí)間
- filtertype: age
source: name
# direction值為: younger|older
direction: younger
timestring: '%Y.%m.%d'
unit: days
unit_count: 14
exclude: False
# 這里匹配索引名稱
- filtertype: pattern
# kind值: prefix|suffix|timestring|regex
kind: prefix
value: logstash-
exclude: False
Environment Variables
環(huán)境變量可以應(yīng)用與執(zhí)行curator和curator_cli命令。
環(huán)境變量支持寫入CONFIG.YML和ACTION_FILE.YML。
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/envvars.html
CONFIG.YML
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/configfile.html
CONFIG.YML是curator和curator_cli的全局配置文件。
在使用命令時(shí),如果不指定配置文件,默認(rèn)讀取文件:
~/.curator/curator.yml
curator.yml
---
# Remember, leave a key empty if there is no value. None will be a string,
# not a Python "NoneType"
client:
hosts:
- 10.0.0.1
- 10.0.0.2:9200
- 10.0.0.3:9201
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']
curator4版本當(dāng)前的坑說明
curator當(dāng)前在filters中的age類型中對(duì)時(shí)間存在時(shí)差問題.
原因是,這個(gè)age對(duì)時(shí)間的計(jì)算形式如下:
point_of_reference = epoch - ((number of seconds in unit) * unit_count)
<point_of_reference>就是計(jì)算出來的時(shí)間
<epoch>是當(dāng)前時(shí)間的utc時(shí)間
<number of seconds in unit>就是配置的day或hours單位的秒數(shù),就是配置的unit換算來的.
<unit_count>就是unit_count值
curator直接是把<point_of_reference>這個(gè)時(shí)間拿來匹配索引的時(shí)間,比如索引名稱的后綴時(shí)間%Y.%m.%d
由這里很明顯的知道了由于<epoch>是utc時(shí)間,所以<point_of_reference>也utc時(shí)間.
那么,中國(guó)的和utc時(shí)間是要+8小時(shí)的,所以這里匹配出來的時(shí)間要再加8小時(shí)間才是對(duì)的.
當(dāng)前看似官方也知道這個(gè)問題,后面的版本可能會(huì)再換算一個(gè)native時(shí)區(qū)的時(shí)間吧.
當(dāng)前可以這樣解決:
在換算時(shí)間的時(shí)候,有意識(shí)的先扣掉8個(gè)小時(shí)再換算,這樣就可以解決問題了:
比如要獲取前一天是索引,改成這樣:
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: hours
unit_count: 16
exclude: False