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

相关推荐

  • Linux 实用工具 Screen —— 再也不怕因为网络连接中断杀死任务了!

    不知道小伙伴们是否遇到过这样的场景: 有时候,我们本地通过 SSH 连接到远程服务器并不是很稳定,经常会断开连接。如果此时我们正在做类似更新系统、DD 系统、远程传输 / 下载文件等需要一定时间的操作,就会非常难受,好不容易传了半天的文件,中断了,又得重新来传一次,还得祈祷这次别传一半断开了。 今天我们介绍的这个工具 ——screen,就是为了来解决上面这些…

    2023年11月9日
    92000
  • Windows 10 共享打印机出现0x00000709报错

    在共享端主机上进行操作 新建记事本文档,输入如下内容: 然后保存,修改文件扩展名为reg,比如1.reg,然后双击这个文件导入注册表即可解决问题。

    2022年12月13日
    1.2K00
  • frp配置多端口内网穿透?frp多端口怎么配置?

    FRP内网穿透应用场景:本地Web服务外网访问、本地开发微信、本地联调支付宝\微信支付、TCP/UDP端口转发 在本机开发好的网站想让客户测试不在需要上传到服务器上面,使用FRP内外网穿透轻松解决;微信开发也不需要在上传到服务器,使用免费FRP内网穿透服务器帮您解决80端口问题,实现微信服务器直接访问到您本机web服务。 使用frp作为内网穿透的时候,有时候…

    2024年5月10日
    1.0K00
  • MySQL 用户管理和权限管理

    在项目中,一个数据库有很多人需要使用,不能所有的人都使用相同的权限,如果人比较多,一人一个用户也很难管理。一般来说,会分超级管理员权限,管理员权限,读写权限,只读权限等,这样方便管理。当然,具体怎么管理权限根据实际情况来确定。无论如何,都需要创建多个用户来管理权限。root 是数据库的超级管理员用户,对于普通开发人员来说,权限太大了,如果不小心做了一些不可逆…

    2022年6月9日
    1.5K00
  • 禅道安装

    禅道介绍 禅道项目管理软件是国产的开源项目管理软件,专注研发项目管理,内置需求管理、任务管理、bug管理、缺陷管理、用例管理、计划发布等功能,实现了软件的完整生命周期管理。 禅道属于开源项目,有收费版,本次以开源版9.1.2进行搭建 禅道官网:http://www.zentao.net/ 提示:本地环境我们没有安装mysql,安装禅道环境需要LNMP或者LA…

    2023年4月27日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信