インストール
$ 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>
- タグ「apache.access」がマッチするので、
- elasticsearchに
- logstashフォーマットした「apache_log.ymd」のインデックスで、
- localhost:9200のelasticsearchに
- タイプ「apache-access-log」で送信する感じ。