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に飛ばしてくれない