Elastic Curator 的配置和運(yùn)行

Elastic Curator 的配置和運(yùn)行

elasticsearch索引的管理工具curator4的配置和運(yùn)行詳解,這個(gè)是elastic官方提供的工具.

Singleton Command Line Interface

運(yùn)行:

curator_cli [OPTIONS] COMMAND [ARGS]...
# 如果用不指定的Options連接es,可以指定curator.yml配置文件讀取連接es和curator的參數(shù)
# 默認(rèn)配置文件~/.curator/curator.yml
curator_cli --config /PATH/TO/curator.yml COMMAND [ARGS]...

# 幫助命令
curator_cli --help
curator_cli show_indices --help

# 例子
curator_cli --host 192.168.1.36:9200 show_indices

新版的curator_cli命令行工具對(duì)條件的匹配已經(jīng)改了,
需要使用--filter_list JSON 的格式來過濾。(感覺已經(jīng)沒幫助可查了,用起來變得復(fù)雜- -!)

# 例如查看索引,需要使用--filter_list來過濾需要的索引
curator_cli --host 192.168.13.36:9200 show_indices  --filter_list '[{"filtertype":"age","source":"creation_date","direction":"older","unit":"days","unit_count":13},{"filtertype":"pattern","kind":"prefix","value":"logstash"}]'

這樣還不如就用這個(gè)了:
curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML

Command Line Interface

運(yùn)行:

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

  --config CONFIG.YML    curator配置文件,配置連接es等參數(shù),
                         默認(rèn)為~/.curator/curator.yml
  --dry-run              測(cè)試運(yùn)行
  ACTION_FILE.YML        YAML actionfile指定執(zhí)行操作的文件

ACTION_FILE.YML

ACTION_FILE.YML文件用于配置curator需要執(zhí)行的操作。

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

curator_actions_cron.yml

主要用于配置curator定時(shí)執(zhí)行任務(wù),
將運(yùn)行命令放在crontab中在每日凌晨0點(diǎn)過后執(zhí)行,
用于清理和優(yōu)化es的索引。

---
actions:
  1:
    action: delete_indices
    description: "刪除過期索引"
    options:
      # action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
      disable_action: False
      # 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
      ignore_empty_list: True
      # 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
      continue_if_exception: True
    filters:
    # 是否排除隱藏索引,如.kibana
    - filtertype: kibana
      exclude: True
    # 是否排除open狀態(tài)的索引
    - filtertype: opened
      exclude: True
    # 處理30天前的索引
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 30
      exclude: False
  2:
    action: allocation
    description: "冷熱數(shù)據(jù)分離任務(wù):將非當(dāng)天索引從hot節(jié)點(diǎn)遷移到stale節(jié)點(diǎn)。"
    options:
      # action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
      disable_action: False
      # ignore_empty_list標(biāo)識(shí)忽略選項(xiàng),默認(rèn)False,
      # 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
      ignore_empty_list: True
      # 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
      continue_if_exception: True
      allocation_type: include
      key: zone
      value: stale
      wait_for_completion: False
    filters:
    # 是否排除隱藏索引,如.kibana
    - filtertype: kibana
      exclude: True
    # 是否排除open狀態(tài)的索引
    - filtertype: opened
      exclude: False
    # 處理1天前的索引
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 1
      exclude: False
  3:
    action: forcemerge
    description: "強(qiáng)制歸并索引segments,優(yōu)化es性能"
    options:
      # action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
      disable_action: False
      # ignore_empty_list標(biāo)識(shí)忽略選項(xiàng),默認(rèn)False,
      # 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
      ignore_empty_list: True
      # 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
      continue_if_exception: True
      max_num_segments: 1
      delay:
    filters:
    # 是否排除隱藏索引,如.kibana
    - filtertype: kibana
      exclude: False
    # 是否排除open狀態(tài)的索引
    - filtertype: opened
      exclude: False
    # 處理1天前的索引
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 2
      exclude: False
  4:
    action: close
    description: "關(guān)閉匹配的索引,減少es內(nèi)存占用"
    options:
      # action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False
      disable_action: False
      # 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
      ignore_empty_list: True
      # 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
      continue_if_exception: True
      # close索引前是否刪除aliases
      delete_aliases: False
    filters:
    # 是否排除隱藏索引,如.kibana
    - filtertype: kibana
      exclude: True
    # 是否排除open狀態(tài)的索引
    - filtertype: opened
      exclude: False
    # 處理7天前的索引
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 7
      exclude: False

