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

相关推荐

  • wordpress上传图片提示“缺少临时文件夹”的解决方法

    在wordpress发布文章上传图片时出现了“缺少临时文件夹”的错误提示,该错误通常是由于服务器php配置的原因,如果之前上传图片正常,而且最近操作过服务器就很有可能是php配置导致的错误,解决方法也很简单,修改一下php配置文件即可。 Linux主机: 1、编辑配置文件php.ini,搜索查找upload_tmp_dir,修改为: upload_tmp_d…

    2023年5月5日
    1.5K00
  • Linux下安装配置maven仓库

    1、安装wget命令 如果需要通过使用wget命令,直接通过网络下载maven安装包时,需要在linux系统中安装wget命令。 2、下载maven安装包 在/usr/local/下创建一个maven文件: mkdir /usr/local/maven 切换到安装目录,即新建的文件中: 下载安装: 3、解压缩maven 4、配置maven环境变量 添加环境变…

    2022年6月20日
    1.8K00
  • Linux查看磁盘UUID的几种方式

    查看/dev/disk/by-uuid目录命令: 可以查看系统全部磁盘挂载信息 blkid命令命令: 也可以指定磁盘查看,命令: tune2fs和dumpe2fs配合grep命令: 修改磁盘挂载ID,可以参考:https://help.aliyun.com/document_detail/199739.html挂载磁盘千万不要使用 这种方式,linux系统从…

    2023年7月28日
    1.2K00
  • 通过远程桌面连接Windows实例提示“远程连接计算机需要网络级别身份验证”怎么办?

    问题描述 使用远程桌面连接工具登录Windows系统的ECS实例失败,并提示“远程连接计算机需要网络级别身份验证”的报错,如下图所示。 问题原因 本地Windows主机的远程桌面连接工具版本过低,导致远程连接失败。 解决方案 下列操作以Windows Server 2012 R2 64位操作系统为例,其它版本的操作系统的配置可能有所差异,具体情况请参考相应操…

    2023年11月22日
    1.2K00
  • Hollywood – 给你的命令行加点魔法般的动画效果

    作为命令行的重度用户,你是否想让枯燥的终端界面来点生动有趣的元素?Hollywood来了!这是一个无比诙谐、小巧玲珑而又功能强大的动画效果命令行工具。 Hollywood可以为文本添加各种动画效果,让你的输出显示得像电影般生动活泼。它支持多种炫酷动画,并可深度自定义。本文将详细介绍Hollywood的安装使用、酷炫示例和高级技巧,让你快速上手,给终端加点魔力…

    2023年10月13日
    1.7K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信