LoginSignup
18
18

More than 5 years have passed since last update.

Raspberry Pi に fluentd をインストールする

Posted at

Raspberry Pi (raspbian) に fluentd をインストールして upstart で自動起動するように設定する。

fluentd 事前設定

Fluentdインストールの前に | Fluentd に従って設定する。

ファイルディスクリプタの設定

ファイルディスクリプタを確認する。

Pi
$ ulimit -n
1024

/etc/security/limits.conf に以下を追加して 1024 から 65536 に変更する。

/etc/security/limits.conf
root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536

再起動して反映させる。

fluend インストール

Raspbian デフォルトの ruby-1.9.3 を使って gem 版をインストールする。
C で書かれている部分があるせいか、ruby-dev も必要な模様。

Pi
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [arm-linux-eabihf]
$ sudo apt-get install ruby-dev
$ sudo gem install fluentd --no-ri --no-rdoc

動作確認する。

Pi
$ fluentd --setup ./fluent
$ fluentd -c ./fluent/fluent.conf -vv &
$ echo '{"json":"message"}' | fluent-cat debug.test

fluentd の標準出力に debug.test: {"json":"message"} が表示されればOK。

fluentd 自動実行設定

今回は upstart を使ってみる。

upstart インストール

Pi
$ sudo apt-get install upstart

sysvinit を削除するので確認メッセージがでるが指示どおりにタイプする。
インストールできたらシステムを再起動する。

fluentd セットアップ

/etc/fluent に fluentd の設定ファイルを置く。

Pi
$ sudo mkdir /etc/fluent
$ sudo fluentd --setup /etc/fluent
Installed /etc/fluent/fluent.conf.

fluentd 用のユーザとグループを作成する。

Pi
$ sudo groupadd fluentd
$ sudo useradd -g fluentd -s /bin/false -M fluentd

fluentd 用 upstart 設定ファイル作成

/etc/init/fluentd.conf を以下のようにする。

/etc/init/fluentd.conf
description "fluentd upstart script"

start on (local-filesystem and net-device-up)
stop  on shutdown

respawn
respawn limit 5 60

script
  exec sudo -u fluentd /usr/local/bin/fluentd -c /etc/fluent/fluent.conf
end script

fluentd 起動

Pi
$ sudo start fluentd

fluentd の起動確認と動作確認をしておく。

Pi
$ sudo status fluentd
fluentd start/running, process 1318
$ echo '{"json":"message"}' | fluent-cat debug.test
$ sudo tail -f /var/log/upstart/fluentd.log

/var/log/upstart/fluentd.log が fluentd の標準出力になっている模様。
debug.test: {"json":"message"} が出力されていればOK。

参考

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