1. 程式人生 > >Elasticsearch叢集管理工具curator詳解-curator_cli

Elasticsearch叢集管理工具curator詳解-curator_cli

介紹

Curator 是一個elasticsearch叢集管理工具,在日常叢集管理方面的一個利器,掌握此神器,es叢集日常管理將輕鬆+愉快。

功能介紹

如下:

建立索引
刪除索引
關閉索引
刪除快照
從快照還原
新增或移除索引
開啟已經關閉的索引
更改分片路由配置
強制合併索引
更改索引每個分片的副本數量
為索引建立快照
reindices 、remote reindices
rollover indices(當某個別名指向的實際索引過大的時候,自動將別名指向下一個實際索引)
等等。。。。。

安裝配置(centos7)

install the public signing key:

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch   

新增repo 檔案

RHEL/CentOS 7:

cat >/etc/yum.repos.d/es-curator.repo <<-EOF
[curator-5]
name=CentOS/RHEL 7 repository for Elasticsearch Curator 5.x packages
baseurl=https://packages.elastic.co/curator/5/centos/7
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

安裝

yum install elasticsearch-curator -y   

curator的介面 介紹

curator提供了兩種介面。一個是curator_cli 命令列模式 ,一個是curator API 模式。  

curator_cli 命令列模式介紹

檢視幫助

curator_cli --help
Usage: curator_cli [OPTIONS] COMMAND [ARGS]...

常用命令

Commands:
  allocation        Shard Routing Allocation
  close             Close indices
  delete_indices    Delete indices
  delete_snapshots  Delete snapshots
  forcemerge        forceMerge index/shard segments
  open              Open indices
  replicas          Change replica count
  show_indices      Show indices
  show_snapshots    Show snapshots
  snapshot          Snapshot indices

例項

檢視 index

curator_cli --host 10.33.4.160 --port 9200 show_indices --verbos

ptlog-prod-userservice-2018.11.20         open    58.4MB     185964   5   1 2018-11-20T00:00:09Z
ptlog-prod-userservice-2018.11.21         open    58.3MB     185658   5   1 2018-11-21T00:00:12Z
ptlog-prod-userservice-2018.11.22         open    57.5MB     182808   5   1 2018-11-22T00:00:18Z
ptlog-prod-userservice-2018.11.23         open    56.7MB     180296   5   1 2018-11-23T00:00:18Z

檢視 snapshots

curator_cli --host 10.33.4.160 --port 9200 show_snapshots --verbose

過濾特性 (filter)

可以根據指定條件匹配,然後指定相應的動作。

例項演示

將30天以前建立的以ptlog開頭的index狀態為 close

curator_cli --host 172.20.11.32 --port 9200 close --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":30},{"filtertype":"pattern","kind":"prefix","value":"ptlog-"}]'

驗證結果:

檢視索引資訊

GET _cat/indices

      green open  15_hot_v1                                    P1FnKd6FRsG7NmnoWZ5hZA 20 1   1780400    59939    1.9gb  981.1mb
      close ptlog-pte-prod-userservice-2018.11.12        LaAHL-KKToqQ30f0dX6pqw                                          
      green open  ptlog-pte-prod-userservice-2018.11.27        bXIzgcrVR1eki8NpehUWcA  5 1     91756        0   57.6mb   28.8mb
      close ptlog-ddv-syslog-2018.10.26                  x4lnrJbbQ_uD4UXR8iXGWw                                          
      green open  ptlog-ddv-trace-2018.12.03                   BrGrgpsYQFOQM0TVHgR-QA  5 1       110        0  896.2kb  438.6kb
      close ptlog-pte-prod-ptservice-2018.11.09          A4Fil2BkRUC70jjcW9iczQ                                          
      close ptlog-pte-prod-userservice-2018.10.24        0eNY0RzYSNuxH5Fm5bpM9A                                          
發現符合條件的索引狀態都調整為 close !   

將30天以前建立的以ptlog開頭的index狀態為刪除

curator_cli --host 172.20.11.32 --port 9200 delete_indices --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":30},{"filtertype":"pattern","kind":"prefix","value":"ptlog-"}]'

輸入結果如下:

2018-12-12 14:33:57,064 INFO      ---deleting index ptlog-ddv-syslog-2018.10.23
...........
2018-12-12 14:33:57,066 INFO      ---deleting index ptlog-ddv-syslog-2018.11.02
2018-12-12 14:33:57,066 INFO      ---deleting index ptlog-ddv-syslog-2018.10.31
2018-12-12 14:33:57,066 INFO      ---deleting index ptlog-pte-prod-userservice-2018.10.25

再次檢視索引資訊

發現所有 close 狀態的索引都被刪除了,生產環境推薦這樣操作,先關閉一段時間觀察,然後再刪除資料,畢竟恢復資料比較麻煩。

GET _cat/indices

green open 15_hot_v1                                    P1FnKd6FRsG7NmnoWZ5hZA 20 1   1780726    59943    1.9gb  987.4mb
green open 6c_hot_v1                                    TIiPrWmaTRCPUShBfVdVIw 20 1  34826911   369431     37gb   18.4gb
green open ptlog-event-pte-prod-ecology-2018.12.10      FSgH1MFkRbKkR7Y27ugNXA  2 1         0        0      1kb     522b

elasticsearch 叢集管理工具curator 介面模式使用介紹

http://blog.51cto.com/michaelkang/2333607