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修改limits.conf不生效

    一、修改方法 1.临时方法 为了优化linux性能,可能需要修改这个最大值。临时修改的话ulimit -n 204800就可以了,重启后失效。 2.永久生效方法 (1)、修改/etc/security/limits.conf文件 在文件末尾添加如下内容,然后重启服务器或重新登录即可生效。重启后用查看命令进行查看,如果显示数字等于204800即证明修改成功。如…

    2024年5月14日
    1.8K00
  • CentOS 添加(永久)静态路由的方法总结

    一、使用 route 命令加入临时路由,重启后将失效 route 命令参数: 二、在 Linux 中添加永久路由的方法 1. 默认网关 (1)写入 ifcfg 文件(推荐) vi /etc/sysconfig/network-scripts/ifcfg-eth0 在配置 ip 地址的时候直接将 GATEWAY 的配置写入 ifcfg 文件。形式:GATEWA…

    2023年9月5日
    1.9K00
  • OpenSuSe15.4以Server模式安装配置网络

    配置静态ip地址 编辑/etc/sysconfig/network/ifcfg-xxx (xxx是网卡设备名),此处是ifcfg-eth0 主要是为了实现静态ip的需求 配置网关 在ifcfg-xxx中配置GATEWAY是无效的,需要编辑/etc/sysconfig/network/routes 主要解决无法访问外网的问题,常见问题: ping 一个公网ip…

    2022年11月23日
    1.9K00
  • 如何处理CentOS Failed to load SELinux policy

    CentOS 7在启动时,卡在进度条界面一直进不去系统,如下图所示: 我们可以通过按键盘的左右方向键,可以看到提示“Failed to load SELinux policy.”,这就是造成系统一直卡住无法正常启动的原因。 原因 是因为没有正确修改系统的selinux的配置,导致系统在启动时报selinux的错误 解决方案 第一步:先重启CentOS7操作系…

    2022年6月15日
    2.3K00
  • 服务器中挖矿木马病毒如何解决(kswapd0进程使cpu爆满)

    现象:系统cpu持续使用过高,造成无法远程连接 分析过程:一开始机器不能远程登录,但又能够ping通,登录信息也没有修改过,判断可能远程登录服务故障,后登录机器top发现,cpu使用率百分百,这很不正常,上面只运行了一个网站与数据库,发现异常进程kswapd0,查找资料后发现其是挖矿程序 解决方案:排查kswapd0进程 top 执行命令 netstat -…

    2022年12月13日
    2.6K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信