rsyslogで中継サーバ経由してログ送信を行う【cloudpack 大阪 BLOG】

以下のような構成でrsyslogを使用してログをログ収集サーバへ集約させる要件がありました。
検証で動作確認を実施してみたので、備忘録としてやり方を残しておきたいと思います。

f:id:cloudfish:20170126190943p:plain,w400,h250

やりたいこと

webサーバの/var/log/messagesをログ中継サーバを経由させてログ収集サーバへ送信する
ユースケースとしてはログ収集サーバが別のVPCや外部DCにあるケースを想定しています。

構成

サーバ IP
webサーバ 172.31.0.1
中継サーバ 172.31.0.2
ログ収集サーバ 172.31.0.3

webサーバの設定

■/etc/rsyslog.config

*.info;mail.none;authpriv.none;cron.none                /var/log/messages
*.info;mail.none;authpriv.none;cron.none                @@172.31.02      ←追加

# 以下コメントを解除(73-78行目)
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName fwdRule1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g   # 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

中継サーバの設定

■/etc/rsyslog.config

# 以下コメントを解除
$ModLoad imtcp
$InputTCPServerRun 514

$AllowedSender TCP, 127.0.0.1, 172.31.0.0/24   ←送信元を指定

*.info;mail.none;authpriv.none;cron.none                /var/log/messages
*.info;mail.none;authpriv.none;cron.none                @@172.31.03       ←追加

#コメントを解除(73-78行目)
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName fwdRule1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g   # 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

ログ収集サーバの設定

■/etc/rsyslog.config

# 以下コメントを解除
$ModLoad imtcp
$InputTCPServerRun 514

$AllowedSender TCP, 127.0.0.1, 172.31.0.0/24   ←送信元を指定

#フォーマット指定
$template message_log,"/var/log/message.d/%fromhost%_%$year%%$month%%$day%.log"   ←追加
*.info;mail.none;authpriv.none;cron.none     -?message_log             ←追加

上記設定後にwebサーバでmessagesにログを出力し、ログ収集サーバに転送されていれば正常に設定されています。

logger logtest