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

相关推荐

  • Windows server 2008 R2 服务报错14001解决方案

    错误 14001:因为应用程序的并行配置不正确 有关详细信息 请参阅应用程序事件日志 或使用命令行 sxstrace.exe 工具 今日通过服务管理器重新启动mysql服务时发现报错14001,解决方案如下: 打开左下角服务管理器,点击功能,然后添加功能,添加 Framework 3.51全部功能,这样就可以去服务管理器中启动服务了!!!

    2022年11月22日
    1.3K00
  • Windows挂载虚拟磁盘VHD/VHDX文件

    挂载VHD/VHDX 打开磁盘工具 WIN+R弹出运行窗口,输入:diskmgmt.msc命令,回车确认弹出磁盘管理工具 附加VHD/VHDX文件 可以看到已经添加到系统中,接下来就可以进行初始化操作 在系统中操作 打开我的电脑,可以发现多了一块磁盘 这个就是我们附加的vhdx文件。此时,已经可以对改vhdx文件进行操作了 分离vhdx

    2022年7月14日
    1.8K00
  • Linux SSH 登录失败多少次禁止该IP访问 防止暴力破解

    Linux 系统SSH 登录失败的内容会记录到/var/log/secure文件,通过查找关键字 Failed,可以定位到这些异常的IP地址,比如: 比如这里,明显这个IP地址在进行SSH 扫描,不断的更换端口和用户进行暴力测试。 在Linux里面有两个相关的文件: /etc/hosts.allow: 允许哪些IP访问主机 /etc/hosts.deny 禁…

    2023年3月1日
    1.2K00
  • 如何解决Windows server系统开机自动进入修复模式而无法正常启动的问题

    相信大家都会碰到这样一个问题,Windows系统重启之后自动进入修复而不去正常启动,如下图 那么我们该如何去解决呢 第一步:根据它的选项,进入到修复模式,然后点击下一步 第二步:输入登录的账户密码,然后就会有三个系统恢复的选项,我们选择命令提示符,依次输入以下命令 然后等待出现以下信息 到此,我们重新启动系统,就可以正常进入到桌面系统了,如果你想之后的系统重…

    2022年6月13日
    3.0K00
  • 常见的windows网络管理命令

    ipconfig命令 ipconfig实用程序可用于显示当前机器的TCP/IP配置。 tracert命令 路由追踪命令,用来显示数据包到达目的主机所经过的路径。 一般添加 -d 参数 ,不将地址解析为计算机名,加快路由速度 nslookup命令 nslookup命令可以指定查询的类型,可以查到DNS记录的生存时间还可以指定使用哪个DNS服务器进行解释。 ip…

    2022年6月10日
    1.1K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信