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

相关推荐

  • 可以ping通Windows server 2003服务器,无法使用远程桌面登录的解决方法

    Windows系统远程不上有很多种问题,我们最常见的问题就是远程端口访问权限没打开、远程端口防火墙没放行等,所以我们在解决这类问题时,首先就需要查看访问权限、防火墙这两项是否设置正常 如何查看或者修改远程端口 有关于查看和修改远程端口的问题,大家可以去看我们的另外一篇文章,还有一点就是Windows系统更改端口的方法基本都是一致,都是通过修改注册表来实现的:…

    2022年6月20日
    2.7K00
  • 清华源连接失败原因与解决 CondaHTTPError SSLError

    Conda 清华源连接失败原因与解决 问题描述 在我设置好国内源之后,用conda创建虚拟环境,下载python版本时出现以下错误。 我的~/.condarc内容(即conda channels设置)如下 解决方案 在我查阅了多篇博客,尝试了多种方案之后,终于找到两种解决方案: 两种方法选一种即可 原因分析 https协议比http协议多了SSL,TLS等验…

    2023年3月23日
    2.0K00
  • Centos7安装telnet-server并升级安装Openssh9.0p1

    背景 HW之前漏洞扫描出来机器的一些OpenSSH安全漏洞,且当前的版本是OpenSSH_7.4p1, OpenSSH <7.5 属实有点老了 需求 更新至OpenSSH_9.0p1 更新OpenSSH前先安装telnet-server服务,防止意外发生 1、安装telnet-server服务 查看本机是否安装telnet客户端及服务端 [root@s…

    Linux系统 2023年1月20日
    95500
  • Linux系统之安装uptime-kuma服务器监控面板

    一、检查本地环境 1.1 检查本地操作系统版本检查本地操作系统版本 1.2 检查系统内核版本 检查系统内核版本 1.3 检查系统是否安装Node.js 检查系统是否安装Node.js 二、部署Node.js 环境 2.1 下载Node.js安装包 下载Node.js安装包 2.2 解压Node.js安装包 解压Node.js安装包 2.3 复制二进制文件 将…

    2023年9月21日
    1.1K00
  • Windows 2012 R2 64位中cmd命令修改用户名、用户密码、windows防火墙、禁ping

    windows中cmd命令 control userpasswords2 修改用户名 2 windows中cmd命令 net user 修改用户密码 输入命令“net user”回车,列出目前电脑所有用户。 选择需要更改密码的用户名,例如administrator, 使用命令  net user administrator 123  这里…

    2022年7月18日
    2.1K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信