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

相关推荐

  • centos7 shell 支持中文显示

    其实很简单,让 shell 支持 utf8 即可。先使用locale命令看一下设置情况: LC_ALL没有设置,需要赋值en_US.UTF-8,很简单: 最后,不要忘了source一下bash_profile,让其生效。

    2023年3月14日
    1.7K00
  • 服务器bash进程占用cpu过多疑似中挖矿病毒记录

    发现过程因为我有使用conky的习惯,也就是在桌面上会显示cpu和内存的占用情况,由于服务器不止我一个人使用,最近发现好几次我同学的账户下的bash进程占用特别多,问了他之后,他也说他几次都是没有使用过bash相关服务,之前一直以为可能是某个软件bug之类的,这次想着好好查一下 排查过程 使用top可以看出zhy用户的bash进程cpu和内存占用都非常多,这…

    2024年3月22日
    1.9K00
  • 指定端口被system程序占用解决方法

    一:查看指定端口占用PID 根据PID在进程中我们找到被system的进程占用 二:解决指定端口被占用

    2023年10月18日
    2.2K00
  • PVE8开启vgpu显卡虚拟化(基于Tesla P4)

    Tesla系列显卡真是垃圾佬的福音,很久以上上万的卡,现在几百块就能收到,不仅可以炼丹,还可以玩游戏,甚至可以给PVE用作vgpu,来实现云桌面,云游戏。博主先后买过P40和P4,面对250W功耗的24G显存的P40,显然它更适合炼丹,P4 TDP 75W,1060的性能表现,它的最佳用途其实不是个人桌面的游戏显卡,而是虚拟化云主机使用,而搭配上一台低功耗主…

    2024年2月26日
    3.3K00
  • Win10彻底永久关闭自动更新

    在使用Win10系统的过程中,经常会遇到系统提示自动更新的问题,时不时就要更新,非常烦人。其实我们可以关闭自动更新功能,这样就不会收到系统提示了。下面小编就给大家分享一下Win10彻底永久关闭自动更新的方法。 一、禁用Windows Update服务   1、同时按下键盘 Win + R,打开运行对话框,然后输入命令 services.msc ,点击下方的“…

    2024年6月11日
    2.2K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信