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

相关推荐

  • Nginx优化与防盗链技术

      在当今互联网时代,网站的性能和安全性变得尤为重要。Nginx作为一种高性能的HTTP和反向代理服务器,因其轻量级、高效能和灵活性而被广泛应用于各类网站和应用中。然而,随着互联网流量的不断增长和网络袭击的日益猖獗,如何优化Nginx服务并有效防止盗链成为了每个网站管理员必须面对的重要课题。   Nginx的优化不仅仅是为了提升网站的响应…

    2024年6月27日
    1.3K00
  • Ping命令详解

    命令简介 ping 命令是 Linux 系统中一个非常常用的网络命令。ping 命令主要用于测试网络的连通性,也可用于测试网络的性能和主机的响应能力。 日常工作中,我们经常会遇到网页无法打开、网址无法请求的情况。这个时候我们的一般操作是 ping 一下网址,比如 ping baidu.com 使用 …

    2023年1月4日
    79400
  • Windows系统批量绑定删除多IP以及Linux系统批量绑定IP

    一、Windows系统 1.1个IP绑定 在网络连接中,选择更改适配器设置,选择本地连接,右键属性,选择Internet 协议版本4双击打开。 在其中选择”使用下面的IP地址”,填写相关信息,确认即可 2.2个IP的绑定 点击IPV4属性中的高级,选择IP地址的添加,添加IP地址及子网掩码即可 3.多个IP的绑定 使用命令,打开cmd…

    2022年6月9日
    1.8K00
  • 如何在 Ubuntu 22.04 上启用 BBR?

    由于购买的VPS或者主机数据中心都在国外,经常会发生网络拥堵的情况,我们可以通过启用BBR来优化。 在Ubuntu系统上启用BBR可以提升网络连接速度,优化网络拥堵情况。 BBR代表瓶颈带宽,RTT是拥塞控制系统。 您可以在 Linux 桌面上启用 TCP BBR 以改善整体网上冲浪体验。 默认情况下,Linux 使用 Reno 和 CUBIC 拥塞控制算法…

    2024年3月12日
    1.4K00
  • Git:合并多个commit 的高级技巧

    前言 在我们的日常项目开发中,git commit -m 无疑是使用最频繁的指令,这也造成了大量的commit 在我们的分支上。这样常常会带来分支过长、版本过多的问题。 正文 想要解决这个问题,我们通常会对commit 进行合并。 当我们发现两个commit 或多个commit 存在很强的关联性、并且几个commit 加起来也可以成为一个完整的描述的时候,就…

    2023年3月15日
    1.4K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信