Systemd

SystemD JournalD 無法禁用子程序輸出

  • April 3, 2022

我在帶有核心 5.10.50 的自定義嵌入式 Linux 設備上執行 SystemD 版本 249.7+。我正在使用 Podman 4.0.2 和 Docker-Compose 來執行一些容器。我遇到的問題是 podman 系統服務中的“conmon”子程序複製了 docker-compose 程序生成的每個日誌日誌條目。我想刪除日誌條目的普通版本,只保留 docker-compose 生成的日誌條目。

Journalctl 顯示重複的條目,如下所示:

-- Journal begins at Sun 2012-01-01 00:02:21 UTC. --
Mar 30 17:06:15 device conmon[1625]: {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:16 device sh[16648]: app1  | App1 endpoint hit ...
Mar 30 17:06:16 device sh[16648]: app3  | {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:16 device sh[16648]: app2  | App2 endpoint hit ...
Mar 30 17:06:16 device sh[16648]: app1  | 10.89.0.3 - - [30/Mar/2022 17:06:15] "GET / HTTP/1.1" 200 -
Mar 30 17:06:16 device sh[16648]: app2  | Getting http://app1 ...
Mar 30 17:06:16 device sh[16648]: app2  | Status of GET: 200
Mar 30 17:06:16 device sh[16648]: app2  | Results of GET: {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:16 device sh[16648]: app2  |
Mar 30 17:06:16 device sh[16648]: app2  | 10.89.0.4 - - [30/Mar/2022 17:06:15] "GET / HTTP/1.1" 200 -
Mar 30 17:06:21 device conmon[1558]: App2 endpoint hit ...
Mar 30 17:06:21 device conmon[1558]: Getting http://app1 ...
Mar 30 17:06:22 device sh[16648]: app1  | App1 endpoint hit ...
Mar 30 17:06:22 device sh[16648]: app2  | App2 endpoint hit ...
Mar 30 17:06:22 device sh[16648]: app1  | 10.89.0.3 - - [30/Mar/2022 17:06:22] "GET / HTTP/1.1" 200 -
Mar 30 17:06:22 device sh[16648]: app3  | {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:22 device sh[16648]: app2  | Getting http://app1 ...
Mar 30 17:06:22 device sh[16648]: app2  | Status of GET: 200
Mar 30 17:06:22 device sh[16648]: app2  | Results of GET: {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:22 device sh[16648]: app2  |
Mar 30 17:06:22 device sh[16648]: app2  | 10.89.0.4 - - [30/Mar/2022 17:06:22] "GET / HTTP/1.1" 200 -
Mar 30 17:06:22 device conmon[1393]: App1 endpoint hit ...
Mar 30 17:06:22 device conmon[1393]: 
Mar 30 17:06:22 device conmon[1393]: 10.89.0.3 - - [30/Mar/2022 17:06:22] "GET / HTTP/1.1" 200 -
Mar 30 17:06:22 device conmon[1558]: Status of GET: 200
Mar 30 17:06:22 device conmon[1558]: 
Mar 30 17:06:22 device conmon[1558]: Results of GET: {"products":["Linux","Windows","Mac"]}
Mar 30 17:06:22 device conmon[1558]: 
Mar 30 17:06:22 device conmon[1558]: 10.89.0.4 - - [30/Mar/2022 17:06:22] "GET / HTTP/1.1" 200 -
Mar 30 17:06:22 device conmon[1625]: {"products":["Linux","Windows","Mac"]}

conmon 日誌由 podman.service 的“conmon”子程序生成。

root@device:~# systemctl status podman
● podman.service - Podman API Service
    Loaded: loaded (8;;file://device/lib/systemd/system/podman.service^G/lib/systemd/system/podman.service8;;^G; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2022-03-30 15:48:55 UTC; 1h 18min ago
TriggeredBy: ● podman.socket
      Docs: 8;;man:podman-system-service(1)^Gman:podman-system-service(1)8;;^G
  Main PID: 515 (podman)
     Tasks: 17 (limit: 495)
    Memory: 11.8M
       CPU: 2min 11.029s
    CGroup: /system.slice/podman.service
            ├─ 515 /usr/bin/podman --log-level=error system service --time=0
            ├─1391 /usr/bin/dnsmasq -u root --conf-file=/run/containers/cni/dnsname/docker-compose_host_internal_net/dnsmasq.conf
            ├─1393 /usr/bin/conmon --api-version 1 -c 6739cff6019d2f7e8f123d6fb02f163ec99ee73d322672c41d81f85d6218c66f -u 6739cff6019d2f7e8f123d6fb02f163ec99ee73d322672c41d81f85d6218c66f -r /usr/bin/crun -b /con>
            ├─1558 /usr/bin/conmon --api-version 1 -c ae34f69196a5d1b332f2f137942d3728c24bb41d06392b13dcfc7296f39b7936 -u ae34f69196a5d1b332f2f137942d3728c24bb41d06392b13dcfc7296f39b7936 -r /usr/bin/crun -b /con>
            └─1625 /usr/bin/conmon --api-version 1 -c b94e032b37a8690f847442ab9cdcf7b78aefab45231098d02c60b5f79e5c3474 -u b94e032b37a8690f847442ab9cdcf7b78aefab45231098d02c60b5f79e5c3474 -r /usr/bin/crun -b /con>

Mar 30 17:07:19 device conmon[1558]: App2 endpoint hit ...
Mar 30 17:07:19 device conmon[1558]: Getting http://app1 ...
Mar 30 17:07:20 device conmon[1393]: App1 endpoint hit ...
Mar 30 17:07:20 device conmon[1393]: 10.89.0.3 - - [30/Mar/2022 17:07:20] "GET / HTTP/1.1" 200 -
Mar 30 17:07:20 device conmon[1558]: Status of GET: 200
Mar 30 17:07:20 device conmon[1558]: 
Mar 30 17:07:20 device conmon[1558]: Results of GET: {"products":["Linux","Windows","Mac"]}
Mar 30 17:07:20 device conmon[1558]: 
Mar 30 17:07:20 device conmon[1558]: 10.89.0.4 - - [30/Mar/2022 17:07:20] "GET / HTTP/1.1" 200 -
Mar 30 17:07:20 device conmon[1625]: {"products":["Linux","Windows","Mac"]}

我嘗試將 SystemD 服務文件中的 podman.service StandardOutput 和 StandardErr 重定向為 null - 但 conmon 日誌仍然顯示為 journalctl。

root@device:~# cat /lib/systemd/system/podman.service 
[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0

[Service]
Environment=XDG_RUNTIME_DIR=
CPUWeight=1000
Type=exec
KillMode=process
StandardOutput=null
StandardError=null
Environment=LOGGING="--log-level=error"
#ExecStart=/bin/sh -c "/usr/bin/podman $LOGGING system service --time=0 1>/dev/null 2>/dev/null"
ExecStart=/usr/bin/podman $LOGGING system service --time=0

如何擺脫 conmon 日誌條目?謝謝。

Try LogLevelMax=error,它只是將單元的所有日誌記錄限制為日誌級別錯誤或更糟。至少對我來說,這解決了一個類似的問題,即程序會向 journalctl 發送垃圾郵件。也許在這種情況下它也有幫助,至少在某種意義上它會抑制來自子程序的所有非錯誤消息。

這是不言自明的,但有關更多詳細資訊,請查看 systemd 單元的手冊,它解釋了它的確切作用: https ://www.freedesktop.org/software/systemd/man/systemd.exec.html

引用自:https://unix.stackexchange.com/questions/697389