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

相关推荐

  • mysql connect unblock with mysqladmin flush-hosts

    原因同一个ip在短时间内产生太多(超过max_connect_errors的最大值)中断的数据库连接而导致的阻塞。 查看 max_connect_errors show variables like ‘max_connect_errors’; 解决前提:需要换一个IP地址连接 方法一增大 max_connect_errors set …

    2024年2月21日
    95100
  • Nginx 代理多个服务器(多个server方式)

    1.介绍 1.1 背景介绍 如果每台linux服务器只运行了一个小网站,那么人气低,流量小的草根站长需要承担高额的服务器租赁费,也造成了硬件资源浪费。 虚拟主机就是将一台服务器分割成多个“虚拟服务器”,每个站点使用各自的硬盘空间,由于省资源,省钱,众多网站都使用虚拟主机来部署网站。 虚拟主机的概念就是在web服务里的一个独立的网站站点,这个站点对应独立的域名…

    2022年6月23日
    1.7K00
  • 使用PowerShell管理文件访问权限

    文件和目录的权限管理是一项复杂且耗时的工作,尤其是在Windows环境中,windows环境中,文件和目录权限管理使用图形化界面进行标准操作。但Powershell将能使这项工作更快更容易。 Powershell能够完成权限管理的哪些操作呢 列出文件和目录权限设置 添加文件和目录权限 移除文件和目录权限 修改文件和目录的属主 启用和禁用目录的继承属性 列出N…

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

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

    2023年11月29日
    2.3K00
  • CentOS图形化界面和命令行界面的转化–超详细(Linux操作系统)

    对于我这样的小白来说,Linux系统的图形化界面更加简单,但是Linux命令行才是精髓,如何进行转化呢? 1、快捷键方式切换(较为简单) 图形化界面转化成命令行界面  ctrl+alt+F3 命令行界面转化为图形化界面 ctrl+alt+F1 2、命令行形式切换切换成命令行模式: systemctl set-default mu…

    2023年12月13日
    1.4K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信