轉載來源 :
es索引管理工具-curator
https://www.cnblogs.com/xiaobaozi-95/p/10450380.html
介紹
elasticsearch-curator 是官方收購的開源社群周邊産品,用來管理es的索引和快照。 在6.6以後官方推出了ILM(索引生命周期管理政策),更加易于操作和友善使用,可以通過restful api,也可以在kibana界面直接操作。
官方文檔:
https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html
功能包括:從别名添加、删除索引,更改分片路由配置設定,打開/關閉索引,建立/删除索引,快照管理、合并segment,更改索引分片副本數等。
目前使用的elasticsearch-curator版本是5.4, Python2.6安裝會出現問題.建議在安裝在python2.7+的環境中.
安裝:
# pip install elasticsearch-curator
使用:
指令文法:
指令行參數: curator [–config CONFIG.YML] [–dry-run] ACTION_FILE.YML
$ 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. # --dry-run參數在調試action_file時比較重要
--version Show the version and exit.
--help Show this message and exit.
curator運作需兩個配置檔案:
config.yml:用于連接配接ES叢集配置
action.yml:用于配置要執行的操作,檔案名稱可以随意命名
config.yml配置:
# cat curator.yml
# Remember, leave a key empty ifthere is no value. None will be a string,
# not a Python "NoneType"
client:
hosts:
- 172.16.10.23
- 172.16.10.24
- 172.16.10.25
port: 9200
url_prefix:
use_ssl: False
certificate:
client_cert:
client_key:
ssl_no_validate: False
http_auth:
timeout: 3600
master_only: False
logging:
loglevel: INFO
# logfile: /home/test/curator.log
logfile:
logformat: default
blacklist: ['elasticsearch', 'urllib3']
配置說明:
-
hosts:
同一個叢集内節點IP,如果端口不同,可寫成ip:port形式;隻能一次使用一個叢集。在主機設定中包含來自多個叢集的節點将導緻錯誤。
- port: 預設值是9200。這個值隻适用于沒有端口的主機。
- timeout: 預設值是30S,根據實際使用情況調整.
- logfile: 預設值是空的,會将執行結果輸出到
- STDOUT或控制台。如果指定檔案,會把執行日志輸出到檔案中,而不是控制台.
-
blacklist: 預設值為’elasticsearch’, ‘urllib3’。Python子產品不被輸出。除非需要調試某些問題,
否則請使用預設值.
ACTION_FILE配置
配置說明:關閉字首為syslog- 并且 時間格式為 '%Y.%m.%d’的7天前的所有的文檔.
# cat action_close.yml
---
# Remember, leave a key empty ifthere 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 thisaction as a template, be sure to set thisto False after
# copying it.
actions:
1:
action: close
description: >-
Close indices older than 30days (based on index name), forlogstash-
prefixed indices.
options:
delete_aliases: False
disable_action: False
filters: # filters下的配置都是隐含的邏輯“AND”操作連結.
- filtertype: pattern
kind: prefix
value: syslog-
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: 7
curator_cli指令行指令行檢視所有索引:
執行指令:
參考連結 :