LoginSignup
16

More than 5 years have passed since last update.

fluentd インストール

Last updated at Posted at 2016-02-16

メモ:fluentdでログ集約

※関連記事:
http://qiita.com/ohayougenki/items/4add0d5afdc91a3a441d

環境

EC2(A):CentOS 6.5 ※こっちからログを送る
EC2(B):CentOS 6.5 ※こっちへログを集約する 

前提

1)apacheがログ収集元サーバにインストールされていること
2)ruby 1.9.2以上
※Treasure Data(fluentdの開発元)がRHEL互換環境にfluentdをインストールできるシェルを用意してくれている。
詳しくは:http://docs.fluentd.org/articles/install-by-rpm

3)fluentdではTCP/UDPともに使用する(SGで許可)
※今回は24224のTCP/UDP
※TCPでファイルを送り、UDPで死活の確認

4)今回は検証だったので、iptablesは停止しています。

インストール

EC2(A)(B)共に

install
#curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
#sudo /etc/init.d/td-agent start
#sudo /etc/init.d/td-agent status

基本的な要素は3つ
source,
match,
include

今回使うのは
sourceとmatchだけ。

設定ファイル

まずは、送信元「EC2(A)」の設定を行う。
1)apacheログの操作権限付与
2)td-agent.confの設定

[root@FluentdAgent ~]# chmod o+x /var/log/httpd
[root@FluentdAgent ~]# vi /etc/td-agent/td-agent.conf
<source>
  type tail
  path /var/log/httpd/access_log
  tag apache.access
  pos_file /var/log/td-agent/access_log.pos
  format apache2
</source>

#<match apache.access>
#  type file
#  path /var/log/td-agent/httpd/access.log
#  time_slice_format %Y%m%d
#  time_slice_wait 10m
#  compress gzip
#</match>

<match apache.access>
  type forward
  <server>
    name サーバ名
    host XXX.XXX.XXX.XXX
    port 24224
  </server>
</match>

次に集約サーバ「EC2(B)」側の設定を行う
1)td-agent.confの設定

[root@fluentdManager httpd]# cat /etc/td-agent/td-agent.conf
<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>

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

こんな感じでログ出力される。

[root@fluentdManager httpd]# pwd
/var/log/td-agent/collect/httpd
[root@fluentdManager httpd]# ls -la
total 12
drwxr-xr-x. 2 td-agent td-agent 4096 Feb 16 05:16 .
drwxr-xr-x. 3 td-agent td-agent 4096 Feb 16 04:39 ..
-rw-r--r--. 1 td-agent td-agent  858 Feb 16 05:16 access.log.20160216.b52bdc3bd93ae658d

以上メモでした。

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
16