Linux-Journal
Linux-Journal
2. 日志的优先级和分类
2.1 优先级
2.2 设施分类
3. 命令帮助
4. 日志查看示例
5. 日志大小限制
6. 手动清理日志文件
1. 日志简介
https://wiki.archlinux.org/index.php/Systemd/Journal
systemd有自己的日志记录系统; 因此,syslog不再需要运行守护程序。要阅读日志,请使用:#journalctl
在Arch Linux中,该目录/var/log/journal/是systemd包的一部分,并且日志(当Storage=设置为auto到/etc/systemd/journald.conf时)将写入/var/log/journal/。
如果删除该目录,systemd将不会自动重新创建它,而是/run/systemd/journal以非持久方式写入其日志。
然而,如果文件夹将被重新创建Storage=persistent被添加到journald.conf和systemd-journald.service被重新启动(或重新引导系统)。
Systemd Journal 的优点如下:
- * 简单性:代码少,依赖少,抽象开销最小。
- * 零维护:日志是除错和监控系统的核心功能,因此它自己不能再产生问题。举例说,自动管理磁盘空间,避免由于日志的不断产生而将磁盘空间耗尽。
- * 移植性:日志 文件应该在所有类型的 Linux 系统上可用,无论它使用的何种 CPU 或者字节序。
- * 性能:添加和浏览 日志 非常快。
- * 最小资源占用:日志 数据文件需要较小。
- * 统一化:各种不同的日志存储技术应该统一起来,将所有的可记录事件保存在同一个数据存储中。所以日志内容的全局上下文都会被保存并且可供日后查询。例如一条固件记录后通常会跟随一条内核记录,最终还会有一条用户态记录。重要的是当保存到硬盘上时这三者之间的关系不会丢失。Syslog 将不同的信息保存到不同的文件中,分析的时候很难确定哪些条目是相关的。
- * 扩展性:日志的适用范围很广,从嵌入式设备到超级计算机集群都可以满足需求。
- * 安全性:日志 文件是可以验证的,让无法检测的修改不再可能。
2. 日志的优先级和分类
系统日记按(优先级Priority level)和(设施Facility)对信息进行分类。日志分类对应于经典的Syslog协议(RFC 5424)。
注:下面表格最后一列 (wc -l) 是统计的记录数比例,总数是3个月的日志,大约100万条数据。
2.1 优先级
Value | (Key)Severity | Description | Examples | wc -l |
0 |
(emerg)ency 紧急 |
System is unusable |
Severe Kernel BUG, systemd dumped core. This level should not be used by applications. |
|
1 |
alert 警报 |
Should be corrected immediately |
Vital subsystem goes out of work. Data loss. kernel: BUG: unable to handle kernel paging request at ffffc90403238ffc. |
0.001% |
2 |
(crit)ical 危急 |
Critical conditions |
Crashes, coredumps. Like familiar flash: systemd-coredump[25319]: Process 25310 (plugin-containe) of user 1000 dumped core Failure in the system primary application, like X11. |
1% |
3 |
(err)or 错误 |
Error conditions |
Not severe error reported: kernel: usb 1-3: 3:1: cannot get freq at ep 0x84, systemd[1]: Failed unmounting /var., libvirtd[1720]: internal error: Failed to initialize a valid firewall backend |
1% |
4 |
warning 警告 |
May indicate that an error will occur if action is not taken. |
A non-root file system has only 1GB free. org.freedesktop. Notifications[1860]: (process:5999): Gtk-WARNING **: Locale not supported by C library. Using the fallback 'C' locale. |
71% |
5 |
notice 注意 |
Events that are unusual, but not error conditions. |
systemd[1]: var.mount: Directory /var to mount over is not empty, mounting anyway, gcr-prompter[4997]: Gtk: GtkDialog mapped without a transient parent. This is discouraged |
2% |
6 |
(info)rmational 信息 |
Normal operational messages that require no action. | lvm[585]: 7 logical volume(s) in volume group "archvg" now active | 25% |
7 |
debug 调试 |
Information useful to developers for debugging the application. | kdeinit5[1900]: powerdevil: Scheduling inhibition from ":1.14" "firefox" with cookie 13 and reason "screen" | 1% |
2.2 设施分类
Facility code | Keyword | Description | Info | wc -l |
0 | kern | Kernel messages | 15% | |
1 | user | User-level messages | 1% | |
3 | daemon | System daemons | All daemons, including systemd and its subsystems | 18% |
4 | auth | Security/authorization messages | Also watch for different facility 10 | 1% |
10 | authpriv | Security/authorization messages | Also watch for different facility 4 | 1% |
9 | Clock daemon | systemd-timesyncd | 0% |
下面是不常用或已弃用的分类:
Facility code | Keyword | Description |
2 | Mail system | |
5 | syslog | Messages generated internally by syslogd |
6 | lpr | Line printer subsystem |
7 | news | Network news subsystem |
8 | uucp | UUCP subsystem |
11 | ftp | FTP daemon |
12 | - | NTP subsystem |
13 | - | Log audit |
14 | - | Log alert |
15 | cron | Scheduling daemon |
16 - 23 | local0 - 7 | Local use 0 (local0) - Local use 7 (local7) |
3. 命令帮助
journalctl -h | |||
Options: | |||
--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 | 在所有条目之后打印光标 | |
--cursor-file=FILE | Show entries after cursor in FILE and update FILE | 在FILE中显示光标后的条目并更新FILE | |
-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 | 显示指定单位的日志 |
--user-unit=UNIT | Show logs from the specified user unit | 显示指定用户单元的日志 | |
-t | --identifier=STRING | Show entries with the specified syslog identifier | 显示具有指定syslog标识符的条目 |
-p | --priority=RANGE | Show entries with the specified priority | 显示具有指定优先级的条目 |
-g | --grep=PATTERN | Show entries with MESSAGE matching PATTERN | 显示MESSAGE匹配PATTERN的条目 |
--case-sensitive[=BOOL] | Force case sensitive or insenstive matching | 强制区分大小写或不区分匹配 | |
-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-precise, short-iso, short-iso-precise, short-full, short-monotonic, short-unix, (precise精确,monotonic单调) |
更改日志输出模式: verbose, export, json, json-pretty, json-sse, json-seq, cat, with-unit) |
--output-fields=LIST | Select fields to print in verbose/export/json modes | 选择要以详细/导出/ json模式打印的字段 | |
--utc | Express time in Coordinated Universal Time (UTC) | 协调世界时(UTC)的快车时间 | |
-x | --catalog | Add message explanations where available | 添加消息说明(如果有) |
--no-full | Ellipsize fields | Ellipsize字段 | |
-a | --all | Show all fields, including long and unprintable | 显示所有字段,包括长字段和不可打印字段 |
-q | --quiet | Do not show info messages and privilege warning | 不显示信息消息和权限警告 |
--no-pager | Do not pipe output into a pager | 不要将输出传输到寻呼机 | |
--no-hostname | Suppress output of hostname field | 禁止输出主机名字段 | |
-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 files below a root directory | 对根目录下的文件进行操作 | |
--interval=TIME | Time interval for changing the FSS sealing key | 更改FSS密封键的时间间隔 | |
--verify-key=KEY | Specify FSS verification key | 指定FSS验证密钥 | |
--force | Override of the FSS key pair with --setup-keys | 使用--setup-keys覆盖FSS密钥对 | |
Commands: | |||
-h | --help | Show this help text | 显示此帮助文本 |
--version | Show package version | 显示包版本 | |
-N | --fields | List all field names currently used | 列出当前使用的所有字段名称 |
-F | --field=FIELD | List all values that a specified field takes | 列出指定字段所需的所有值 |
--disk-usage | Show total disk usage of all journal files | 显示所有日志文件的总磁盘使用情况 | |
--vacuum-size=BYTES | Reduce disk usage below specified size | 将磁盘使用量降低到指定大小以下 | |
--vacuum-files=INT | Leave only the specified number of journal files | 只保留指定数量的日志文件 | |
--vacuum-time=TIME | Remove journal files older than specified time | 删除早于指定时间的日志文件 | |
--verify | Verify journal file consistency | 验证日志文件一致性 | |
--sync | Synchronize unwritten journal messages to disk | 将未写入的日志消息同步到磁盘 | |
--flush | Flush all journal data from /run into /var | 将/ run中的所有日志数据刷新到/var | |
--rotate | Request immediate rotation of the journal files | 请求立即轮换日志文件 | |
--header | Show journal header information | 显示日记标题信息 | |
--list-catalog | Show all message IDs in the catalog | 显示目录中的所有消息ID | |
--dump-catalog | Show entries in the message catalog | 在消息目录中显示条目 | |
--update-catalog | Update the message catalog database | 更新消息目录数据库 | |
--setup-keys | Generate a new FSS key pair | 生成新的FSS密钥对 |
4. 日志查看示例
Show all messages from this boot: -b 启动信息
$ sudo journalctl -b //启动信息23565
$ sudo journalctl --list-boots //引导列表
$ sudo journalctl -b -0 //
$ sudo journalctl -b -1 //前一次启动信息... 通过查询引导列表可看到最多能查看前几次启动信息
Show all messages from date (and optional time): -S 显示不早于指定日期的条目
$ sudo journalctl --since="2019-06-13 16:42:34"
Show all messages since 20 minutes ago: 最近20分钟
$ sudo journalctl --since "20 min ago"
$ sudo journalctl -S "20 min ago"
Follow new messages:
$ sudo journalctl -f
Show all messages by a specific executable:特定可执行文件
$ sudo journalctl /usr/lib/systemd/systemd
Show all messages by a specific process:特定进程
$ sudo journalctl _PID=1
Show all messages by a specific unit: -u 特定单元
$ sudo journalctl -u man-db.service
Show kernel ring buffer:-k 显示当前引导的内核消息日志(--dmesg)
$ sudo journalctl -k
Show only error, critical and alert priority messages:-p 显示具有指定优先级的条目(0-7)
$ sudo journalctl -p err..alert
$ sudo journalctl -p 3..1 //3-1
$ sudo journalctl -p 3 //3-0
$ sudo journalctl -p 3 -r //3-0; 加-r选项,首先显示最新的条目
Show auth.log equivalent by filtering on syslog facility:
$ sudo journalctl SYSLOG_FACILITY=10
0 kern 内核;1 user 用户;3 daemon 守护进程;
4 auth 授权;10 authpriv 授权;
$ sudo journalctl SYSLOG_FACILITY=0 -r
$ sudo journalctl -k -r
$ sudo journalctl SYSLOG_FACILITY=4 |wc -l
14516
$ sudo journalctl SYSLOG_FACILITY=10 |wc -l
9049
If the journal directory (by default located under /var/log/journal) contains a large amount of log data then journalctl can take several minutes to filter output. It can be sped up significantly by using --file option to force journalctl to look only into most recent journal:
$ sudo journalctl --file /var/log/journal/*/system.journal -f
5. 日志大小限制
默认为基础文件系统的10%,但上限为4GB。
例如本机/var/log/journal/位于30Gb分区上,日志最多需要3Gb。超过40Gb的分区,日志文件需要最大值都为4Gb。
可以通过取消注释和更改以下内容来控制持久日志的最大大小:
/etc/systemd/journald.conf
SystemMaxUse=50M
也可以使用drop-in snippets配置覆盖机制,而不是编辑全局配置文件。在这种情况下,将覆盖置于[Journal]标题下:
/etc/systemd/journald.conf.d/00-journal-size.conf
[Journal]
SystemMaxUse=50M
修改后重新启动日志系统 systemd-journald.service
6. 手动清理日志文件
删除已归档的日志文件,直到它们使用的磁盘空间低于100M:
$ sudo journalctl --vacuum-size=100M
使所有日记文件不包含超过2周的数据。
$ sudo journalctl --vacuum-time=2weeks
Linux-Journal相关推荐
- Linux: journal日志文件维护
清空 /var/log/journal 文件的方法 1.用echo命令,将空字符串内容重定向到指定文件中 echo "" > system.journal 说明:此方法只会清 ...
- Linux Journal 2013点评 Readers' Choice Awards 2013
Readers' Choice Awards 2013 资料来源于:http://www.linuxjournal.com/rc2013 加以整理 Best Linux Distribution ...
- Linux journal日志文件维护
前言 系统空间占用排查过程中,发现 /var/log/journal目录占用空间较大,我们来看一下这个 journal 目录下的文件是否真的可以删除. journal 目录是什么? journalct ...
- 2012《Linux杂志》读者选择奖 (Readers' Choice Awards 2012- Linux Journal)
作者 :http://www.linuxjournal.com 注释:http://www.znsystem.com/blog/ This post is from :http://www.linux ...
- LINUX应用与发展简介
学习linux也有一段时间了,对linux系统也有了更深的认识,今天就来总结一下到底什么是linux系统,以及简单介绍Linux系统的发展史与现在企业级别的应用. 顾名思义,linux是一种系统(OS ...
- 世界级安全技术专家力作——《Linux防火墙》
媒体评论 我看过数百部安全技术方面的著作,但本书可谓出类拔萃,我是一个FreeBSD用户,但在看过这本书后,我已在考虑在某些场合使用Linux了! --Richard Bejtlich,通用电气公司应 ...
- http://www.huihoo.com/ 灰狐网站 Linux 专业网站
.joyfire.net (2004.10.26) .车东开发笔记 (2004.10.26) .Linux一句话问答 (2004.02.09) .2003 Linux Journal Readers' ...
- linux操作系统学习网站整理(100个)
linux操作系统学习网站整理(100个) 评选出的这100个优秀站点,将按照下述20个类别作以评介: (一) 文件下载 (二) 幽默娱乐 (三) 相关新闻 (四) 通用硬体 (五) 专用硬体 (六) ...
- 深入Linux内核网络堆栈
前一段时间看到这篇帖子,确实很经典,于是翻出了英文原版再读,顺便再翻译出来供大家学习,这篇文章的中文版也早都有了,不过出于完全理解的目的,我还是将它翻译了出来,加进了自己的代码,虽然在上一周的翻译过程 ...
- Linux 2.4调度系统分析--转
http://www.ibm.com/developerworks/cn/linux/kernel/l-k24sch/index.html 杨沙洲 (pubb@163.net)国防科技大学计算机学院 ...
最新文章
- Select2 的简单使用
- SDCC 2015算法专场札记:知名互联网公司的算法实践
- 【错误记录】Google Play 上架报错 ( 此版本不符合 Google Play 关于提供 64 位版本应用的要求 )
- jdbc对mysql进行增删改查操作(Statement)
- windows docker常用命令
- Linux运维新主机挂载硬盘,linux运维:Linux下添加新硬盘+分区及挂载详细步骤图解...
- matlab算法用python做_机器学习笔记—朴素贝叶斯算法实现(matlab/python)
- 如何利用VUE动态添加class样式
- 用C++获取屏幕上某点的颜色
- Atitit 单片机与嵌入式系统原理与概念 目录 1. 寄存器、数据库,堆栈	2 1.1. 寻址模式	2 1.2. 指令	2 1.3. Watchdog 中断	2 2. 软件是如何影响硬件设计的	2
- 仿微信图片选取、相机拍照—PhotoPicker(已集成GalleryView)
- linux环境下刷机9008,LINUX下线刷修复变砖手机
- ftdi+usb转串口驱动+android,FTDI usb转串口驱动
- Vlmcsd: 自建 KMS 激活服务器
- 从GNU/Linux看国产操作系统的安全可控性
- 日有所思(4)——磁密,磁场强度,磁通量傻傻分不清
- 《中国垒球》:跨界联赛·完美落幕
- 语音播报警示器技术要求
- Flink流式计算框架中的窗口函数
- 把1,2,3,4,5,6,7,8,9九个数分成三组,各个数字使用一次
热门文章
- 区块链的意义和应用现状----新时代区块链研究院
- 仿5173游戏交易平台系统SQL注入(可直接脱裤)+Getshell
- 多图详解uefi+gpt安装win10系统,再也不用求人了!
- Java如何去除字符串中的HTML标签
- 利用区块链技术健全大数据价值流通体系
- 增压撬启停控制优化及纳入GE UCP控制系统可行性研究
- 标签平滑深度学习:Google Brain解释了为什么标签平滑有用以及什么时候使用它(SOTA tips)​...
- 提升工作效率的神器:电脑版番茄工作软件
- JAVA API文档中文版,网盘下载
- 站长导航系统源码-修复版