curator_actions_cmd.yml

主要用于需要手動(dòng)處理的es索引任務(wù)。

---
actions:
  1:
    action: open
    description: "open匹配的索引"
    options:
      # action開關(guān),為True表示不執(zhí)行這個(gè)action,默認(rèn)False 【記得手動(dòng)開啟action】
      disable_action: True
      # 如果為True,則在filters空列表時(shí),繼續(xù)下一個(gè)action處理而不是退出程序。
      ignore_empty_list: True
      # 發(fā)現(xiàn)錯(cuò)誤后,繼續(xù)執(zhí)行下一個(gè)索引操作,默認(rèn)False
      continue_if_exception: True
    # 下面開始匹配需要執(zhí)行的任務(wù)的索引 【記得手動(dòng)修改filters條件】
    filters:
    - filtertype: closed
      exclude: False
    # 是否排除open狀態(tài)的索引
    - filtertype: opened
      exclude: True
    # 是否排除隱藏索引,如.kibana
    - filtertype: kibana
      exclude: True
    # 主要在這里匹配索引的時(shí)間
    - filtertype: age
      source: name
      # direction值為: younger|older
      direction: younger
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 14
      exclude: False
    # 這里匹配索引名稱
    - filtertype: pattern
      # kind值: prefix|suffix|timestring|regex
      kind: prefix
      value: logstash-
      exclude: False

Environment Variables

環(huán)境變量可以應(yīng)用與執(zhí)行curator和curator_cli命令。

環(huán)境變量支持寫入CONFIG.YML和ACTION_FILE.YML。

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

CONFIG.YML

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

CONFIG.YML是curator和curator_cli的全局配置文件。

在使用命令時(shí),如果不指定配置文件,默認(rèn)讀取文件:

~/.curator/curator.yml

curator.yml

---
# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
client:
  hosts:
    - 10.0.0.1
    - 10.0.0.2:9200
    - 10.0.0.3:9201
  port: 9200
  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']

curator4版本當(dāng)前的坑說明

curator當(dāng)前在filters中的age類型中對(duì)時(shí)間存在時(shí)差問題.

原因是,這個(gè)age對(duì)時(shí)間的計(jì)算形式如下:

point_of_reference = epoch - ((number of seconds in unit) * unit_count)

<point_of_reference>就是計(jì)算出來的時(shí)間
<epoch>是當(dāng)前時(shí)間的utc時(shí)間
<number of seconds in unit>就是配置的day或hours單位的秒數(shù),就是配置的unit換算來的.
<unit_count>就是unit_count值

curator直接是把<point_of_reference>這個(gè)時(shí)間拿來匹配索引的時(shí)間,比如索引名稱的后綴時(shí)間%Y.%m.%d

由這里很明顯的知道了由于<epoch>是utc時(shí)間,所以<point_of_reference>也utc時(shí)間.
那么,中國(guó)的和utc時(shí)間是要+8小時(shí)的,所以這里匹配出來的時(shí)間要再加8小時(shí)間才是對(duì)的.

當(dāng)前看似官方也知道這個(gè)問題,后面的版本可能會(huì)再換算一個(gè)native時(shí)區(qū)的時(shí)間吧.

當(dāng)前可以這樣解決:
在換算時(shí)間的時(shí)候,有意識(shí)的先扣掉8個(gè)小時(shí)再換算,這樣就可以解決問題了:

比如要獲取前一天是索引,改成這樣:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: hours
      unit_count: 16
      exclude: False
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、ELK平臺(tái)介紹 在搜索ELK資料的時(shí)候,發(fā)現(xiàn)這篇文章比較好,于是摘抄一小段:以下內(nèi)容來自:http://bai...
    螺旋上升的世界閱讀 3,362評(píng)論 0 20
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,534評(píng)論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,261評(píng)論 6 342
  • 計(jì)劃的在完美,也敵不過意志力薄弱
    咣當(dāng)xx閱讀 110評(píng)論 0 0
  • 想買大福, 可素家里的冰箱被麻麻買的臨期酸奶塞的滿滿的。 此時(shí)此刻,我覺得我的心比冰箱還要塞。
    禾阿乃閱讀 226評(píng)論 0 1

友情鏈接更多精彩內(nèi)容