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

相关推荐

  • 成功解决:ubuntu下ifconfig不显示网卡信息

    方法一(临时) 或者 需要注意的是,以上两种方式只是临时性的,非永久性,下次重启还是会出现ifconfig没有网卡的现象 dhclient(DHCP client)为动态主机配置协议客户端。DHCP 客户端 dhclient 提供了一种使用动态主机配置协议 和 BOOTP 协议配置一个或多个网络接口的方法。如果这些协议失败,则通过静态分配地址来配置。 方法二…

    2023年6月21日
    2.3K00
  • Sql server windows nt 64bit 内存占用过高解决办法

    首先说明,如果单纯的就是内存不断慢慢增高,那您可以看这篇文章。配置一些sql server所占用的最大内存即可解决: 内存占用居高不下 现象:         1.重启sql服务后,sql服务以没秒100M的速度在吞噬着内存         2.用管理工具登录sql发现非常卡,很…

    2022年11月29日
    5.4K00
  • CentOS 7 安装 JDK 11

    现在很多编译器和软件都开始要求使用 JDK 11 了。 因此我们希望在 CentOS 上安装 JDK 11。 运行下面的命令: 如果你的系统中还装有不同版本的 JDK 的话。你需要运行: 来选择默认的 JDK。 随后你就可以验证安装的 JDK 了。

    2023年3月11日
    82300
  • Ubuntu 输入正确的密码后,黑屏一闪,重新返回到登陆界面问题解决

    一,问题描述: Ubuntu出现登陆界面后,选择用户名,输入密码,然后登陆画面消失,似乎要进入系统了;但很快,又出现了同样的用户登陆界面,再次选择用户名、输入密码,再次来到这个状态,形成一个死循环。 二,解决办法: 1.若是本地的虚拟机运行的服务: 在登录界面Ctrl+Alt+F1进入命令行界面: 先找到这个文件: /home/user/.xsession-…

    2023年11月29日
    1.6K00
  • 幻兽帕鲁服务器一键部署保姆教程

    普通一键部署(使用一键部署脚本) Windows 服务器一键部署 Windows的一键部署需要借助 PowerShell 来完成。PowerShell是一种任务自动化和配置管理框架,它提供了一个命令行Shell和脚本语言,用于管理和控制Windows操作系统和相关应用程序。那么要如何找到 PowerShell ?方法如下: 方法 描述 使用开始菜单 点击Wi…

    2024年1月30日
    76600

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信