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

相关推荐

  • Linux Centos 7.6修改ssh端口为49527,并添加防火墙例外,修改root密码, 设置禁ping,搭建FTP站点 ,修改yum源。

    1.修改ssh端口为49527,并添加防火墙例外 (1). 修改ssh配置文件  /etc/ssh/sshd_config,将端口号修改为49527.同时保留ssh默认的22端口,为了防止修改端口号失败以后,远程登录不上服务器,如图1所示: (2).修改firewall配置 默认情况下,防火墙在没有配置任何策略集情况下,是禁止所有ip地址和端口号同行的,因此…

    2022年7月18日
    1.7K00
  • Centos下五大步安装Python

    一、下载Python包 网上教程大多是通过官方地址进行下载Python的,但由于国内网络环境问题,会导致下载很慢,所以这里建议通过国内镜像进行下载 例如:淘宝镜像 http://npm.taobao.org/mirrors/python/ 大部分版本和各系统包都提供,这里的教程用Python3.9.6来举例: Linux可以通过wget命令进行下载(在任意目…

    2022年6月17日
    1.5K00
  • 用户管理命令

    useradd 命令 创建普通用户 指定uid和组 创建用户,禁止登录且不创建家目录 使用 -M -s 参数 userdel命令 删除用户与相关文件 案例 passwd命令 passwd命令修改用户密码和过期时间等,root可以改普通用户,反之不可以 一条命令设置密码,企业常用 echo “密码” | passwd — stdin 用户名 –s…

    2022年6月11日
    1.4K00
  • Python爬虫进阶:爬取在线电视剧信息与高级检索

    简介:        本文将向你展示如何使用Python创建一个能够爬取在线电视剧信息的爬虫,并介绍如何实现更高级的检索功能。我们将使用requests和BeautifulSoup库来爬取数据,并使用pandas库来处理和存储检索结果。 一、爬取在线电视剧信息 首先,我们需要找到一个提供电视剧信息的网站,并确保我们可以合法地爬取这些数据。 代码实现: 二、实…

    2024年2月27日
    1.5K00
  • 解析Vue中的虚拟DOM与Diff算法:提升性能的利器

    前言 vue中的diff算法时常是面试过程中的考点,本文将为大家讲解何为diff以及diff算法的实现过程。那么在了解diff之前,我们需要先了解虚拟DOM是什么? 虚拟DOM 虚拟 DOM (Virtual DOM,简称 VDOM) 是一种编程概念,意为将目标所需的 UI 通过数据结构“虚拟”地表示出来,保存在内存中,然后将真实的DOM与之保持同步。具体来…

    2024年3月22日
    1.2K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信