Curator操作指南
Curator是Elasticsearch官方提供的一個索引管理工具,提供了刪除、創(chuàng)建、關(guān)閉、段合并索引等功能。本文介紹Curator的使用方法,包括安裝Curator、單命令行接口、crontab定時執(zhí)行、冷熱數(shù)據(jù)分離實踐以及跨節(jié)點遷移索引。
安裝Curator
前提條件
創(chuàng)建阿里云Elasticsearch實例。
創(chuàng)建阿里云ECS實例,并準(zhǔn)備Python環(huán)境。
本文以CentOS 7.3 64位的ECS為例,所購買的實例需要與阿里云ES實例在同一地域和可用區(qū),以及同一專有網(wǎng)絡(luò)VPC(Virtual Private Cloud)下。詳情請參見自定義購買實例。
操作步驟
連接ECS實例。具體操作請參見通過密碼或密鑰認(rèn)證登錄Linux實例。
說明本文檔以普通用戶權(quán)限為例。
執(zhí)行以下命令安裝Curator。
sudo pip install elasticsearch-curator
說明建議您安裝5.6.0版本的Curator,它可以支持阿里云ES 5.5.3和6.3.2版本。關(guān)于Curator版本與Elasticsearch版本的兼容性,請參見Version Compatibility。
更多關(guān)于Curator的詳細(xì)說明請參見Curator。
安裝成功后,執(zhí)行以下命令查看Curator版本。
sudo curator --version
正常情況下,返回結(jié)果如下。
curator, version 5.6.0
單命令行接口
您可以使用curator_cli命令執(zhí)行單個操作,使用方式請參見Singleton Command Line Interface。
curator_cli命令只能執(zhí)行一個操作。
并不是所有的操作都適用于單命令行執(zhí)行,例如Alias和Restore操作。
crontab定時執(zhí)行
您可以通過crontab和curator命令實現(xiàn)定時執(zhí)行一系列操作。
curator命令格式如下。
curator [OPTIONS] ACTION_FILE
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.
執(zhí)行curator命令時需要指定config.yml文件和action.yml文件,詳情請參見config.yml官方文檔和action.yml官方文檔。
冷熱數(shù)據(jù)分離實踐
詳細(xì)操作方法請參見使用Curator進(jìn)行冷熱數(shù)據(jù)遷移。
將索引從hot節(jié)點遷移到warm節(jié)點
在/usr/curator/路徑下創(chuàng)建config.yml文件,配置內(nèi)容參考如下示例。
client: hosts: - http://es-cn-0pxxxxxxxxxxxx234.elasticsearch.aliyuncs.com port: 9200 url_prefix: use_ssl: False certificate: client_cert: client_key: ssl_no_validate: False http_auth: user:password timeout: 30 master_only: False logging: loglevel: INFO logfile: logformat: default blacklist: ['elasticsearch', 'urllib3']
hosts
:替換為對應(yīng)阿里云ES實例的私網(wǎng)或外網(wǎng)地址(此處以私網(wǎng)地址為例)。http_auth
:替換為對應(yīng)阿里云ES實例的賬號和密碼。
在/usr/curator/路徑下創(chuàng)建action.yml文件,配置內(nèi)容參考如下示例。
actions: 1: action: allocation description: "Apply shard allocation filtering rules to the specified indices" options: key: box_type value: warm allocation_type: require wait_for_completion: true timeout_override: continue_if_exception: false disable_action: false filters: - filtertype: pattern kind: prefix value: logstash- - filtertype: age source: creation_date direction: older timestring: '%Y-%m-%dT%H:%M:%S' unit: minutes unit_count: 30
以上示例按照索引創(chuàng)建時間,將30分鐘前創(chuàng)建在
hot
節(jié)點以logstash-
開頭的索引遷移到warm
節(jié)點中。您也可以根據(jù)實際場景自定義配置action.yml文件。執(zhí)行以下命令,驗證curator命令能否正常執(zhí)行。
sudo curator --config /usr/curator/config.yml /usr/curator/action.yml
正常情況下會返回類似如下所示的信息。
2019-02-12 20:11:30,607 INFO Preparing Action ID: 1, "allocation" 2019-02-12 20:11:30,612 INFO Trying Action ID: 1, "allocation": Apply shard allocation filtering rules to the specified indices 2019-02-12 20:11:30,693 INFO Updating index setting {'index.routing.allocation.require.box_type': 'warm'} 2019-02-12 20:12:57,925 INFO Health Check for all provided keys passed. 2019-02-12 20:12:57,925 INFO Action ID: 1, "allocation" completed. 2019-02-12 20:12:57,925 INFO Job completed.
執(zhí)行以下命令,使用crontab實現(xiàn)每隔15分鐘定時執(zhí)行curator命令。
crontab -e */15 * * * * curator --config /usr/curator/config.yml /usr/curator/action.yml