LoginSignup
14
15

More than 5 years have passed since last update.

CentOSにfluentdを入れてapacheログをfluentdのログファイルに書き出してみた。

Posted at

fluentdインストール

RPMパッケージでインストール
rpmパッケージからFluentdをインストールする | Fluentd

手順通り。

インストール後使えるようになるサービス

/etc/init.d/td-agent

start, stop, status, restartできる。
設定ファイル直したら/etc/init.d/td-agent restartする。

設定ファイルの場所

  • /etc/td-agent/td-agent.conf

fluentd設定

$ vi /etc/td-agent/td-agent.conf

apacheログファイル読み込む

apacheの設定例は設定ファイルの下の方にコメントアウトされている。

<source>
  type tail
  format apache
  path /var/log/httpd/access_log
  pos_file /var/log/td-agent/access.pos
  tag apache.access
</source>

td-agentの元設定ファイルからの注意点

pos_fileを追加すること

5行目のpos_fileがないと、td-agent起動時にワーニングがでる。

'pos_file PATH' parameter is not set to a 'tail' source.
this parameter is highly recommended to save the position to resume tailing.
tagを変えた方が良いかも

最初の状態だと、tag td.apache.accessのようになっている。
これだと、この後の普通にファイルに出力する際に別のターゲットにマッチしてしまうらしく、ファイルに出てこない。。(これでしばらくハマった・・)

apacheログファイルをtd-agentで読めるようにする

apacheログファイルのパーミッション設定を変える。
ファイルが読めない権限の場合、/var/log/td-agent/td-agent.logにエラーが書きこまれる。

# chmod o+rx /var/log/httpd/access_log

読み込んだログをfluentdのログファイルとして書き出す

$ vi /etc/td-agent/td-agent.conf

またもや設定ファイルを直す。さっきapacheログ読み込みを書いたsourceの下にでも追記。

<match apache.access>
  type file
  path /var/log/td-agent/access
</match>

tag変えた方が良いかも、で変えてない場合、td.apache.accessにすると、設定ファイルの上の方に書かれているtd.*に持ってかれてるっぽい。

14
15
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
14
15