journalctl -u sshd -n 1000 -f

Linux命令-journalctl学习

 
1 人赞同了该文章

一、命令作用

journalctl主要功能用于查看指定的日志信息。

二、命令格式

journalctl [参数]

三、选项参数说明

我们可以使用man journalctl命令查看官方说明

$ man journalctl
NAME
       journalctl - Query the systemd journal

SYNOPSIS
       journalctl [OPTIONS...] [MATCHES...]

DESCRIPTION
       journalctl may be used to query the contents of the systemd(1) journal as written by
       systemd-journald.service(8).

       If called without parameters, it will show the full contents of the journal, starting with
       the oldest entry collected.

       If one or more match arguments are passed, the output is filtered accordingly. A match is
       in the format "FIELD=VALUE", e.g.  "_SYSTEMD_UNIT=httpd.service", referring to the
       components of a structured journal entry. See systemd.journal-fields(7) for a list of
       well-known fields. If multiple matches are specified matching different fields, the log
       entries are filtered by both, i.e. the resulting output will show only entries matching
       all the specified matches of this kind. If two matches apply to the same field, then they
       are automatically matched as alternatives, i.e. the resulting output will show entries
       matching any of the specified matches for the same field. Finally, the character "+" may
       appears as a separate word between other terms on the command line. This causes all
       matches before and after to be combined in a disjunction (i.e. logical OR).

       As shortcuts for a few types of field/value matches, file paths may be specified. If a
       file path refers to an executable file, this is equivalent to an "_EXE=" match for the
       canonicalized binary path. Similarly, if a path refers to a device node then match is
       added for the kernel name of the device ("_KERNEL_DEVICE="). Also, matches for the kernel
       names of all the parent devices are added automatically. Device node paths are not stable
       across reboots, therefore match for the current boot id ("_BOOT_ID=") is always added as
       well. Note that only the log entries for the existing device nodes maybe queried by
       providing path to the device node.

       Additional constraints may be added using options --boot, --unit=, etc, to further limit
       what entries will be shown (logical AND).

       Output is interleaved from all accessible journal files, whether they are rotated or
       currently being written, and regardless of whether they belong to the system itself or are
       accessible user journals.

       The set of journal files which will be used can be modified using the --user, --system,
       --directory, and --file options, see below.

       All users are granted access to their private per-user journals. However, by default, only
       root and users who are members of a few special groups are granted access to the system
       journal and the journals of other users. Members of the the "systemd-journal", "adm", and
       "wheel" groups can read all journal files. Note that the two latter groups traditionally
       have additional privileges specified by the distribution. Members of the "wheel" group can
       often perform administrative tasks.

       The output is paged through less by default, and long lines are "truncated" to screen
       width. The hidden part can be viewed by using the left-arrow and right-arrow keys. Paging
       can be disabled; see the --no-pager option and the "Environment" section below.

       When outputting to a tty, lines are colored according to priority: lines of level ERROR
       and higher are colored red; lines of level NOTICE and higher are highlighted; other lines
       are displayed normally.

