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

相关推荐

  • Win10共享文件夹无法访问怎么办

    无论是学习还是工作我们都会去设置共享文件来使用,不过难免也会遇到无法打开或者使用共性文件夹的情况,而这一般是系统设置出现问题,而以下是小编所带来几种解决win10不能共享文件夹的解决方法,一起来看看吧。   Win10无法打开共享文件的解决方法   方法一   1. 首先在Windows10电脑上按下Win+R组合键,打开运行窗口,输入命令services.…

    2024年6月11日
    1.8K00
  • Xcopy-windows命令行复制命令详解

    XCOPY是COPY的扩展,可以把指定的目录连文件和目录结构一并拷贝,但不能拷贝系统文件;使用时源盘符、源目标路径名、源文件名至少指定一个;选用/S时对源目录下及其子目录下的所有文件进行COPY。除非指定/E参数,否则/S不会拷贝空目录,若不指定/S参数,则XCOPY只拷贝源目录本身的文件,而不涉及其下的子目录;选用/V参数时,对拷贝的扇区都进行较验,但速度…

    2023年6月9日
    1.8K00
  • 如何在Ubuntu中禁用和启用CPU内核?

    在某些情况下,您可能需要在Ubuntu操作系统中禁用或启用CPU内核。禁用CPU内核可以帮助您降低功耗,提高性能或解决一些与硬件和软件兼容性相关的问题。本文将介绍如何在Ubuntu中禁用和启用CPU内核的方法。 方法一:使用GRUB配置 GRUB是Ubuntu的引导加载程序,您可以通过编辑GRUB配置文件来禁用或启用CPU内核。 这将禁用非核心时钟事件。 方…

    2024年5月24日
    1.4K00
  • MySQL 如何使用离线模式维护服务器

    离线模式 作为 DBA,最常见的任务之一就是批量处理 MySQL 服务的启停或其他一些活动。在停止 MySQL 服务前,我们可能需要检查是否有活动连接;如果有,我们可能需要把它们全部杀死。通常,我们使用 pt-kill 杀死应用连接或使用 SELECT 语句查询准备杀死语句。例如: MySQL 有一个名为 offline_mode 的变量…

    2023年10月20日
    1.4K00
  • kali系统登录密码忘了如何进行重置

    如果你的kali系统密码忘记了,又不想重装系统,那么,你可以通过如下几个步骤来强制重置root密码 第一步:在启动kali系统之后会进入到一个引导界面,然后我们需要按“e”来进入启动前的编辑命令,若你在开机时没有出现如下界面,你可以连续按上下键来阻止系统正常启动,以此来进入这个开机引导界面。 第二步:按“e”进入到启动前编辑命令界面后,找到以下内容,并做一定…

    2022年6月13日
    3.9K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信