elasticsearch-curator 是官方收購的開源社區周邊產品,用來管理es的索引和快照。 在6.6以后官方推出了ILM(索引生命周期管理策略),更加易於操作和方便使用,可以在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命令行命令行查看所有索引:
# curator_cli --config config.yml action_close.yml --verbose
執行命令:
# curator --config config.yml action_close.yml