OPTIONS
       The following options are understood:

       --no-full, --full, -l
           Ellipsize fields when they do not fit in available columns. The default is to show
           full fields, allowing them to wrap or be truncated by the pager, if one is used.

           The old options -l/--full are not useful anymore, except to undo --no-full.

       -a, --all
           Show all fields in full, even if they include unprintable characters or are very long.

       -f, --follow
           Show only the most recent journal entries, and continuously print new entries as they
           are appended to the journal.

       -e, --pager-end
           Immediately jump to the end of the journal inside the implied pager tool. This implies
           -n1000 to guarantee that the pager will not buffer logs of unbounded size. This may be
           overridden with an explicit -n with some other numeric value while -nall will disable
           this cap. Note that this option is only supported for the less(1) pager.

       -n, --lines=
           Show the most recent journal events and limit the number of events shown. If --follow
           is used, this option is implied. The argument is a positive integer or "all" to
           disable line limiting. The default value is 10 if no argument is given.

       --no-tail
           Show all stored output lines, even in follow mode. Undoes the effect of --lines=.

       -r, --reverse
           Reverse output so that the newest entries are displayed first.

       -o, --output=
           Controls the formatting of the journal entries that are shown. Takes one of the
           following options:

           short
               is the default and generates an output that is mostly identical to the formatting
               of classic syslog files, showing one line per journal entry.

           short-iso
               is very similar, but shows ISO 8601 wallclock timestamps.

           short-precise
               is very similar, but shows timestamps with full microsecond precision.

           short-monotonic
               is very similar, but shows monotonic timestamps instead of wallclock timestamps.

           verbose
               shows the full-structured entry items with all fields.

           export
               serializes the journal into a binary (but mostly text-based) stream suitable for
               backups and network transfer (see Journal Export Format[1] for more information).

           json
               formats entries as JSON data structures, one per line (see Journal JSON Format[2]
               for more information).

           json-pretty
               formats entries as JSON data structures, but formats them in multiple lines in
               order to make them more readable by humans.

           json-sse
               formats entries as JSON data structures, but wraps them in a format suitable for
               Server-Sent Events[3].

           cat
               generates a very terse output, only showing the actual message of each journal
               entry with no metadata, not even a timestamp.

       --utc
           Express time in Coordinated Universal Time (UTC).

       -x, --catalog
           Augment log lines with explanation texts from the message catalog. This will add
           explanatory help texts to log messages in the output where this is available. These
           short help texts will explain the context of an error or log event, possible
           solutions, as well as pointers to support forums, developer documentation, and any
           other relevant manuals. Note that help texts are not available for all messages, but
           only for selected ones. For more information on the message catalog, please refer to
           the Message Catalog Developer Documentation[4].

           Note: when attaching journalctl output to bug reports, please do not use -x.

       -q, --quiet
           Suppresses any warning messages regarding inaccessible system journals when run as a
           normal user.

       -m, --merge
           Show entries interleaved from all available journals, including remote ones.

       -b [ID][±offset], --boot=[ID][±offset]
           Show messages from a specific boot. This will add a match for "_BOOT_ID=".

           The argument may be empty, in which case logs for the current boot will be shown.

           If the boot ID is omitted, a positive offset will look up the boots starting from the
           beginning of the journal, and a equal-or-less-than zero offset will look up boots
           starting from the end of the journal. Thus, 1 means the first boot found in the
           journal in chronological order, 2 the second and so on; while -0 is the last boot, -1
           the boot before last, and so on. An empty offset is equivalent to specifying -0,
           except when the current boot is not the last boot (e.g. because --directory was
           specified to look at logs from a different machine).

           If the 32-character ID is specified, it may optionally be followed by offset which
           identifies the boot relative to the one given by boot ID. Negative values mean earlier
           boots and a positive values mean later boots. If offset is not specified, a value of
           zero is assumed, and the logs for the boot given by ID are shown.

       --list-boots
           Show a tabular list of boot numbers (relative to the current boot), their IDs, and the
           timestamps of the first and last message pertaining to the boot.

       -k, --dmesg
           Show only kernel messages. This implies -b and adds the match "_TRANSPORT=kernel".

       -t, --identifier=SYSLOG_IDENTIFIER|PATTERN
           Show messages for the specified syslog identifier SYSLOG_IDENTIFIER, or for any of the
           messages with a "SYSLOG_IDENTIFIER" matched by PATTERN.

           This parameter can be specified multiple times.

       -u, --unit=UNIT|PATTERN
           Show messages for the specified systemd unit UNIT (such as a service unit), or for any
           of the units matched by PATTERN. If a pattern is specified, a list of unit names found
           in the journal is compared with the specified pattern and all that match are used. For
           each unit name, a match is added for messages from the unit ("_SYSTEMD_UNIT=UNIT"),
           along with additional matches for messages from systemd and messages about coredumps
           for the specified unit.

           This parameter can be specified multiple times.

       -p, --priority=
           Filter output by message priorities or priority ranges. Takes either a single numeric
           or textual log level (i.e. between 0/"emerg" and 7/"debug"), or a range of
           numeric/text log levels in the form FROM..TO. The log levels are the usual syslog log
           levels as documented in syslog(3), i.e.  "emerg" (0), "alert" (1), "crit" (2),
           "err" (3), "warning" (4), "notice" (5), "info" (6), "debug" (7). If a single log level
           is specified, all messages with this log level or a lower (hence more important) log
           level are shown. If a range is specified, all messages within the range are shown,
           including both the start and the end value of the range. This will add "PRIORITY="
           matches for the specified priorities.

       -c, --cursor=
           Start showing entries from the location in the journal specified by the passed cursor.

       --after-cursor=
           Start showing entries from the location in the journal after the location specified by
           the this cursor. The cursor is shown when the --show-cursor option is used.

       --show-cursor
           The cursor is shown after the last entry after two dashes:

               -- cursor: s=0639...

           The format of the cursor is private and subject to change.

       -S, --since=, -U, --until=
           Start showing entries on or newer than the specified date, or on or older than the
           specified date, respectively. Date specifications should be of the format "2012-10-30
           18:17:16". If the time part is omitted, "00:00:00" is assumed. If only the seconds
           component is omitted, ":00" is assumed. If the date component is omitted, the current
           day is assumed. Alternatively the strings "yesterday", "today", "tomorrow" are
           understood, which refer to 00:00:00 of the day before the current day, the current
           day, or the day after the current day, respectively.  "now" refers to the current
           time. Finally, relative times may be specified, prefixed with "-" or "+", referring to
           times before or after the current time, respectively.

       -F, --field=
           Print all possible data values the specified field can take in all entries of the
           journal.

       --system, --user
           Show messages from system services and the kernel (with --system). Show messages from
           service of current user (with --user). If neither is specified, show all messages that
           the user can see.

       -M, --machine=
           Show messages from a running, local container. Specify a container name to connect to.

       -D DIR, --directory=DIR
           Takes a directory path as argument. If specified, journalctl will operate on the
           specified journal directory DIR instead of the default runtime and system journal
           paths.

       --file=GLOB
           Takes a file glob as an argument. If specified, journalctl will operate on the
           specified journal files matching GLOB instead of the default runtime and system
           journal paths. May be specified multiple times, in which case files will be suitably
           interleaved.

       --root=ROOT
           Takes a directory path as an argument. If specified, journalctl will operate on
           catalog file hierarchy underneath the specified directory instead of the root
           directory (e.g.  --update-catalog will create ROOT/var/lib/systemd/catalog/database).

       --new-id128
           Instead of showing journal contents, generate a new 128-bit ID suitable for
           identifying messages. This is intended for usage by developers who need a new
           identifier for a new message they introduce and want to make recognizable. This will
           print the new ID in three different formats which can be copied into source code or
           similar.

       --header
           Instead of showing journal contents, show internal header information of the journal
           fields accessed.

       --disk-usage
           Shows the current disk usage of all journal files. This shows the sum of the disk
           usage of all archived and active journal files.

       --vacuum-size=, --vacuum-time=
           Removes archived journal files until the disk space they use falls below the specified
           size (specified with the usual "K", "M", "G", "T" suffixes), or all journal files
           contain no data older than the specified timespan (specified with the usual "s",
           "min", "h", "days", "months", "weeks", "years" suffixes). Note that running
           --vacuum-size= has only indirect effect on the output shown by --disk-usage as the
           latter includes active journal files, while the former only operates on archived
           journal files.  --vacuum-size= and --vacuum-time= may be combined in a single
           invocation to enforce both a size and time limit on the archived journal files.

       --list-catalog [128-bit-ID...]
           List the contents of the message catalog as a table of message IDs, plus their short
           description strings.

           If any 128-bit-IDs are specified, only those entries are shown.

       --dump-catalog [128-bit-ID...]
           Show the contents of the message catalog, with entries separated by a line consisting
           of two dashes and the ID (the format is the same as .catalog files).

           If any 128-bit-IDs are specified, only those entries are shown.

       --update-catalog
           Update the message catalog index. This command needs to be executed each time new
           catalog files are installed, removed, or updated to rebuild the binary catalog index.

       --setup-keys
           Instead of showing journal contents, generate a new key pair for Forward Secure
           Sealing (FSS). This will generate a sealing key and a verification key. The sealing
           key is stored in the journal data directory and shall remain on the host. The
           verification key should be stored externally. Refer to the Seal= option in
           journald.conf(5) for information on Forward Secure Sealing and for a link to a
           refereed scholarly paper detailing the cryptographic theory it is based on.

       --force
           When --setup-keys is passed and Forward Secure Sealing (FSS) has already been
           configured, recreate FSS keys.

       --interval=
           Specifies the change interval for the sealing key when generating an FSS key pair with
           --setup-keys. Shorter intervals increase CPU consumption but shorten the time range of
           undetectable journal alterations. Defaults to 15min.

       --verify
           Check the journal file for internal consistency. If the file has been generated with
           FSS enabled and the FSS verification key has been specified with --verify-key=,
           authenticity of the journal file is verified.

       --verify-key=
           Specifies the FSS verification key to use for the --verify operation.

       --flush
           Asks the Journal daemon to flush any log data stored in /run/log/journal into
           /var/log/journal, if persistent storage is enabled. This call does not return until
           the operation is complete.

       -h, --help
           Print a short help text and exit.

       --version
           Print a short version string and exit.

       --no-pager
           Do not pipe output into a pager.

