Skip to content

Instantly share code, notes, and snippets.

@froop
Last active January 24, 2023 07:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froop/f229308cb12aa71dd09bf08f686cffa1 to your computer and use it in GitHub Desktop.
Save froop/f229308cb12aa71dd09bf08f686cffa1 to your computer and use it in GitHub Desktop.
[rsyslog] メッセージ出力のタイミングが遅延する

[rsyslog] メッセージ出力のタイミングが遅延する

事象

rsyslog パッケージの omfwd モジュールにより、TCP ベースの syslog 転送 1 が発生した際に、ソケットから制御が戻るまでの間、他のアクションでも出力が待たされる(最大で数分)。 例えば、デフォルトの /etc/rsyslog.conf の場合、下記ファイルへの出力が遅延する。

  • /var/log/messages
  • /var/log/secure
  • /var/log/maillog
  • /var/log/cron
  • /var/log/spooler
  • /var/log/boot.log

また、遅延している間に下記状況となった場合、メッセージが出力されないまま破棄される。

  • rsyslog サービスが停止
  • メインメッセージキューのサイズ($MainMsgQueueSize: デフォルト100000)を超過

場合によっては、入力側も詰まることがある模様。

rsyslogで処理が詰まらないようにする | たむたむの日記
https://blog.orz.at/2018/06/17/rsyslog/
Slow ssh while rsyslog forwarding system logs via TCP - Red Hat Customer Portal
https://access.redhat.com/solutions/1594173

発生条件

omfwd モジュールを使用して TCP 通信を行うアクションが、キューなし(デフォルトの $ActionQueueType Direct)の場合。 具体的には、/etc/rsyslog.conf に転送設定 1 のみを追加し、アクションキュー設定を追加していない場合。

特に影響が大きいのが、TCP 接続の確立要求(3 ウェイハンドシェイクの SYN パケット)に応答がなく、タイムアウトまで待機する場合。 RHEL7 のデフォルトでは、TCP接続確立のリトライは 6 回(net.ipv4.tcp_syn_retries = 6)のため、合計で 2 分強も遅延する。 なお、相手ホストが存在しない場合でも、ルータから ICMP(Type 3: destination unreachable)が返るならば発生しない。

原因

TCP転送アクション 1 にキューがないために、メッセージを非同期的に処理できず?、他アクションも巻き込まれる。

参考

第23章 ログファイルの表示と管理 Red Hat Enterprise Linux 7 | Red Hat Customer Portal
23.4. Rsyslog でのキュー (Queue) を使った操作
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-viewing_and_managing_log_files#s1-working_with_queues_in_rsyslog

対処方法

/etc/rsyslog.conf 2 への転送設定 1 の追加に合わせて、アクションキュー(例: $ActionQueueType LinkedList)も追加する。 /etc/rsyslog.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.
#$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
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###

Footnotes

  1. /etc/rsyslog.conf 2 のルール設定にて、出力先として "@@host:port" (先頭に「@」2つ)の形式で指定したもの。例えば *.* @@remote-host:514 2 3 4

  2. または /etc/rsyslog.d 配下のファイル 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment