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

相关推荐

  • 常见IIS错误解决方法

    1、错误号401.1症状:HTTP 错误 401.1 – 未经授权:访问由于凭据无效被拒绝。分析:由于用户匿名访问使用的账号(默认是IUSR_机器名)被禁用,或者没有权限访问计算机,将造成用户无法访问。解决方案:(1)查看IIS管理器中站点安全设置的匿名帐户是否被禁用,如果是,请尝试用以下办法启用:控制面板->管理工具->计算机管理->本地用户和组,将IUS…

    2022年11月25日
    1.2K00
  • 一个由MySQL安全插件引发的生产问题

    一、背景 生产环境下遇到一个问题,有数据库节点的连接数略高,触发了连接数告警。登录上查看后,发现实际业务压力不大。查看processlist发现有大量状态为“Waiting in connection_control plugin”的等待连接。 mysql> select ID,HOST,DB,COMMAND,TIME,STATE,INFO from …

    2023年3月6日
    99500
  • 幻兽帕鲁服务器版本更新

    幻兽帕鲁服务器游戏怎么升级版本?自建幻兽帕鲁服务器进入Palworld游戏提示“您正尝试加入的比赛正在运行不兼容的游戏版本,请尝试升级游戏版本”什么原因?这是由于你的客户端和幻兽帕鲁服务器版本不匹配,如何解决?更新幻兽帕鲁服务器即可解决。 幻兽帕鲁进行一次更新,服务器也需要同步更新,才能继续游玩。 Linux服务器更新 1、使用如下命令,首先切换至root用…

    2024年2月4日
    2.2K00
  • 电脑C盘内存满了怎么清理内存-七种方法轻松搞定!

    在我们日常电脑的使用中,可能会由于电脑运行产生了临时文件、下载以及安装软件的位置在C盘、系统更新后的文件能占用几个G的空间等因素,导致出现C盘内存爆满,不够用的问题,为了电脑可以流畅稳定运行,下面小编精心整理了七种清理C盘内存的有效方法! 方法一:运行磁盘清理   磁盘清理是一个 Windows 内置工具,允许您删除一些在 Windows 文件资源管理器中无…

    2024年6月5日
    1.6K00
  • docker image tag为什么出现none

    背景 公司项目是基于容器化架构设计,具体业务也拆成了多个微服务及对应了多个docker image镜像。研发环境中会频繁进行升级image镜像,导致出现很多image为 <none> 命名的镜像,这种也称为悬空镜像。 本篇文章将展示几种现象会导致这种情况发生。下文演示环境,版本信息如下: 现象一 前提条件:在同环境中两个镜像名称:tag都相同,imag…

    2023年10月20日
    97900

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信