EXIT STATUS
       On success, 0 is returned; otherwise, a non-zero failure code is returned.

ENVIRONMENT
       $SYSTEMD_PAGER
           Pager to use when --no-pager is not given; overrides $PAGER. Setting this to an empty
           string or the value "cat" is equivalent to passing --no-pager.

       $SYSTEMD_LESS
           Override the default options passed to less ("FRSXMK").

EXAMPLES
       Without arguments, all collected logs are shown unfiltered:

           journalctl

       With one match specified, all entries with a field matching the expression are shown:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service

       If two different fields are matched, only entries matching both expressions at the same
       time are shown:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097

       If two matches refer to the same field, all entries matching either expression are shown:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _SYSTEMD_UNIT=dbus.service

       If the separator "+" is used, two expressions may be combined in a logical OR. The
       following will show all messages from the Avahi service process with the PID 28097 plus
       all messages from the D-Bus service (from any of its processes):

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097 + _SYSTEMD_UNIT=dbus.service

       Show all logs generated by the D-Bus executable:

           journalctl /usr/bin/dbus-daemon

       Show all kernel logs from previous boot:

           journalctl -k -b -1

       Show a live log display from a system service apache.service:

           journalctl -f -u apache

SEE ALSO
       systemd(1), systemd-journald.service(8), systemctl(1), coredumpctl(1), systemd.journal-
       fields(7), journald.conf(5)

