LoginSignup
20
17

More than 5 years have passed since last update.

Fluentd入門

Posted at

インストール

$ curl -L http://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

起動

# systemctl start td-agent.service
# chkconfig td-agent on

再起動

# systemctl restart td-agent.service

とりあえず、動作テスト

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

<source>
  type forward
  port 24224
</source>

<match *.*>
  type stdout
</match>
$ echo '{"message": "Hello World!"}' | /opt/td-agent/embedded/bin/fluent-cat debug.test
# tail /var/log/td-agent/td-agent.log

apacheのアクセスログを収集するように設定

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

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

Permissionが足りないくてapacheのアクセスログが読めない場合

/var/log/td-agent/td-agent.log に

Permission denied @ rb_sysopen - /var/log/httpd/access_log

のエラーが出たら

# vi /etc/init.d/td-agent

- DAEMON_ARGS=${DAEMON_ARGS---user td-agent}
+ DAEMON_ARGS=${DAEMON_ARGS---user root}
TD_AGENT_ARGS="${TD_AGENT_ARGS-/usr/sbin/td-agent --user root --group td-agent --log /var/log/td-agent/td-agent.log}"

Elasticsearchへ転送する設定

Elasticsearch用プラグインインストール

# /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-elasticsearch

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

<match apache.*>
  type elasticsearch
  logstash_format true
  logstash_prefix apache_log
  hosts localhost:9200
  type_name apache-access-log
  buffer_type memory
  buffer_chunk_limit 1m
  buffer_queue_limit 128
  flush_interval 2s
  retry_limit 17
</match>
  1. タグ「apache.access」がマッチするので、
  2. elasticsearchに
  3. logstashフォーマットした「apache_log.ymd」のインデックスで、
  4. localhost:9200のelasticsearchに
  5. タイプ「apache-access-log」で送信する感じ。
20
17
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
20
17