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.8K00
  • Windows实例内部自定义域名解析与本地网络域名解析不一致导致无法访问网站如何处理?

    问题描述 在Windows实例内部通过浏览器无法访问某网站,但在其他设备上可以正常访问,排查发现Windows实例内部自定义域名解析与本地网络域名解析不一致,具体说明如下: 问题原因 Windows实例内部和本地域名解析的IP地址不一致的可能原因如下: 解决方案 说明 本文操作以Windows Server 2019 数据中心版 64位中文版操作系统为例,其…

    2023年11月20日
    99400
  • centos 7 NTP 内网时间定时同步

    一、环境 二、ntp安装服务 server服务器配置: client服务器配置:(如果有多台client服务器,亦可如此配置) 四、启动NTP服务&开机启动设置(包括server服务器和client服务器) 五、server服务器防火墙配置 六、client服务器手动从server服务器进行时间同步 在server服务器上执行date命令,查看时间 …

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

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

    2023年11月20日
    80700
  • Linux系统部署BBR服务器加速软件

    一、BBR加速软件介绍  BBR简介:  BBR是谷歌的黑科技,也可以理解为用来加速网络的软件,如果服务器在海外,会发现丢包率很高,线路还会时断时续。所以,不用点黑科技,肯定是没办法使用。而BBR加速能充分利用网络带宽 BBR的作用就是尽量跑满带宽,并且尽量不要有排队的情况。BBR可以起到单边加速TCP连接的效果。通俗来讲就是最大化利用网络上瓶颈线路的带宽。…

    2023年12月1日
    97800

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信