0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FluentdでS3にログをアップする

Posted at

Fluentdのインストール

$ sudo curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
$ sudo td-agent-gem install fluent-plugin-config-expander fluent-plugin-tail-asis fluent-plugin-file-alternative fluent-plugin-forest

$ sudo mkdir /var/log/td-agent/pos
$ sudo mkdir /var/log/td-agent/buffer
$ sudo chown -R td-agent. /var/log/td-agent

conf設定

$ sudo vi /etc/td-agent/td-agent.conf
--------------------------------------------------------------------------------
<source>
  type config_expander
  <config>
    type tail
    format none
    path /var/log/ec2-user/XXXX.log
    pos_file /var/log/td-agent/pos/XXXX.pos
    tag api_${hostname}/XXXX
  </config>
</source>

<source>
  type config_expander
  <config>
    type tail
    format none
    path /var/log/ec2-user/XXXX.log
    pos_file /var/log/td-agent/pos/XXXX.pos
    tag api_${hostname}/XXXX
  </config>
</source>

<match *.**>
  type forest
  subtype s3
   <template>
    aws_key_id XXXX
    aws_sec_key XXXX
    s3_bucket XXXX
    s3_region ap-northeast-1

    path
    buffer_path /var/log/td-agent/buffer/${tag}
    time_slice_format %Y/%m/%d/${tag}/ec2-%Y-%m-%d-%H
    retry_wait 30s
    retry_limit 5
    flush_interval 1h
    flush_at_shutdown true
   </template>
</match>

起動と自動起動

$ sudo /etc/init.d/td-agent start
$ sudo chkconfig td-agent on

リブート時のfuluentdの実行

$ sudo crontab -e
--------------------------------------------------------------------------------
@reboot /bin/bash -lc '/etc/init.d/td-agent restart 1>/tmp/td-agent-restart.log 2>&1'

つまづいた事

fluent-plugin-tail-asis(type tail_asis)を使用していたが下記のようなエラーが発生し起動できない。解決策は見つからず。tailに変更した。

  • uninitialized constant Fluent::TailInput (NameError)
  • dry run failed: uninitialized constant Fluent::TailInput

未解決

@reboot時にfluentdがログをS3に飛ばしてくれない

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?