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无法使用Internet Explorer浏览器访问外部网站如何处理?

    问题描述 在Windows实例内无法使用操作系统自带的Internet Explorer浏览器访问外部网站,提示如下: 问题原因 在Windows实例内无法使用Internet Explorer浏览器访问外部网站,可能是如下原因导致: 解决方案 您可以通过以下步骤逐步排查,解决上述问题。 说明 以下操作步骤以Windows Server 2019 数据中心版…

    2023年11月16日
    1.1K00
  • Linux中查看服务器配置与文件时间的方法!

    查看服务器配置   Linux是服务器领域最喜欢的操作系统,因为它安全、稳定、灵活、开源,具备诸多独特的优势。那么Linux如何查看服务器配置?在Linux中,有很多命令可以检查服务器配置信息,接下来通过这篇文章介绍一下详细的方法。   Linux系统中有多种方法可以查看服务器配置,以下是几种常见的方法:   1、lscpu命令   此命令可显示有关服务器C…

    2024年6月26日
    1.6K00
  • linux centOS虚拟机出现entering emergency mode解决方案

    1、centos打开之后出现这个问题,迟迟打不开 按他的操作输入journalctl之后输入shift+g到日志最后查看报错发现是xfs(dm-0有问题) 输入xfs_repair -v -L /dev/dm-0因此修复 /dev/dm-0就可以了 -L 选项指定强制日志清零,强制xfs_repair将日志归零,即使它包含脏数据(元数据更改)。 #重启虚拟机…

    2024年1月11日
    1.2K00
  • zabbix用户密码忘记并找回

    解决方案: 1、登陆zabbix服务器,连接到mysql数据库 [root@localhost ~]# mysql -uroot -p     // -u 后面加用户名,-p 回车,输入数据库密码Enter password:   2、进入mysql数据库以后查询users表 MariaDB [(none)]> …

    2023年2月25日
    2.4K00
  • Pmail——仅用一分钟就可以搭建好一个邮箱服务器

    有一个自己的邮箱,是不是光想着就觉得很酷。在之前,我介绍过一个邮箱poste.io 的搭建过程。虽然说是用docker但是其实搭建起来还是挺麻烦的。今天再来介绍一个搭建简单的邮局系统 pmail。 项目的优势: 1、部署简单 2、资源占用极小 编译后二进制文件仅15MB,运行过程中占用内存10M以内。 3、安全方面 支持dkim、spf校验。正确配置的情况下…

    2024年7月2日
    3.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信