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 升级后 模块无法使用提示报错,ngx_stream_module.so” version 1014000 instead of 1016000

    原因: nginx 1.16 升级到 1.19 后 ,重启nginx 后提示报错 报错内容: ngx_stream_module.so” version 1014000 instead of 1016000 , 方法: 1、网上的讲法 都是是让你卸载 yum remove nginx-mod* 再安装 yum install nginx-modu…

    Linux系统 2023年2月3日
    75200
  • yum 安装部署 docker-ce

    一、yum安装Docker 本案例要求配置本地yum源并安装Docker: 准备1台虚拟机,IP为192.168.137.100, 网络设置为NAT模式 安装docker 关闭防火墙 关闭SELINUX 实现此案例需要按照如下步骤进行。   步骤一:配置yum源 1、Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提…

    Linux系统 2023年2月8日
    76500
  • Docker常用命令

    列出所有容器ID 查看所有运行或者不运行容器 停止所有的container(容器),这样才能够删除其中的images: 如果想要删除所有container(容器)的话再加一个指令: 查看当前有些什么images 删除images(镜像),通过image的id来指定删除谁 想要删除untagged images,也就是那些id为的image的话可以用 要删除全…

    2022年11月19日
    74400
  • 关于编码你必须知道的知识和技巧

    乱码问题是所有运维职业生涯中都会遇到的问题,本篇文章带你探究背后的原理以及解决的技巧 字符编码 我们知道计算机只认识二进制数据,其他格式的数据都需要转换成二进制才能被计算机处理,也就是说我们在计算机上看到的文本、视频、可执行程序等格式的文件,最终都会转换成二进制数据交给计算机处理 计算机中最小的数据单位是bit,也叫二进制位,每一个bit都有0和1两种状态,…

    2023年1月16日
    84800
  • 文件传输工具WinSCP的安装与使用

    安装 首先下载软件,下面是WinSCP的下载网址 Download WinSCP 5.19.4 – free – latest version 下载完成后打开安装并接受许可协议 这里我们可以选择自定义安装,若是完整升级安装类型默认安装位置是C盘,接着下一步 若选择自定义安装则会有选择安装位置的窗口,若选择完整升级类型则为直接安装窗口【…

    2023年1月4日
    85200

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信