LoginSignup
0
1

More than 5 years have passed since last update.

【Fluentd】Ubuntu14.04でFluentdを動かしNginxのアクセスログを出すところまで

Last updated at Posted at 2016-11-14

Fluentdの初歩の初歩。

環境

Ubuntu14.04 trusty

インストール

公式ページのInstallationから使うUbuntuのバージョンのコマンドを見つけて実行。
今回は14.04なので以下を実行する。

$curl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent2.sh | sh

起動確認

インストールが完了したら起動してるか確認する

sudo apt-get update
sudo apt-get install nginx
$sudo service nginx status
 * nginx is running

td-agent.confの設定

一旦インストール時の設定を全て消す(サンプルの設定がエラー吐くので)

nginxのaccess.logをtailして標準出力に出す。

<source>
  type tail
  path /var/log/nginx/access.log
  pos_file /var/log/td-agent/nginx-access.pos
  format /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<forwarder>[^\"]*)")?/
  time_format %d/%b/%Y:%H:%M:%S %z
  tag nginx.access
</source>

<match nginx.access>
  @type stdout
</match>

td-agentを再起動する

sudo service td-agent restart

td-agentに/var/log/nginx/access.logのPermissionがないので/var/log/td-agent.logにエラーログが流れた。

2016-11-14 16:57:08 +0000 [error]: Permission denied @ rb_sysopen - /var/log/nginx/access.log
  2016-11-14 16:57:08 +0000 [error]: suppressed same stacktrace

td-agentの実行ユーザーを変える

/etc/init.d/td-agentにtd-agentの実行ユーザーを変更する設定があるので思い切ってrootにする。

$ sudo vim /etc/init.d/td-agent
TD_AGENT_USER=root
TD_AGENT_GROUP=root

実行確認

再起動する。

sudo service td-agent restart

nginxにアクセスする度に/var/log/td-agent/td-agent.logにログが出力されるようになった!

vagrant@vagrant-ubuntu-trusty-64:~$ sudo tail -f /var/log/td-agent/td-agent.log
2016-11-14 17:02:05 +0000 nginx.access: {"remote":"192.168.33.1","host":"-","user":"-","method":"GET","path":"/","code":"304","size":"0"}
2016-11-14 17:02:14 +0000 nginx.access: {"remote":"192.168.33.1","host":"-","user":"-","method":"GET","path":"/","code":"304","size":"0"}
2016-11-14 17:04:03 +0000 nginx.access: {"remote":"192.168.33.1","host":"-","user":"-","method":"GET","path":"/","code":"304","size":"0"}
0
1
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
0
1