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

相关推荐

  • Windows10 此用户无法登录,因为该账户当前已被禁用

    当我访问同事电脑共享文件夹时,弹出如下提示框:(可以在命令提示符上ping通,就是死活不能访问) 网上的那些置顶解决办法我就不说了,什么修改本地策略、安全策略,什么关闭防火墙啦、什么打开网络发现啦……..    压根球用没有!!我这里用的是找得小众化的偏方: 1、打开控制面板; 2、选择用户账户; 3、打…

    2023年2月17日
    1.9K00
  • Pantum打印机连接教程

    1、点击文章末尾的下载文件,下载驱动 2、解压文件后双击执行程序,进行安装,勾选同意后进入下一步 3、选择手动安装 4、选择对应的驱动版本M6518,选择有线网络连接 5、等待程序搜索打印机,如果没有找到打印机,选择手动添加IP,输入192.168.1.66,点击下一步,等待安装 6、此时安装成功 7、在wps中选择对应的打印机M6518,然后点击打印 相关…

    2023年8月3日
    1.4K00
  • 通过 Linux 命令行连接远程 Windows 系统

    安装 xfreerdp 在使用 xfreerdp 之前,您需要安装它。在大多数 Linux 发行版中,您可以使用包管理器来执行此操作。 在 Ubuntu / Debian 和 Linux Mint 上,运行以下命令 基于 RHEL 的发行版,如 Rocky Linux、AlmaLinux 和 Fedora,运行以下命令 使用 xfreerdp 远程连接 Wi…

    2023年9月20日
    1.2K00
  • Windows 2008实例更新补丁出现“8000FFFFwindows update 遇到未知的错误”报错如何处理?

    问题描述 Windows 2008实例更新补丁时出现“8000FFFFwindows update 遇到未知的错误”报错,如下图所示。 问题原因 由于系统的C盘没有设置Users权限,导致系统无法正常安装更新的补丁。 解决方案 方案一 方案二 如果方案一无法解决问题,请参考以下操作步骤。

    2023年11月20日
    81900
  • atop:监控Linux系统资源与进程

    命令简介 atop 命令是一款监控 Linux 系统资源与进程的工具,非内部命令,需要安装。 atop 是以一定的频率记录系统的运行状态,所采集的数据包含系统资源(CPU、内存、磁盘和网络)使用情况和进程运行情况,并能以日志文件的方式保存在磁盘中,服务器出现问题后,我们可获取相应的atop日志文件进行分析,atop是一款开源软件。 语法格式 选项说明 进程图…

    2023年9月5日
    99800

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信