三三世界-百宝箱

文章 分类 标签
130 9 247

公告

暂无站点公告

CentOS7-快速查看系统日志

三三 2022-02-17 1756 0条评论 Linux使用 centos日志

首页 / 正文

systemd拥有强大的解决与系统日志记录功能-systemd-journald。日志目录一般是在/var/log/journal,记录的是二进制文件,我们可以通过journalctl进行查看。

常用的操作

显示所有日志:

journalctl

查看启动只有的所有日志:

journalctl -b

查看最后20条日志

journalctl -n 20

跟踪日志

journalctl -f

带有指定关键字的日志

journalctl | grep "WARNING"

查看内核日志(不显示应用日志)

journalctl -k

查看系统本次启动的日志

journalctl -b
journalctl -b -0

查看上一次启动的日志需更改设置,如上次系统崩溃,需要查看日志时,就要看上一次的启动日志。

journalctl  -b -1

查看指定时间的日志

journalctl --since="2012-10-3018:17:16"
journalctl --since "20 minago"
journalctl --since yesterday
journalctl --since"2015-01-10" --until "2015-01-11 03:00"
journalctl --since 09:00 --until"1 hour ago"
journalctl --since"15:15" --until now

只显示冲突、告警和错误

journalctl -p err..alert

显示某个单元日志(也可以同时显示多个增加多个 -u nginx.service -u php-fom.service)

journalctl -u nginx.service

根据时间查找

journalctl --since "20 min ago" #查找20分钟前的日志
journalctl --since today #查找今天的日志
journalctl --until 2019-10-23 #查找2019-10-23日期的日志

查看指定服务的日志

journalctl  /usr/lib/systemd/systemd

查找指定客户(UID)日志

journalctl _UID=1000

**查看指定进程的日志**
journalctl   _PID=1

查看某个路径的脚本的日志

journalctl    /usr/bin/bash

查看指定用户的日志

journalctl _UID=33  --since today

查看某个Unit的日志

journalctl  -u nginx.service
journalctl  -u nginx.service  --since  today

实时滚动显示某个Unit的最新日志

journalctl  -u nginx.service  -f

合并显示多个Unit的日志

journalctl  -u nginx.service  -u php-fpm.service  --since today

查看指定优先级(及其以上级别)的日志

日志优先级共有8级

0: emerg
1: alert
2: crit
3: err
4: warning
5: notice
6: info
7: debug

显示不同级别的日志:

journalctl  -p err  -b
journalctl  -p err..alert -b

不分页标准输出日志

默认分页输出--no-pager改为正常的标准输出

journalctl  --no-pager

以JSON格式(单行)输出#

JSON(JavaScript Object Notation)是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScriptProgramming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集。JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java,JavaScript, Perl, Python等)。这些特性使JSON成为理想的数据交换语言。

JSON建构于两种结构:

“名称/值”对的集合(A collection ofname/value pairs):不同的语言中,它被理解为对象(object),纪录(record),结构(struct),字典(dictionary),哈希表(hash table),有键列表(keyed list),或者关联数组(associativearray)。

值的有序列表(An ordered list of values):在大部分语言中,它被理解为数组(array)。

这些都是常见的数据结构。事实上大部分现代计算机语言都以某种形式支持它们。这使得一种数据格式在同样基于这些结构的编程语言之间交换成为可能。

例子:
以JSON格式(单行)输出

journalctl  -b -u httpd.service  -o json

以JSON格式(多行)输出,可读性更好,建议选择多行输出

journalctl  -b -u httpd.service  -o json-pretty

显示日志占据的硬盘空间

journalctl  --disk-usage

指定日志文件占据的最大空间

journalctl   --vacuum-size=1G

指定日志文件保存多久

journalctl   --vacuum-time=1years

评论(0)

当前没有评论,还不快来留下第一个脚印吧


Copyright 2021 三三世界-百宝箱. All Rights Reserved.

最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年05月

   1234
567891011
12131415161718
19202122232425
262728293031 

文章目录

上一张 下一张