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

相关推荐

  • 解决crond引发大量sendmail、postdrop进程导致内存使用过大问题

    现象:客户反馈机器卡顿,上面只运行了一个宝塔,疑似中了木马 分析过程:top发现内存使用过高,ps -aux发现大量postdrop、sendmail、crond进程,而postdrop是由sendmail启动的,sendmail是由crond启动的。 crond在执行脚本时会将脚本输出信息以邮件的形式发送给系统用户,所以必然要调用sendmail,而sen…

    2022年12月6日
    1.8K00
  • Centos下配置JDK环境-支持JDK所有版本(超详细过程)

    前言 配置jdk环境,本人写了两种方案进行配置,当然也最推荐第一种方案。 下载JDK都是免费的,JDK各个版本的下载地址为:https://www.oracle.com/java/technologies/javase-downloads.html 本文以JDK 8为例,操作系统以CentOS7.6为例,CentOS7的所有系统都是相同的操作。 一、环境 首…

    2022年6月17日
    2.5K00
  • CentOS添加永久路由方式

    1. CentOS7添加永久路由   ● 方式一:  执行以下命令打开路由配置文件进行编辑: 这里的<interface>是指您要添加路由的网络接口,例如eth0或ens33  在文件中添加路由规则,例如: 其中<gateway>是默认网关的 IP 地址,<interface>是网络接口的名称  例如: 保存并关闭文件,执行以下命令重启网络…

    2023年12月5日
    92200
  • 创建物理卷报错Can‘t open /dev/sdb1 exclusively. Mounted filesystem?以及对应的解决方法

    在将几块盘做LVM时,遇到一个之前都没遇到过的问题: 首先第一反应就是查看这个分区是否已经在使用了,但是没有。 二:解决方法 2.使用 dmsetup remove xxx 移除掉就可以创建PV了:

    2023年11月23日
    1.4K00
  • 云服务器上的目录定时同步到Github

    具体操作与脚本 第一 在Github上创建私有仓库这一步相信大家都知道怎么操作 第二 在服务器拉取Github仓库并把.git目录复制到需要同步的目录下假设服务器需要同步的目录为:/usr/share/nginx/html/imgs 第三 编写定时同步脚本具体脚本如下,如脚本位置: /root/script/sync_to_github.sh 第四 通过Li…

    2023年5月15日
    1.2K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信