NOTES
        1. Journal Export Format
           http://www.freedesktop.org/wiki/Software/systemd/export

        2. Journal JSON Format
           http://www.freedesktop.org/wiki/Software/systemd/json

        3. Server-Sent Events
           https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events

        4. Message Catalog Developer Documentation
           http://www.freedesktop.org/wiki/Software/systemd/catalog

看到这里是不是很头大,一大堆英语,很懵。那么接下来按照上面的格式进行翻译说明

$ man journalctl
名字
        journalctl - 查询系统日志
概要
        journalctl [OPTIONS...] [MATCHES...]
描述
        journalctl 可用于查询 systemd(1) 日志的内容,如systemd-journald.service(8)。

         如果不带参数调用,它将显示日志的全部内容,从收集到的最早条目。

         如果传递了一个或多个匹配参数,则会相应地过滤输出。一场比赛是格式为“FIELD=VALUE”,例                       如“_SYSTEMD_UNIT=httpd.service”,指的是结构化日记帐分录的组成部分。有关列表,请参阅                    systemd.journal-fields(7)知名领域。如果指定多个匹配匹配不同的字段,则日志条目被两者过滤,即结果输出将        仅显示匹配的条目所有指定的此类匹配项。如果两个匹配项应用于同一字段,则它们自动匹配为备选方案,即结果输出         将显示条目匹配同一字段的任何指定匹配项。最后,字符“+”可能在命令行上显示为其他术语之间的单独单词。这导致        所有之前和之后的匹配在析取中组合(即逻辑或)。

         作为几种类型的字段/值匹配的快捷方式,可以指定文件路径。如果一个文件路径指的是可执行文件,这相当               于“_EXE=”匹配规范化的二进制路径。类似地,如果路径指的是设备节点,则匹配是为设备的内核名称添加              ("_KERNEL_DEVICE=")。此外,匹配内核所有父设备的名称都会自动添加。设备节点路径不稳定重新启动后,因此始        终将当前引导 ID ("_BOOT_ID=") 的匹配项添加为出色地。请注意,只有现有设备节点的日志条目可能会被查询
         提供到设备节点的路径。


        可以使用 --boot、--unit= 等选项添加额外的约束,以进一步限制将显示哪些条目(逻辑与)。

        输出从所有可访问的日志文件中交错,无论它们是旋转的还是当前正在编写,无论它们是否属于系统本身或可访问的用        户日志。


        可以使用--user、--system、--directory 和 --file 选项,见下文。


        所有用户都被授予访问他们私人的每用户日志的权限。但是,默认情况下,只有root 和一些特殊组成员的用户被授予        访问系统的权限期刊和其他用户的期刊。 “systemd-journal”、“adm”和“adm”的成员“wheel”组可以读取所有日志        文件。请注意,传统上后两组具有分配指定的附加权限。 “车轮”组的成员可以经常执行行政任务。

        默认情况下,输出通过 less 分页,长行被“截断”到屏幕宽度。可以使用左箭头键和右箭头键查看隐藏部分。分页
        可以禁用;请参阅 --no-pager 选项和下面的“环境”部分。

        当输出到 tty 时,线条根据优先级着色:错误级别的线条更高的是红色;突出显示级别 NOTICE 和更高级别的行;其       他线路都正常显示。

