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

相关推荐

  • Linux Centos 7.6修改ssh端口为49527,并添加防火墙例外,修改root密码, 设置禁ping,搭建FTP站点 ,修改yum源。

    1.修改ssh端口为49527,并添加防火墙例外 (1). 修改ssh配置文件  /etc/ssh/sshd_config,将端口号修改为49527.同时保留ssh默认的22端口,为了防止修改端口号失败以后,远程登录不上服务器,如图1所示: (2).修改firewall配置 默认情况下,防火墙在没有配置任何策略集情况下,是禁止所有ip地址和端口号同行的,因此…

    2022年7月18日
    1.7K00
  • 用plink批量验证ssh免交互登录

    我系统里的plink.exe是VMware自带的 C:\Program Files (x86)\VMware\VMware vCenter Converter Standalone\plink.exe 语法:plink.exe -ssh -P your_port -pw “password” username@your_host cm…

    2024年5月30日
    1.1K00
  • Zabbix的Mysql数据库内存占用高问题分析与处理

    问题:1、Zabbix内存使用率高;2、MariaDB没有开启独享表空间 ibdata1是InnoDB的共有表空间,默认情况下会把表空间存放在一个文件ibdata1中,会造成这个文件越来越大. 原因1:使用InnoDB共享表空间存储数据 参数innodb_file_per_table,控制innodb引擎采用共享表空间存储还是独立表空间存储。 参数innod…

    2022年12月30日
    1.4K00
  • Linux安装青龙面板 稳定版超级详细

    一.安装docker容器 1.工具安装 复制所有代码然后直接右键粘贴进去 中间过程输入y 回车 yum install docker-io –y 这里输入y 安装成功之后是这个样子 输入以下代码回车 systemctl start docker 复制粘贴下面命令回车 docker ps 如果显示下图 即为成功 二.安装青龙面板 1.安装面板 (想改青龙面板端…

    2022年6月22日
    3.2K00
  • Win10 Edge浏览器无法使用内置管理员打开解决办法

    在Win10系统中我们经常会遇到这样的问题,应用打不开,提示无法使用内置管理员帐户打开此应用,今天有用户也遇到了Edge浏览器打不开的问题,一样的情况,这是由于Win10的特殊权限机制导致的,大家一般都会使用Administrator这个内置管理员帐户,想要打开应用还需要设置一下,具体看看下面解决方法。 解决方法一:还原UAC设置 1.打开win10系统的控…

    2023年12月1日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信