LoginSignup
7
9

More than 5 years have passed since last update.

curator 4.1.1 で Elasticsearchにたまったlogstashのログを消すメモ

Last updated at Posted at 2016-10-05

Logstashのログが気付いたらめちゃんこ溜まってたので処理したときのメモ

こちらの記事を見つけて、 curatorを使わざるを得ない 
と思ったけどいろいろ変わってて泣いたのでまとめました。

環境

CentOS 7.2

インストール

自分は yum を使いたかったので、公式を参考に設定した。
Curator 4.1 Instration

# /etc/repo.d/curator.repo を作成 編集
[curator-4]
name=CentOS/RHEL 7 repository for Elasticsearch Curator 4.x packages
baseurl=http://packages.elastic.co/curator/4/centos/7
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

で、 yum install

sudo yum install python-elasticsearch-curator

設定ファイルの作成

したいこと
- localhost:9200 のElasticsearchへ接続
- logstash で始まるindex の削除
- 過去30日分だけ残す

configファイルの作成

curator を実行するユーザーの ~/.curator/ ディレクトリに curator.yml を作成
別の場所に作っても、パス指定できるので問題ない。

公式を参考に...
Curator4.1 Configuration

### ~/.curator/curator.yml
client:
  hosts:
    - localhost # 接続先IP かホスト名
  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ファイルの作成

やりたいことの設定ファイルを作成 今回はindexを消したい

場所はどこでもいいです。 私は設定ファイルと同じ場所に置きました
ファイル名は適当に、 delete_indices_30_days にしました

公式のサンプルを参考に...
Curator Examples

### ~/.curator/delete_indices_30_days

# Remember, leave a key empty if there is no value.  None will be a string,
# not a Python "NoneType"
#
# Also remember that all examples have 'disable_action' set to True.  If you
# want to use this action as a template, be sure to set this to False after
# copying it.
actions:
  1:
    action: delete_indices
    description: >-
      Delete indices older than 45 days (based on index name), for logstash-
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.
    options:
      ignore_empty_list: True
      timeout_override:
      continue_if_exception: False
      disable_action: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: logstash-
      exclude:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 30 #何日前まで残すか
      exclude:

このままだと実行できないので、
"disable_action: True" を False にします。

実行

# 設定ファイルを ~/.curator/curator.yml に作った場合
$ curator ~/.curator/delete_indices_30_days

# 設定ファイルを それ以外の場所に作った場合
$ curator --config /path/to/curatoy.yml  ~/.curator/delete_indices_30_days

いけました! ではでは

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