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

相关推荐

  • MySQL5.7主从同步、读写分离

    MySQL5.7主从同步、读写分离 安装MySQL5.7 下载rpm包 安装 启动mysql查看密码 登录mysql 主从同步 关闭每台服务器的防火墙和selinux 主从服务器时间同步 主服务器使用本地时钟源 修改配置文件 开启ntpd 从服务器同步主服务器时间 安装ntp工具 启动ntp和主服务器进行时间同步 主服务器mysql配置 修改配置文件 重启m…

    2022年7月31日
    20900
  • yum 安装部署 docker-ce

    一、yum安装Docker 本案例要求配置本地yum源并安装Docker: 准备1台虚拟机,IP为192.168.137.100, 网络设置为NAT模式 安装docker 关闭防火墙 关闭SELINUX 实现此案例需要按照如下步骤进行。   步骤一:配置yum源 1、Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提…

    Linux系统 2023年2月8日
    5500
  • Truenas webdav共享服务数据备份

    第一步 首先创建数据集 第二步 启用webdav共享服务,并配置账号密码(已启用可忽视) 第三步 配置数据集使用webdav共享服务 这样webdav服务就已经打开了 配置webdav服务上传文件大小限制,进入/usr/local/etc/apache24/Includes 修改webdav文件,http修改webdav.conf ,https修改webda…

    2023年3月13日
    4800
  • 通过配置hosts.allow和hosts.deny限制登陆

    我们通常只对管理员开放SSH登录,那我们就可以禁用不必要的IP,而只开放管理员可能使用到的IP段。 /etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,通过他可以允许或者拒绝某个ip或者ip段的客户访问linux的某项服务。 我们通常只对管理员开放SSH登录,那我们就可以禁用不必要的IP,而只开放管理员可能使用到的I…

    2022年11月15日
    13300
  • smokeping修改Ping间隔和Ping包数量

    1、复制 所有带*.dist 2、修改httpd.conf 配置文件 3、修改 /usr/local/smokeping/etc/config

    2022年11月26日
    13700

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信