选项

        理解以下选项:

       --no-full, --full, -l
           当字段不适合可用列时,将其省略。默认是显示完整字段,允许它们换行或被寻呼机截断,如果使用的话。

           旧选项 -l/--full 不再有用,除了撤消 --no-full。

       -a, --all

          完整显示所有字段,即使它们包含不可打印的字符或很长。

       -f, --follow

          仅显示最近的日记条目,并在新条目出现时不断打印它们被附加到日志中。

       -e, --pager-end
          立即跳转到隐含寻呼机工具内的日志末尾。这意味着-n1000 以保证寻呼机不会缓冲无限大小的日志。这可能是
           用带有其他数值的显式 -n 覆盖,而 -nall 将禁用这个上限。请注意,此选项仅支持 less(1) 寻呼机。

       -n, --lines=
           显示最近的日志事件并限制显示的事件数。如果——跟随被使用时,这个选项是隐含的。参数是一个正整数或“全部”到
           禁用行限制。如果没有给出参数,默认值为 10。

       --no-tail

          显示所有存储的输出行,即使在跟随模式下也是如此。取消 --lines= 的效果。

       -r, --reverse

          反转输出,以便首先显示最新的条目。

       -o, --output=
           控制显示的日记帐条目的格式。采取其中之一以下选项:

           short
               是默认值并生成与格式基本相同的输出经典系统日志文件,每个日志条目显示一行。

           short-iso
               非常相似,但显示 ISO 8601 挂钟时间戳。

           short-precise
               非常相似,但显示的时间戳具有完整的微秒精度。

           short-monotonic
               非常相似,但显示单调时间戳而不是挂钟时间戳。

           verbose
               显示具有所有字段的完整结构化条目项。

           export
               将日志序列化为适合于的二进制(但主要是基于文本的)流备份和网络传输(有关更多信息,请参阅日志导出格              式 [1])。

           json
               将条目格式化为 JSON 数据结构,每行一个(参见 Journal JSON Format[2]了解更多信息)。

           json-pretty

              将条目格式化为 JSON 数据结构,但将它们格式化为多行为了使它们更容易被人类阅读。

           json-sse
               将条目格式化为 JSON 数据结构,但将它们包装成适合服务器发送的事件[3]。

           cat
               生成非常简洁的输出,仅显示每个日志的实际消息条目没有元数据,甚至没有时间戳。

       --utc
           以协调世界时 (UTC) 表示的表达时间。

       -x, --catalog

          使用消息目录中的解释文本扩充日志行。这将添加解释性帮助文本,用于在可用的输出中记录消息。这些
           简短的帮助文本将可能解释错误或日志事件的上下文解决方案,以及指向支持论坛、开发人员文档和任何
           其他相关手册。请注意,帮助文本并非适用于所有消息,但仅适用于选定的。有关消息目录的更多信息,请参阅
           消息目录开发人员文档 [4]。

          注意:将 journalctl 输出附加到错误报告时,请不要使用 -x。

       -q, --quiet

          当作为一个普通用户,禁止显示有关无法访问的系统日志的任何警告消息

       -m, --merge

          显示与所有可用日志交错的条目,包括远程日志。

       -b [ID][±offset], --boot=[ID][±offset]

          显示来自特定引导的消息。这将为“_BOOT_ID=”添加一个匹配项。

          该参数可以为空,在这种情况下将显示当前引导的日志。

          如果省略引导 ID,则正偏移将从引导开始查找引导日志的开头,并且等于或小于零的偏移量将查找靴子
           从日记的末尾开始。因此,1 表示在日记按时间顺序排列,2 第二,依此类推;而 -0 是最后一次启动,-1
           最后引导,等等。空偏移量相当于指定 -0,除非当前引导不是最后一次引导(例如,因为 --directory 是
           指定查看来自不同机器的日志)。

          如果指定了 32 个字符的 ID,则可以选择在其后跟偏移量,该偏移量标识相对于引导 ID 给定的引导。负值意味着          更早靴子和正值意味着以后的靴子。如果未指定偏移量,则值为假定为零,并显示 ID 给定的引导日志。

       --list-boots

          显示引导编号(相对于当前引导)、它们的 ID 和与引导有关的第一条和最后一条消息的时间戳。

       -k, --dmesg

           仅显示内核消息。这意味着 -b 并添加匹配项“_TRANSPORT=kernel”。

       -t, --identifier=SYSLOG_IDENTIFIER|PATTERN
           显示指定系统日志标识符 SYSLOG_IDENTIFIER 的消息,或任何具有与 PATTERN 匹配                                的“SYSLOG_IDENTIFIER”的消息。

           该参数可以指定多次。

       -u, --unit=UNIT|PATTERN
           显示指定系统单元 UNIT(例如服务单元)或任何由 PATTERN 匹配的单元数。如果指定了模式,则找到一个单元名          称列表将日志中的模式与指定的模式进行比较,并使用所有匹配的模式。为了每个单位名称,为来自该单位的消息          添加一个匹配项(“_SYSTEMD_UNIT = UNIT”),以及来自 systemd 的消息和有关核心转储的消息的其他匹配项
           对于指定的单位。

          该参数可以指定多次。

       -p, --priority=
           按消息优先级或优先级范围过滤输出。接受单个数字或文本日志级别(即在 0/"emerg" 和 7/"debug" 之间),           或一系列FROM..TO 格式的数字/文本日志级别。日志级别是通常的系统日志syslog(3) 中记录的级别,                 即“emerg”(0)、“alert”(1)、“crit”(2)、“错误”(3)、“警告”(4)、“通知”(5)、“信息”(6)、“调试”(7)。如          果单个日志级别指定后,所有具有此日志级别或较低(因此更重要)日志的消息水平显示。如果指定了范围,则显示          该范围内的所有消息,包括范围的起始值和结束值。这将添加“PRIORITY =”匹配指定的优先级。

       -c, --cursor=
           从传递的光标指定的日志位置开始显示条目。

       --after-cursor=

          在由指定的位置之后开始显示日志中位置的条目这个游标。使用 --show-cursor 选项时会显示光标。

       --show-cursor

           光标显示在两个破折号之后的最后一个条目之后:

               -- cursor: s=0639...

           游标的格式是私有的,可能会发生变化。

       -S, --since=, -U, --until=
           开始显示指定日期或晚于指定日期或早于指定日期的条目分别指定日期。日期规范应采用“2012-10-30
           18:17:16”。如果省略时间部分,则假定为“00:00:00”。如果只有秒省略组件,假定为“:00”。如果省略日期部           分,则当前假设一天。或者,字符串“昨天”、“今天”、“明天”是理解为当前日的前一天00:00:00,当前
           天,或当天之后的一天,分别。 “现在”指的是当前时间。最后,可以指定相对时间,以“-”或“+”为前缀,指的是
           分别在当前时间之前或之后的时间.

       -F, --field=
          打印指定字段在所有条目中可以接受的所有可能的数据值杂志。


       --system, --user
           显示来自系统服务和内核的消息(使用 --system)。显示消息来自当前用户的服务(使用--user)。如果两者均          未指定,则显示所有消息用户可以看到。


       -M, --machine=
           显示来自正在运行的本地容器的消息。指定要连接的容器名称。

       -D DIR, --directory=DIR
           将目录路径作为参数。如果指定,journalctl 将在指定日志目录 DIR 而不是默认的运行时和系统日志
           路径。

       --file=GLOB

          将文件 glob 作为参数。如果指定,journalctl 将在指定日志文件匹配 GLOB 而不是默认的运行时和系统
           期刊路径。可以指定多次,在这种情况下文件将被适当地交错的。


       --root=ROOT

          将目录路径作为参数。如果指定,journalctl 将在指定目录下的目录文件层次结构而不是根目录
           (e.g. --update-catalog will create ROOT/var/lib/systemd/catalog/database)。


       --new-id128
           不显示日志内容,而是生成一个适合于的新 128 位 ID识别消息。这是供需要新的开发人员使用的
           他们引入并希望使其可识别的新消息的标识符。这会以三种不同的格式打印新 ID,这些格式可以复制到源代码中,           或者相似的。

       --header

          不显示期刊内容,而是显示期刊的内部标题信息访问的字段。

       --disk-usage

          显示所有日志文件的当前磁盘使用情况。这显示了磁盘的总和所有存档和活动日志文件的使用。

       --vacuum-size=, --vacuum-time=
           删除存档的日志文件,直到它们使用的磁盘空间低于指定的大小(用通常的“K”、“M”、“G”、“T”后缀指定)或所有          日志文件不包含早于指定时间跨度的数据(用通常的“s”指定,“分钟”、“小时”、“天”、“月”、“周”、“年”后              缀)。注意运行--vacuum-size= 对 --disk-usage 显示的输出只有间接影响后者包括活跃的日志文件,而前者只          对归档文件进行操作日志文件。 --vacuum-size= 和 --vacuum-time= 可以组合成一个调用以对归档的日志文件          强制执行大小和时间限制。

       --list-catalog [128-bit-ID...]

          将消息目录的内容列为消息 ID 表,加上它们的缩写描述字符串。

          如果指定了任何 128 位 ID,则仅显示那些条目。

       --dump-catalog [128-bit-ID...]

          显示消息目录的内容,条目由一行分隔
           两个破折号和 ID(格式与 .catalog 文件相同)。

           如果指定了任何 128 位 ID,则仅显示那些条目。

       --update-catalog
           更新消息目录索引。每次新建都需要执行这个命令安装、删除或更新目录文件以重建二进制目录索引。

       --setup-keys
          不显示日志内容,而是为 Forward Secure 生成一个新的密钥对密封(FSS)。这将生成密封密钥和验证密钥。封          口密钥存储在日志数据目录中,并应保留在主机上。这验证密钥应存储在外部。参考 Seal= 中的选项                   journald.conf(5) 以获取有关 Forward Secure Sealing 的信息以及指向参考学术论文详细介绍了它所基于的          密码学理论。

       --force
          当 --setup-keys 被传递并且 Forward Secure Sealing (FSS) 已经被传递时
           配置,重新创建 FSS 密钥。

       --interval=
           指定生成 FSS 密钥对时密封密钥的更改间隔--设置键。较短的间隔会增加 CPU 消耗,但会缩短时间范围
           无法检测到的期刊变更。默认为 15 分钟。

       --verify
           检查日志文件的内部一致性。如果文件是用已启用 FSS 且已使用 --verify-key= 指定 FSS 验证密钥,
           日志文件的真实性得到验证。

       --verify-key=

          指定用于 --verify 操作的 FSS 验证密钥。

       --flush

          要求 Journal 守护进程将 /run/log/journal 中存储的任何日志数据刷新到
           /var/log/journal,如果启用了持久存储。此调用不会返回,直到操作完成。


       -h, --help
          打印简短的帮助文本并退出。

       --version
           打印一个短版本字符串并退出。

       --no-pager
           不要将输出通过管道传输到寻呼机。

