fluentdを使いはじめたのですが、apacheログを別のサーバーへ転送させてみてる場合、apacheログがローテーションされてもちゃんとローテーションされるのか検証してみました。(とっても初心者なのでこんな検証からやりはじめてます。。。)

環境

  • Vagrantで稼働しているCentOS6のサーバー2台
  • 送信元が192.168.33.10、受信側が192.168.33.11

送信元のtd-agent.conf

<source>
type tail
path /var/log/httpd/*access_log
pos_file /var/log/td-agent/access_log.pos
tag httpd.access
format apache2
</source>
<match httpd.*>
type forward
<server>
host 192.168.33.11
</server>
</match>

受信側のtd-agent.conf

<source>
type forward
</source>
<match httpd.*>
type copy
<store>
type file
path /var/log/td-agent/web01/httpd_access.log
</store>
</match>

検証

送信元のapacheログを強制的にローテーション。

# logrotate -f /etc/logrotate.d/httpd

するとtd-agent.logには下記のようなinfoログが吐かれます。

2015-11-07 18:47:42 +0900 [info]: detected rotation of /var/log/httpd/stage.example.com-access_log; waiting 5 seconds
2015-11-07 18:47:42 +0900 [info]: ected rotation of /var/log/httpd/www.example.com-access_log; waiting 5 seconds
2015-11-07 18:47:43 +0900 [info]: following tail of /var/log/httpd/www.example.com-access_log
2015-11-07 18:47:43 +0900 [info]: following tail of /var/log/httpd/stage.example.com-access_log

apacheログが正しくローテーションされたのを確認して、この状態で再度Webへアクセスしてみても、正常にログが転送されているのが確認できます。

では、送信元のポジションログや、受信側の転送されたログはいつローテーションされるのか?

これは単純に/etc/logrotate.d/td-agentのローテーションに伴って実行されるようです。

ためしにlogrotateを強制的に実施してみます。

実施前

-rw-r–r– 1 td-agent td-agent 214 11月 7 19:05 2015 access_log.pos
drwxr-xr-x 2 td-agent td-agent 4096 11月 5 18:22 2015 buffer
-rw-r–r– 1 td-agent td-agent 68372 11月 7 18:47 2015 td-agent.log

実施後

# logrotate -f /etc/logrotate.d/td-agent

-rw-r–r– 1 td-agent td-agent 214 11月 7 19:05 2015 access_log.pos
drwxr-xr-x 2 td-agent td-agent 4096 11月 5 18:22 2015 buffer
-rw-r—– 1 td-agent td-agent 0 11月 7 19:08 2015 td-agent.log
-rw-r–r– 1 td-agent td-agent 68437 11月 7 19:08 2015 td-agent.log.1

この状態で再度ウェブサイトへアクセスしてみましたが、どうやらポジションログはローテーションされないようです。

特に容量が常に増えていくようなものでも無いようなので、それはまぁそうかって感じですね。

ただ、受信側でlogorotateを強制的に実施したとこと、転送されたアクセスログが下記のようにローテーションされておりました。

# ls -l web01/
合計 12
-rw-r–r– 1 td-agent td-agent 2506 11月 7 19:09 2015 httpd_access.log.20151107.b523f0819dd082f13
-rw-r–r– 1 td-agent td-agent 5089 11月 7 19:05 2015 httpd_access.log.20151107_0.log

以上から、転送されたアクセスログのローテーションは通常のlogrotateの設定を参照して、必要でであればそこで変更すると良さそうです。(容量が多すぎてしまう場合は、ログの容量を指定して実行させていくのもありでしょうか)

以上

 

カテゴリー: LinuxTech