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

相关推荐

  • docker搭建ELK日志平台

    ELK 是三个开源项目的首字母缩写,这三个项目分别是:Elasticsearch、Logstash 和 Kibana。 由于Logstash占用的资源比较大,我们选择filebeat这个轻量级的日志收集工具来代替Logstash 一、安装ELK 首先,我们通过docker-compose来安装单机版elasticsearch和kibana。 创建docker…

    2023年1月13日
    1.4K00
  • Kswapd0挖矿病毒查杀

    机器负载异常,刚重启过后CPU占用就快速上升至接近100%,且存在网络滥用的情况。使用top显示kswapd0进程疯狂占用cpu,google后有人说是linux虚拟内存的问题,但是系统刚开机,内存基本空闲,只是cpu疯狂被占用,这种说法明显有问题,继续排查后,我发现这个程序和一个名叫WachtdogsMiner的挖矿蠕虫和两个荷兰IP有关 查找病毒 使用t…

    2022年6月25日
    1.4K00
  • Windows远程桌面出现CredSSP加密数据修正问题解决方案

    问题现象: 解决方案:方案一:1、win+R打开运行窗口 2、输入gpedit.msc命令,点击“确定” 3、依次展开“计算机配置”->“管理模板”->“系统”->“凭据分配”设置名称: 加密数据库修正 4、双击“加密数据库修正”,将状态改为“启用”,保护级别改为“易受攻击”,应用—>确定 方案二:1、win+R打开运行窗口 2、输入regedit命令,点击…

    2023年7月28日
    1.1K00
  • 通过远程桌面连接Windows系统的ECS实例时,提示“远程桌面连接已断开”错误怎么办?

    问题描述 通过远程桌面连接Windows系统的ECS实例时失败,并提示“远程桌面连接已断开”错误,具体显示如下图。 问题原因 通过VNC登录Windows实例,进入事件查看器查看系统日志,提示“终端服务器安全层在协议流中检测到错误,并已取消客户端连接”的错误,该问题可能是由于ECS实例的注册表中Certificate子键损坏导致的。 解决方案 本文操作以Wi…

    2023年11月15日
    1.1K00
  • IIS怎么设置应用程序池自动回收

    1、打开 IIS 管理控制台,双击“应用程序池”文件夹。 2、右击适当的应用程序池,然后单击“高级设置”。出现应用程序池的属性对话框。 3、默认回收是有一个固定时间间隔的,但是太长了 4、点击特定时间后面的三个点 5、然后点击添加按钮,接着在Value里面设置时间点,如下图所示 6、最后可以设置多个时间点,如下图所示

    2022年8月9日
    2.2K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信