退出状态
       成功返回0;否则,返回一个非零失败代码。

环境
       $SYSTEMD_PAGER
          未给出 --no-pager 时使用的寻呼机;覆盖 $PAGER。将此设置为空
           字符串或值“cat”等同于传递 --no-pager。

       $SYSTEMD_LESS
           覆盖传递给较少的默认选项(“FRSXMK”)。

例子
       没有参数,所有收集的日志都显示为未过滤:

           journalctl

       指定一个匹配项后,将显示具有与表达式匹配的字段的所有条目:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service

       如果匹配两个不同的字段,则只有同时匹配两个表达式的条目时间显示:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097

       如果两个匹配项引用同一个字段,则显示与任一表达式匹配的所有条目:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _SYSTEMD_UNIT=dbus.service

       如果使用分隔符“+”,则两个表达式可以组合成逻辑或。这以下将显示来自 PID 为 28097 plus 的 Avahi 服务进程的      所有消息来自 D-Bus 服务(来自其任何进程)的所有消息:

           journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097 + _SYSTEMD_UNIT=dbus.service

       显示 D-Bus 可执行文件生成的所有日志:

           journalctl /usr/bin/dbus-daemon

       显示上次启动的所有内核日志:

           journalctl -k -b -1

       显示来自系统服务 apache.service 的实时日志显示:

           journalctl -f -u apache

