Elasticsearch 集羣管理工具curator 接口模式使用介紹

安裝配置參考文檔:
http://blog.51cto.com/michaelkang/2333586

curator 接口模式使用介紹

curator的命令行語法如下:

curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML

--config : 之後跟上配置文件

--dry-run :調試參數,測試腳本運行是否正常;

ACTION_FILE.YML :action文件中可以包含一連串的action,curator接口集中式的config和action管理,可以方便我們重用變量,更利於維護和閱讀。

環境初始化也可以至通過 curator [--config CONFIG.YML] 直接指定

#### linux 默認查找路徑:

~/.curator/curator.yml

環境初始化也可以至通過 curator [--config CONFIG.YML] 直接指定


#### 初始化系統環境

配置 [--config CONFIG.YML]

mkdir -p  ~/.curator/

vim ~/.curator/curator.yml
---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 172.20.11.32     《== 集羣節點IP地址,可以寫多個
  port: 9200           《== datanode 接口
  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']

重要選項介紹

loglevel 支持 :

CRITICAL will only display critical messages.
ERROR will only display error and critical messages.
WARNING will display error, warning, and critical messages.
INFO will display informational, error, warning, and critical messages.
DEBUG will display debug messages, in addition to all of the above.

logfile 支持:

default, json, logstash 或者留空;

blacklist 支持:
那些關鍵字開頭索引日誌不輸出,默認即可。

ACTION_FILE.YML 介紹

action
每個action由三部分組成: 
- action,具體執行什麼操作 
- option, 配置哪些可選項 
- filter, 過濾條件,哪些index需要執行action

支持的動作如下:

Alias
Allocation
Close
Cluster Routing
Create Index
Delete Indices
Delete Snapshots
forceMerge
Index Settings
Open
Reindex
Replicas
Restore
Rollover
Shrink
Snapshot

option: 選項 ,filter:過濾條件,哪些index需要執行action,詳細參考官網;

https://www.elastic.co/guide/en/elasticsearch/client/curator/current/actions.html

實例

實例1 :定期刪除舊index

more delete_indices-eslog-ptlog.yml
actions:
  1:
    action: delete_indices
    description: >-
      刪除超過20天的索引(基於索引名稱),monitoring-*
      前綴索引。如果過濾器沒有導致錯誤,請忽略錯誤
      可操作的索引列表(ignore_empty_list)並徹底退出.
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: regex
      value: '^(\.monitoring-(es|kibana|logstash)-).*$'
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 20
  2:
    action: delete_indices
    description: >-
      刪除超過10天的索引(基於索引名稱ptlog)
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 10

實例2:reindex每天生成的index文件到月index文件

將所有每天生成的ptlog-dd-trace-prod-app-gateway-2018.11.文件彙總到 ptlog-dd-trace-prod-app-gateway-2018.11 月日誌文件,然後刪除 ptlog-dd-trace-prod-app-gateway-2018.11. 的日誌文件。

用於合併瑣碎index文件,減少集羣分片數;

awsesbak-reindex.yml 
---
actions:
  1:
    description: >-
       Reindex 11月份每天生成的index數據到 ptlog-$name-2018.11
    action: reindex
    options:
      disable_action: False
      wait_interval: 9
      max_wait: -1
      request_body:
        source:
          index: REINDEX_SELECTION
        dest:
          index: ptlog-dd-trace-prod-app-gateway-2018.11
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog-dd-trace-prod-app-gateway-2018.11.
  2:
    action: delete_indices
    description: >-
       刪除已經完成合並的索引
    options:
      ignore_empty_list: True
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: ptlog-dd-trace-prod-app-gateway-2018.11.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章