ログに Created slice、Starting Session、Starting User Manager、Reached target の systemd メッセージが大量に記録される
Environment
- Red Hat Enterprise Linux 7
- rsyslog
- Red Hat Enterprise Linux 8 以降
- rsyslog
systemd --user
Issue
-
新しくインストールしたシステムで、
/var/log/messagesと journal に次のイベントが常に表示されます。RHEL 7 の場合
Jul 24 08:50:01 example.com systemd: Created slice user-0.slice. Jul 24 08:50:01 example.com systemd: Starting Session 150 of user root. Jul 24 08:50:01 example.com systemd: Started Session 150 of user root. Jul 24 09:00:01 example.com systemd: Created slice user-0.slice. Jul 24 09:00:02 example.com systemd: Starting Session 151 of user root. Jul 24 09:00:02 example.com systemd: Started Session 151 of user root.RHEL 8 以降の場合
Dec 01 14:14:18 r96 systemd[1]: Starting User Manager for UID 1000... Dec 01 14:14:18 r96 systemd[22233]: pam_unix(systemd-user:session): session opened for user user(uid=1000) by user(uid=0) Dec 01 14:14:18 r96 systemd[22233]: Queued start job for default target Main User Target. Dec 01 14:14:18 r96 systemd[22233]: Created slice User Application Slice. Dec 01 14:14:18 r96 systemd[22233]: Started Mark boot as successful after the user session has run 2 minutes. Dec 01 14:14:18 r96 systemd[22233]: Started Daily Cleanup of User's Temporary Directories. Dec 01 14:14:18 r96 systemd[22233]: Reached target Paths. Dec 01 14:14:18 r96 systemd[22233]: Reached target Timers. Dec 01 14:14:18 r96 systemd[22233]: Starting D-Bus User Message Bus Socket... Dec 01 14:14:18 r96 systemd[22233]: Starting Create User's Volatile Files and Directories... Dec 01 14:14:18 r96 systemd[22233]: Listening on D-Bus User Message Bus Socket. Dec 01 14:14:18 r96 systemd[22233]: Reached target Sockets. Dec 01 14:14:18 r96 systemd[22233]: Finished Create User's Volatile Files and Directories. Dec 01 14:14:18 r96 systemd[22233]: Reached target Basic System. Dec 01 14:14:18 r96 systemd[22233]: Reached target Main User Target. Dec 01 14:14:18 r96 systemd[22233]: Startup finished in 83ms. Dec 01 14:14:18 r96 systemd[1]: Started User Manager for UID 1000. Dec 01 14:15:39 r96 systemd[22233]: Activating special unit Exit the Session... Dec 01 14:15:39 r96 systemd[22233]: Stopped target Main User Target. Dec 01 14:15:39 r96 systemd[22233]: Stopped target Basic System. Dec 01 14:15:39 r96 systemd[22233]: Stopped target Paths. Dec 01 14:15:39 r96 systemd[22233]: Stopped target Sockets. Dec 01 14:15:39 r96 systemd[22233]: Stopped target Timers. Dec 01 14:15:39 r96 systemd[22233]: Stopped Mark boot as successful after the user session has run 2 minutes. Dec 01 14:15:39 r96 systemd[22233]: Stopped Daily Cleanup of User's Temporary Directories. Dec 01 14:15:39 r96 systemd[22233]: Closed D-Bus User Message Bus Socket. Dec 01 14:15:39 r96 systemd[22233]: Stopped Create User's Volatile Files and Directories. Dec 01 14:15:39 r96 systemd[22233]: Removed slice User Application Slice. Dec 01 14:15:39 r96 systemd[22233]: Reached target Shutdown. Dec 01 14:15:39 r96 systemd[22233]: Finished Exit the Session. Dec 01 14:15:39 r96 systemd[22233]: Reached target Exit the Session. Dec 01 14:15:39 r96 systemd[1]: Stopping User Manager for UID 1000... Dec 01 14:15:39 r96 systemd[1]: user@1000.service: Deactivated successfully. Dec 01 14:15:39 r96 systemd[1]: Stopped User Manager for UID 1000.
Resolution
rsyslogd がこれらのログを記録しないようにする方法
-
RHEL 7 の場合、
rsyslog.d/ドロップイン設定ファイルに、以下の例のような破棄フィルターを作成します。# vi /etc/rsyslog.d/0-ignore-systemd-session-slice.conf if $programname == "systemd" and ($msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Created slice" or $msg contains "Starting user-" or $msg contains "Starting User Slice of" or $msg contains "Removed session" or $msg contains "Removed slice User Slice of" or $msg contains "Stopping User Slice of") then stop -
RHEL 8 以降の場合、以下のような 2 つの破棄フィルターが含まれる
rsyslog.d/ドロップイン設定ファイルを作成します。# vi /etc/rsyslog.d/0-ignore-systemd-session-slice.conf if $programname == "systemd" and ($msg contains "User Manager for UID" or $msg contains "user@" or $msg contains "run-user-" or $msg contains "user-runtime-dir@" or $msg contains "slice User Slice of UID" or $msg contains "User runtime directory /run/user/" ) then stop if ($programname == "systemd" and $procid != "1") and ( $msg contains "slice User Application Slice" or $msg contains "Queued start job for default target Main User Target" or $msg contains "Mark boot as successful after the user" or $msg contains "Daily Cleanup of User's Temporary Directories" or $msg contains "D-Bus User Message Bus Socket" or $msg contains "Create User's Volatile Files and Directories" or $msg contains "Exit the Session" or $msg contains "Reached target" or $msg contains "Stopped target" or $msg contains "Startup finished in" ) then stop続いて、rsyslog サービスを再起動します。
# systemctl restart rsyslog注記:フィルターがローカル syslog ロギング (
/var/log/messages) に対してのみ機能し、リモート syslog サーバーに対しては機能しない場合は、syslog イベントがリモート syslog サーバーに送信された後にこのルールが読み取られることがわかります。これを回避するには、rsyslog.conf のリモート syslog 転送設定の行の上にルールを直接追加します。(*.* @logcollector:514 server)
systemd --user がこれらのログを記録しないようにする方法
-
RHEL 8 以降では、
systemd --userセッションレベルで生成されたユーザーアクティビティーをログに記録しないようにできます。オプション 1
-
ユーザーのリンガリングを有効にして、ユーザーにアクティブなセッションがない場合でも
systemd --userインスタンスの実行が継続されるようにします (セッションが終了されないため、ログは 1 回だけ表示されます)。# loginctl enable-linger testuser
オプション 2
-
ユーザーの systemd ユーザーマネージャーのロギングを制限し、"1000" をユーザーの実際の
UIDに変更します (この特定のユーザーのロギングが影響を受けます)。# mkdir /etc/systemd/system/user@1000.service.d # cat > /etc/systemd/system/user@1000.service.d/logging.conf <<EOF [Service] LogLevelMax=notice EOF
オプション 3
-
systemd ユーザーマネージャーのロギングをグローバルに制限します (すべてのユーザーのロギングが影響を受けます)。
# sed -i -e 's/#LogLevel=info/LogLevel=notice/' /etc/systemd/user.conf
WARNING:最後の 2 つの方法は、
notice以上のイベントを生成しないユーザーセッション内で実行されたすべてのロギングを阻害します。 -
Root Cause
- これらのメッセージは正常かつ予期されるものであり、ユーザーがログインまたはログアウトするたびに表示されます (例: ユーザーに対して
cronジョブが実行されたとき)。 - RHEL 8 以降では、ユーザーのスライスが作成された systemd ユーザーインスタンスが自動的に生成されると (
systemd --user)、このようなメッセージが生成されます。 - systemd(1) システムマネージャー (PID 1) は、ユーザーの数値
UIDをユニット識別子として使用して、ユーザーマネージャーインスタンスをuser@UID.serviceとして生成します。このインスタンスはシステムマネージャーと同じプロセス名を使用しますが、別のユニットセットを開始するモードで実行されます。各systemd --userインスタンスは、default.targetから始まる、そのユーザーに固有のユニットの階層を管理します。
Diagnostic Steps
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments