systemd-journald配置详解:journald.conf全面介绍

367 阅读2分钟

文章目录 **

systemd-journald 是 systemd 系统的核心组件之一,负责收集和存储日志数据。通过配置文件 journald.conf,我们可以精细地控制 journald 的行为,包括日志的存储方式、大小限制、转发选项等。本文将深入探讨 journald.conf 的主要配置选项,帮助你更好地管理系统日志。

journald 配置文件位置

journald.conf 的主要配置文件位置如下,按优先级从高到低排列:

  1. /etc/systemd/journald.conf
  2. /run/systemd/journald.conf
  3. /usr/local/lib/systemd/journald.conf
  4. /usr/lib/systemd/journald.conf

此外,还可以使用 .conf.d 目录来存放配置片段:

  • /etc/systemd/journald.conf.d/*.conf
  • /run/systemd/journald.conf.d/*.conf
  • /usr/local/lib/systemd/journald.conf.d/*.conf
  • /usr/lib/systemd/journald.conf.d/*.conf

对于特定命名空间的配置,可以使用:

  • /etc/systemd/journald@NAMESPACE.conf
  • /etc/systemd/journald@NAMESPACE.conf.d/*.conf

journald 配置选项示例

打开 journald 配置文件,通常如下所示:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the journald.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/journald.conf' to display the full config.
#
# See journald.conf(5) for details.

[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000
SystemMaxUse=100M
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
#ReadKMsg=yes
#Audit=no

journald 主要配置选项详细介绍

阅读全文:blog.axiaoxin.com/post/journa…