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

相关推荐

  • Windows 2012的IE增强的安全配置如何关闭

    1.我们用IE访问站点,经常出现IE警告信息,这是因为IE增强的安全配置引起的,要正常访问都需要勾选添加信任此网站。 2.下面来说下如何取消这个设置 找到,控制面板\所有控制面板项\管理工具\服务器管理器 3.点击“本地服务器”–“IE增强的安全配置 ”后面的“启用 4.再次打开IE,提示“Internet Explorer 增强的安全配置未启用…

    2022年7月2日
    1.1K00
  • 网站发现打开是404报错

    现象:今日再使用IIS部署网站发现打开是404报错 分析过程:首先判断web下是否缺失文件,默认文档配置是否正确,PHP模块映射配置是否正确,PHP版本是否有故障。 发现php manager中php版本未能选择,重新选择php版本报错 解决办法:  打开处理程序映射,使php的处理程序为fastcgi,即可修复成功!!!

    2022年12月8日
    1.6K00
  • Minio nginx配置https和http问题解决,疑难症全网首发

    以下问题基本上是因为NGINX代理出现 一、API直接返回单独的错误: io.minio.errors.ErrorResponseException: Access denied 二、API直接返回的错误:The request signature we calculated does not match the si 三、预览文件或者图片返回错误 以上三个…

    2023年10月18日
    3.3K00
  • 服务器出问题了,作为IT,怎样才能第一个知道?免得被骂

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

    2024年5月22日
    62300
  • 在linux中访问网站提示“Nginx 502 bad gateway”错误如何处理?

    问题原因 “Nginx 502 Bad Gateway”错误表示访问请求的php-cgi进程已经开始执行,但是由于读取资源失败等原因没有执行完毕,导致php-cgi进程终止。 常见的问题原因如下: 解决方案 您可以参考如下操作进行逐一排查。 说明 本文中/usr/local/php/etc/php-fpm.conf、/usr/local/php/etc/ph…

    2023年11月16日
    93000

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信