也可以看看
       systemd(1), systemd-journald.service(8), systemctl(1), coredumpctl(1), systemd.journal-
       fields(7), journald.conf(5)

笔记
        1. Journal Export Format
           http://www.freedesktop.org/wiki/Software/systemd/export

        2. Journal JSON Format
           http://www.freedesktop.org/wiki/Software/systemd/json

        3. Server-Sent Events
           https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events

        4. Message Catalog Developer Documentation
           http://www.freedesktop.org/wiki/Software/systemd/catalog

翻译完看是不是好多了呢,下面主要介绍一下常用参数和使用案例。

四、常用用法示例

1.指定查看内核日志信息

$ journalctl -k

2.指定查看本次系统启动的日志信息

$ journalctl -b

3.指定查看某个服务程序的日志信息

$ journalctl -u sshd

4.指定查看最近10条日志信息

$ journalctl -n 10

5.动态追踪最新的日志信息

$ journalctl -f

6.显示从2月6号开始2月7号关于sshd的日志

$ start_time=$(date -d "1 day ago"  "+%Y-%m-%d 00:00:00")
$ end_time=$(date -d "0 day ago"  "+%Y-%m-%d 00:00:00")
$ journalctl --since="$start_time" --until="$end_time" -u sshd

上述参数介绍如下:

  • -d:显示 datestr 中所设定的时间 (非系统时间)
  • "1 day ago":输出一天前的日期
  • "0 day ago":输出当前日期
  • --since:仅显示指定日期或以后的日志条目
  • --until:仅显示指定日期或之前的日志条目
  • -u:仅显示与指定单元相关的日志条目。单元可以是系统服务
posted @   技术颜良  阅读(78)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2022-04-05 go切片的nil 切片、空切片与零切片(重要)
2022-04-05 如何优雅的在 Kubernetes 上实现资源配额(重要)
2022-04-05 TCP原理(三次握手四次挥手)(有这篇就够了,重要)
点击右上角即可分享
微信分享提示