Linux之journalctl命令查看服务日志
Tags: journalctlLinuxOSsystemd命令介绍
简介
从2012年开始,大部分linux发行版本开始从传统的systemv 初始化系统移植到一个叫做systemd的全新系统。systemd用来启动系统并管理进程。systemd包含了一个叫做journalctl的辅助组件,其主要作用是管理系统的事件日志记录。
journalctl可以查看所有的系统日志文件,由于日志信息量很大,journalctl还提供了各种参数帮助用户更快速的定位到日志信息。
默认情况下,用户都可以访问自己的日志。对于系统主日志和其他用户的日志,仅限于有权限的用户访问,比如root用户,wheel组和systemd组的用户。
如果日志比较长,我们可以通过上下左右键盘键查看。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | [root@lhrxxt ~]# journalctl -h journalctl [OPTIONS...] [MATCHES...] Query the journal. Flags: --system Show the system journal --user Show the user journal for the current user -M --machine=CONTAINER Operate on local container -S --since=DATE Show entries not older than the specified date -U --until=DATE Show entries not newer than the specified date -c --cursor=CURSOR Show entries starting at the specified cursor --after-cursor=CURSOR Show entries after the specified cursor --show-cursor Print the cursor after all the entries -b --boot[=ID] Show current boot or the specified boot --list-boots Show terse information about recorded boots -k --dmesg Show kernel message log from the current boot -u --unit=UNIT Show logs from the specified unit -t --identifier=STRING Show entries with the specified syslog identifier -p --priority=RANGE Show entries with the specified priority -e --pager-end Immediately jump to the end in the pager -f --follow Follow the journal -n --lines[=INTEGER] Number of journal entries to show --no-tail Show all lines, even in follow mode -r --reverse Show the newest entries first -o --output=STRING Change journal output mode (short, short-iso, short-precise, short-monotonic, verbose, export, json, json-pretty, json-sse, cat) --utc Express time in Coordinated Universal Time (UTC) -x --catalog Add message explanations where available --no-full Ellipsize fields -a --all Show all fields, including long and unprintable -q --quiet Do not show privilege warning --no-pager Do not pipe output into a pager -m --merge Show entries from all available journals -D --directory=PATH Show journal files from directory --file=PATH Show journal file --root=ROOT Operate on catalog files underneath the root ROOT --interval=TIME Time interval for changing the FSS sealing key --verify-key=KEY Specify FSS verification key --force Override of the FSS key pair with --setup-keys Commands: -h --help Show this help text --version Show package version -F --field=FIELD List all values that a specified field takes --new-id128 Generate a new 128-bit ID --disk-usage Show total disk usage of all journal files --vacuum-size=BYTES Reduce disk usage below specified size --vacuum-time=TIME Remove journal files older than specified date --flush Flush all journal data from /run into /var --header Show journal header information --list-catalog Show all message IDs in the catalog --dump-catalog Show entries in the message catalog --update-catalog Update the message catalog database --setup-keys Generate a new FSS key pair --verify Verify journal file consistency |
journalctl
如果不带参数,journalctl将显示所有的信息。 (从旧到新)
journalctl -r
journalctl -f
要使用 journalctl 跟踪日志文件 (读取最新条目), 只需在命令后加参数 “-f” 即可。
会实时输出最新日志
journalctl -n 数字
指定输出显示的大小
我们可以通过-n 或者 --lines=参数来指定显示的行数大小。
显示指定时间的事件日志
journalctl可以显示指定时间段内发生的事件日志。 通过since和until 参数来实现。其中日期的格式是“YYYY-MM-DD HH:MM:SS”
比如:journalctl --since 1 hour ago ,查看1小时前到现在的日志
journalctl --since “2016-08-04 20:00:00” --until “2016-08-04 20:15:00” 查看8月4日晚上的日志
查看某些服务的日志:journalctl -u *.service
journalctl -u httpd.service 查看web服务的日志
journalctl -u httpd.service -u crond.service
显示系统日志信息
命令 “journalctl -k” 和 “journalctl --dmesg” 用来显示系统的内核日志信息。