Centos7系统如何查看系统日志

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

日志的配置文件是/etc/systemd/journald.conf。

常用的操作有哪些呢

显示所有日志

[root@localhost ~]# journalctl

查看系统本次启动只有的所有日志

[root@localhost ~]# journalctl -b
# 或者
[root@localhost ~]# journalctl -b -0
# 或者
[root@localhost ~]# journalctl -b 0

查看最后10条日志

[root@localhost ~]# journalctl -n 10

跟踪日志

[root@localhost ~]# journalctl -f

只显示冲突、告警和错误

[root@localhost ~]# journalctl -p err..alert

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

[root@localhost ~]# journalctl -u nginx.service

根据时间查找:

#  查找20分钟前的日志
[root@localhost ~]# journalctl --since "20 min ago"

#  查找今天的日志
[root@localhost ~]# journalctl --since today

#  查找2022-06-15日期的日志
[root@localhost ~]# journalctl --until 2022-06-15

#获取15:15到现在的日志
[root@localhost ~]# journalctl --since"15:15" --until now

journal的一些维护

#查看当前日志占用磁盘的空间的总大小
[root@localhost ~]# journalctl --disk-usage 

#指定日志文件最大空间
[root@localhost ~]# journalctl --vacuum-size=1G

#不分页标准输出,日志默认分页输出--no-pager改为正常的标准输出
[root@localhost ~]# journalctl  --no-pager

以上只列举了部分常见的使用方法,如果还想获取更多的使用方法,可以输入以下命令进行查看

[root@localhost ~]# journalctl --help
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
 ........

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/4804

(3)
郭靖的头像郭靖
上一篇 2022年6月15日 下午5:19
下一篇 2022年6月16日 上午11:06

相关推荐

  • Windows实例内部自定义域名解析与本地网络域名解析不一致导致无法访问网站如何处理?

    问题描述 在Windows实例内部通过浏览器无法访问某网站,但在其他设备上可以正常访问,排查发现Windows实例内部自定义域名解析与本地网络域名解析不一致,具体说明如下: 问题原因 Windows实例内部和本地域名解析的IP地址不一致的可能原因如下: 解决方案 说明 本文操作以Windows Server 2019 数据中心版 64位中文版操作系统为例,其…

    2023年11月20日
    1.2K00
  • Windows下安装Nginx错误总结

    别问我为啥非要在Windows上按照Nginx,问的话,回答就是:有这个需求 1:CreateFile()“xxxxx” failed (3: The system cannot find the path specified) 产生原因:创建文件xxxx异常了。大多数情况就是因为:安装目录中存在中文或者是空格 比如凯哥的就是因为存在空格。凯哥第一…

    2024年5月11日
    1.1K00
  • Redis数据备份与恢复

    一、备份 1、cmd命令下,找到redis安装目录 2、创建dump.rdb文件 该命令将在 redis 备份目录中创建dump.rdb文件。 3、查看备份路径 备份后的文件名:dump.rdb 二、恢复 1、将dump.rdb拷贝到目标机,备份文件的目录下 2、重启redis服务 3、打开客户端刷新就能看到新的数据了 PS: 如果电脑安装了两个redis客…

    2022年11月12日
    1.4K00
  • 服务器出问题了,作为IT,怎样才能第一个知道?免得被骂

    做运维的都知道,服务器出点问题,就够我们受的,轻则被骂,重则丢饭碗,所以,每逢节假日,我们恨不得在机房点上三柱香、贴上几张符,给服务器和网络设备跪拜一番,求它们别出问题,也让我们过个清闲的假日。 然而,服务器虽然有一两颗火热的心,但是他们出起问题来,却都是冰冷冷的,一点都不讲情面,总是留下我们在机房凌乱而慌张。 所以,给服务器配置邮件告警,让它有小问题的时候…

    2024年5月22日
    83500
  • ubuntu 使用 ifupdown管理网络连接

    由于需要批量永久修改IP,研发提供的脚本是基于修改interfaces的,所以需要使用ifupdown,高版本的ubuntu使用的都是NetworkManager 卸载 NetworkManager 可能会影响你的网络连接配置,因此在卸载之前确保有其他方式管理网络连接。 步骤 1:备份当前配置 在卸载 NetworkManager 之前,最好备份当前的网络配…

    2024年5月21日
    1.4K00

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信