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

相关推荐

  • IIS 的打开与重启

    windows普通版的启用 打开控制面板 启用IIS功能 控制面板 – 所有控制面板项,程序和功能窗口,左侧点击启用或关闭 Windows 功能 Windows 功能窗口,找到并勾选Internet Information Services 重启电脑 Windows Service版的启用 windows 2008 右键计算机,点击管理 在服务器…

    2022年7月15日
    1.5K00
  • VMware虚拟机安装Ubuntu24.04教程

    (一)Ubuntu镜像文件下载(选择Ubuntu桌面版)1、Ubuntu官方网站(1)Ubuntu官网:https://ubuntu.com(2)Ubuntu官网中文站:https://cn.ubuntu.com(3)Ubuntu24.04桌面端官方下载:https://ubuntu.com/blog/ubuntu-desktop-24-04-noble-n…

    2024年5月31日
    2.2K00
  • Docker部署MinIO对象存储服务器结合Cpolar实现远程访问

    前言MinIO是一个开源的对象存储服务器,可以在各种环境中运行,例如本地、Docker容器、Kubernetes集群等。它兼容Amazon S3 API,因此可以与现有的S3工具和库无缝集成。MinIO的设计目标是高性能、高可用性和可扩展性。它可以在分布式模式下运行,以满足不同规模的存储需求。 MinIO是一个开源的软件,可以免费使用,还可以在普通硬件上运行…

    2023年12月20日
    98400
  • Linux parted 分区命令详解

    一、概述通常我们用的比较多的分区工具是fdisk命令,但由于fdisk只支持MBR分区,MBR分区表最大支撑2T的磁盘,所以无法划分大于2T的分区。而parted工具可以划分单个分区大于2T的GPT格式的分区,也可以划分普通的MBR分区。 parted命令是由GNU组织开发的一款功能强大的磁盘分区和分区大小调整工具。GPT格式的磁盘相当于原来MBR磁盘中原来…

    2023年8月1日
    1.0K00
  • 设备 eth0 似乎不存在, 初始化操作将被延迟

    今天将eth0文件编辑好之后,不管是重启network还是重启电脑都没用,一直显示个eth1,我就很纳闷,明明没有eth1这个文件,eth1到底从哪里来的,网上好多方法都试过了还是不行,什么删除/etc/udev/rules.d/70-persistent-net.rules这个文件,然后重启电脑,没用!关闭NetworkManager服务,没用!有的甚至说…

    2023年3月2日
    1.1K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信