LoginSignup
5
8

More than 5 years have passed since last update.

CuratorでElasticsearchを減量

Posted at

Elasticsearchが重い。
PCのメモリがしょぼい。
もうこのデータ(index)見てない。

そんなあなたへ。

事前に準備する環境

Elasticsearch 5.0.1(5.0.0でも同様)
Python 2.7.10(2.7.6でも同様)

やること

まずpipが入ってない方は、

$ curl -kL https://bootstrap.pypa.io/get-pip.py | sudo python

Curatorのインストール

$ sudo pip install elasticsearch-curator
$ curator --version
curator, version 4.2.4

Elasticsearchが5.xの場合、curatorは4.x以上が必要だそうです。

Curatorに必要なファイル

2つあります

Configuration file

~/.curator/curator.yml
client:
  hosts:
    - localhost
  port: 9200
  url_prefix:
  use_ssl: False
  certificate:
  client_cert:
  client_key:
  ssl_no_validate: False
  http_auth:
# if x-pack is installed, set "http_auth: elastic:changeme"
  timeout: 30
  master_only: False

logging:
  loglevel: INFO
  logfile:
  logformat: default
  blacklist: ['elasticsearch', 'urllib3']

ACTION_FILE

actions:
  1:
    action: delete_indices
    description: >-
      (custommessage)Delete indices older than 5 days (based on index name), for .monitoring-es-
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.(custom message)
    options:
      ignore_empty_list: True
      timeout_override:
      continue_if_exception: False
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: .monitoring-es-
      exclude:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 5
      exclude:
  2:
    action: close
    description: >-
      (custom message)Close indices older than 4 days (based on index name), for .monitoring-es-
      prefixed indices.(custom message)
    options:
      ignore_empty_list: True
      delete_aliases: False
      timeout_override:
      continue_if_exception: False
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: .monitoring-es-
      exclude:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 4
      exclude:

これは、4日以上前のindexをクローズして、5日以上前のindexを削除してます。
ignore_empty_list: Trueでもし該当indexが見つからない時のエラーをスルーできます。
(付けないと、2回以上連続して実行した時にエラーで止まってしまいます。)
unit_countですが、4とすると4日前のデータも削除します。indexの%dが基準のようです。

実行

Configuration fileをデフォルトのパス(~/.curator/curator.yml)で作った場合

$ curator ${action_file}

じゃない場合

$ curator --config ${configuration_file} ${action_file}

あとはこれを気が向いた時に手動で走らせるか、ご自宅のjenkinsおじさんで日次実行させてあげてください。
※簡単なことしかしてません。もっと機能は豊富にあるので公式ドキュメントへどうぞ。

5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8