LoginSignup
8
7

More than 5 years have passed since last update.

rsyslogでLogをremoteに転送するdisk queueが溜まってしまって吐き出されない時の対処法

Last updated at Posted at 2016-01-07

はじめに

rsyslog でログをRemoteのログサーバに転送したいときに、RemoteのログサーバがDownしていた時に備えて、Local DISK上のQueueを利用する設定をしておくことはよく行うと思います。
ただ、その際にDISK上にQueueされたログデータが復帰時に転送されないことがあり、その際の対処法のメモです。

環境・Version

  • OS: Amazon Linux 2013.03 に色々updateをしたVersion
  • rsyslogd: 5.8.10

転送の設定(参考)

/var/lib/rsyslog がQueueに使うDir, QueueName は local1 になります。

/etc/rsyslog.d/00-local1.conf
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName local1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 10g   # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList   # run asynchronously
$ActionResumeRetryCount -1    # infinite retries if host is down
local1.*        @@any-remote-server:514
# ### end of the forwarding rule ###

症状

  • /var/lib/rsyslog/local1.nnnnnnnn(nは数字) というファイルが大量にある。
  • remote サーバは復帰しているが、localのrsyslogが転送している様子はない
  • rsyslogを何度再起動しても再送してくれない

主な原因

rsyslogはremoteにログを転送する際に QueueIndex ファイルを作るようです。
/var/lib/rsyslog/local1.qi というファイル名になりますが、
これが存在しないか内容がおかしいと再送しないようです。

対処

主な対処

QueueIndexファイルを作成する perl scriptがあるので、それを使うと上手くいきました。
こんな感じになります。

sudo su -   
curl -O https://gist.githubusercontent.com/wilrnh/9373137/raw/dfa4ddb5bca5f5114ca0367055aa0521e318c7e1/recover_qi.pl
perl recover_qi.pl -w /var/lib/rsyslog/ -f local1 -d 8 > local1.qi
cp local1.qi /var/lib/rsyslog
service rsyslog restart  # もしくは /etc/init.d/rsyslog restart

このように queue index ファイルをQueueDirに置いてから、rsyslog を restartさせると再送してくれます。

例外1: 謎の空のqueueファイルができてしまう

この時は厄介なのですが、

  1. /etc/rsyslog.d/00-local1.conf で LogDir を別の存在するDIRに変更してrsyslog再起動
  2. もう一度DIRを元に戻してrsyslog再起動
  3. 空のQueueファイルを削除して、もう一度 Queue indexファイルを作成して rsyslog再起動
  4. なんかもう一回rsyslog再起動

などでなおりました(謎)。

サーバの再起動ができるなら、それでも治るかもしれません。

例外2: Queueファイルが1つだけ残ってしまった

もう一度、QueueIndexファイルを作って rsyslog restart すると消えました。

さいごに

bug reportっぽいものもあがっており、古いrsyslogだからかもしれませんが、厄介な問題です。。

8
7
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
8
7