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登录界面死循环怎么办

    在使用Windows 10操作系统的过程中,我们可能会遇到一些意想不到的问题。其中之一就是登录界面陷入死循环,这导致很多小伙伴都无法正常的进入到系统中,那么应该怎么办呢?其实解决起来也并不困难,下面就和小编一起来看看吧。   方法一   1. 首先重启电脑并且按住键盘的“shift”键。   2. 接着依次点击查看高级修复选项>疑难解答>高级选项…

    2024年6月7日
    1.5K00
  • Centos7安装postgresql数据库

    1.更新源 2.安装postgresql 3.初始化数据库 4.启动数据库并设置开机启动 5.登录postgresql并设置密码 postgresql在安装时默认添加用户postgres 输入 psql 进入数据库是这样的 设置密码: 退出按:q 备注其他:列出所有库l 列出所有用户du 列出库下所有表d 6.重启数据库: 7 创建数据库跟用户 因为post…

    2023年4月11日
    1.3K00
  • Grafana如何自定义告警消息

    以下是一个使用pushgateway获取磁盘健康状态的报警消息。 可以看到,grafana默认的模板有很多无用内容。 获取数据 在grafana的报警预览中,只有state和info两个列显示。 info内容看起来是一个键值对类型的数据,其实只是一个字符串,无法从中获取我们想要的键值对。 我们通过go templete语法,提取字符串里的数据。 将该内容填写…

    2022年12月8日
    3.9K00
  • 服务器出问题了,作为IT,怎样才能第一个知道?免得被骂

    做运维的都知道,服务器出点问题,就够我们受的,轻则被骂,重则丢饭碗,所以,每逢节假日,我们恨不得在机房点上三柱香、贴上几张符,给服务器和网络设备跪拜一番,求它们别出问题,也让我们过个清闲的假日。 然而,服务器虽然有一两颗火热的心,但是他们出起问题来,却都是冰冷冷的,一点都不讲情面,总是留下我们在机房凌乱而慌张。 所以,给服务器配置邮件告警,让它有小问题的时候…

    2024年5月22日
    80900
  • 糟了,域帐户不小心误删除了,怎么办?莫慌,教你快速恢复域帐户

    大清早就接到求救电话,干我们这行真是没谁了,都快跟消防队救火差不多了。某网管急吼吼地在电话那头喘着粗气,估计有点慌:“早上特地早点到公司维护一下服务器,谁知道手一抖,删错一个域账户,那是我们财务总监的,要是恢复不了,等他来了,我就要回家待业了。” 笔者:“慌什么?没听说过么?遇到事情不要慌,先发一个朋友圈。要淡定。以后没事不要删除域账户,离职的员工就停用域账…

    2024年5月20日
    89800

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信