同じサービスが開始されるたびにsystemdがシステムログに書き込むのを防ぐ

同じサービスが開始されるたびにsystemdがシステムログに書き込むのを防ぐ

30秒ごとに実行されるサービスがあります。このサービスのsystemdタイマーファイルは次のとおりです。

~# cat /etc/systemd/system/speed_check.timer
[Unit]
Description="Check device speed"

[Timer]
OnBootSec=1
OnUnitActiveSec=30

[Install]
WantedBy=multi-user.target

サービスファイルは単にPythonスクリプトを呼び出します。

# cat /etc/systemd/system/speed_check.service 
[Unit]
Description=Check device speed

[Service]
Type=simple
ExecStart=/usr/bin/check-speed

30秒ごとにsystemdがサービスを開始すると、2つのログが印刷されます。

Jan  8 17:54:23 localhost systemd[1]: Starting Check device speed...
Jan  8 17:54:23 localhost systemd[1]: Started Check device speed.

これらのメッセージを抑制する方法はありますか?彼らは私のシステムログを埋めています!

ありがとう

ベストアンサー1

いくつかの可能性があります。このファイルを構成する必要があります。/etc/systemd/journald.conf。マンページの2つの関連オプションは次のとおりです。

RateLimitInterval=、RateLimitBurst=

 Configures the rate limiting that is applied to all messages generated on the system. If, in the time interval
       defined by RateLimitInterval=, more messages than specified in RateLimitBurst= are logged by a service, all
       further messages within the interval are dropped until the interval is over. A message about the number of
       dropped messages is generated. This rate limiting is applied per-service, so that two services which log do not
       interfere with each other's limits. Defaults to 1000 messages in 30s. The time specification for
       RateLimitInterval= may be specified in the following units: "s", "min", "h", "ms", "us". To turn off any kind of
       rate limiting, set either value to 0.

そして

保存=

      Controls where to store journal data. One of "volatile", "persistent", "auto" and "none". If "volatile", journal
       log data will be stored only in memory, i.e. below the /run/log/journal hierarchy (which is created if needed).
       If "persistent", data will be stored preferably on disk, i.e. below the /var/log/journal hierarchy (which is
       created if needed), with a fallback to /run/log/journal (which is created if needed), during early boot and if
       the disk is not writable.  "auto" is similar to "persistent" but the directory /var/log/journal is not created if
       needed, so that its existence controls where log data goes.  "none" turns off all storage, all log data received
       will be dropped. Forwarding to other targets, such as the console, the kernel log buffer or a syslog daemon will
       still work however. Defaults to "auto".

したがって、次の方法ですべてのシステムログをオフにできます。保存スペース=なししかし、これは過度で賢明ではないようです。制限速度(最初のオプション=より合理的です。デフォルトは30秒あたり1000メッセージです。これは予想よりはるかに多くの数値であり、選択しなかった出力がそれほど多くの理由を説明します。

または、次のいずれかのオプションを使用できます。

   SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=, RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize=

保存されるログファイルのサイズを制御します。これらのオプションを次のいずれかに関連付けることができます。

最大安全ファイル数=

      The maximum time to store entries in a single journal file before rotating to the next one

最大保存時間(秒)=

      The maximum time to store journal entries.

すべてのsyslogメッセージをアーカイブしますが、短期間保存します。

最後に、次のものを使用できます。

MaxLevelStore=、MaxLevelSyslog=、MaxLevelKMsg=、MaxLevelConsole=、MaxLevelWall=

      Controls the maximum log level of messages that are stored on disk, forwarded to syslog, kmsg, the console or
       wall (if that is enabled, see above). As argument, takes one of "emerg", "alert", "crit", "err", "warning",
       "notice", "info", "debug" or integer values in the range of 0..7 (corresponding to the same levels). Messages
       equal or below the log level specified are stored/forwarded, messages above are dropped. Defaults to "debug" for
       MaxLevelStore= and MaxLevelSyslog=, to ensure that the all messages are written to disk and forwarded to syslog.
       Defaults to "notice" for MaxLevelKMsg=, "info" for MaxLevelConsole= and "emerg" for MaxLevelWall=.

あまり重要ではないメッセージは捨てて、重要なメッセージのみを保管してください。

おすすめ記事