LoginSignup
3
3

More than 5 years have passed since last update.

Curator5.4でElasticsearch5.5のSnapshotの取得と削除、indexのDeleteを行う

Posted at

こちらはElastic stack Advent Calendarの7日目の記事となります。

今回はElasticsearch 5.5に対して、Curator 5.4を適用し、Snapshotの取得、indexのDeleteを行う方法について書きたい思います。

CuratorとはElastic社が提供する運用支援ツールで、Pythonで動作します。
Cronなどで定期実行することでメンテンスを自動化することができます。

今回は以下の構成で行います
・CentOS 7
・JDK 1.8.0_141
・Python 3.6
・Elasticsearch 5.5
・Curator 5.4

注意点

本記事はCurator 5.4の記事となります。
Curatorは3.5までと4.0以降で設定方法、実行方法が大きく異なります。

ElasticsearchのバージョンとCuratorのバージョンの対応についてはこちらを参照してください。

Curator 3.5までの記事であれば
・Curator: 時系列インデックスの管理(日本語訳)
http://blog.johtani.info/blog/2014/01/24/curator-tending-your-time-series-indices-in-japanese/

・CuratorによるElasticsearchのメンテナンス
https://dev.classmethod.jp/server-side/elasticsearch/elastic-curator/

が参考になると思います。

またCuratorには他にもいくつか機能があります。
他機能についてはこちらをご覧ください。

Curatorのインストール方法

Curatorはpipコマンドで簡単にインストールできます。

pip install elasticsearch-curator

バージョンを指定してインストールする場合は以下です。

pip install -U elasticsearch-curator==X.Y.Z

Curatorの設定方法

Curator 5.4では
1. Curatorの設定
2. アクション(snapshot, delete等)の定義
の2つの設定ファイルが必要です。

注意点にも書きましたが、この2つの設定ファイルを用意するのはCurator 4.0以降の方法です。

Curatorの設定

x-packをインストールしている場合にはhttp_authの設定が必要です。

curator.yml
client:
  hosts:
    - 127.0.0.1
  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']

アクションの定義

アクションはどのアクションを行うのかとそのオプション、どのインデックスに実行するか、何日以前のデータに対して実行するかを定義します。

action.yml
actions:
# Snapshotを取得する
  1:
    action: snapshot
    description: >-
    options:
      repository: my_backup
      name: 'snapshot-%Y.%m.%d'
      include_global_state: True
      wait_for_completion: True
      max_wait: 3600
      wait_interval: 10
    filters:
    - filtertype: pattern
      kind: prefix
      value: myindex-
      exclude: False
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 1

# 30日以前のSnapshotを削除する
  2:
    action: delete_snapshots
    description: >-
    options:
      repository: my_backup
      retry_interval: 120
      retry_count: 3
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: myindex-
      exclude: False
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 30

# 30日以前のindexをdeleteする
  3:
    action: delete_indices
    description: "Delete selected indices"
    options:
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: myindex-
      exclude: False
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 30

Curatorを実行する

Curatorは以下のコマンドで実行できます。

curator --config /path/to/curator.yml /path/to/action.yml

実行すると以下のようなログが出力され、Snapshotの取得と削除、indexの削除が行われていることが分かります。

2017-12-07 00:05:23,150 INFO      Preparing Action ID: 1, "snapshot"
2017-12-07 00:05:23,185 INFO      Trying Action ID: 1, "snapshot":
2017-12-07 00:05:23,974 INFO      Creating snapshot "snapshot-2017.12.06" from indices:[
:
:
中略
:
:
2017-12-07 00:05:48,708 INFO      Action ID: 1, "snapshot" completed.
:
:
2017-12-07 00:06:09,407 INFO      ---deleting index myindex-2017.11.30
2017-12-07 00:06:11,756 INFO      Action ID: 3, "delete_indices" completed.
2017-12-07 00:06:11,756 INFO      Job completed.

おわりに

今回はElasticsearch 5.5に対して、Curator 5.4を適用し、Snapshotの取得、indexのDeleteを行う方法についてでした。
Advent CalendarはおろかQiitaへの投稿すら今回が初なので、至らぬ点等あると思いますがご容赦頂ければ幸いです。

3
3
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
3
3