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

相关推荐

  • Centos软件gcc 多版本共存

    问题背景: Centos默认的gcc版本太老了,有时候需要用新版本的gcc,编译gcc太麻烦可以使用centos提供的scl功能快速切换gcc版本。本文需要用到的SCL 软件集,可以快速解决这个问题。 SCL软件集(Software Collections)是为了给 RHEL/CentOS 用户提供一种 以方便、安全地安装和使用应用程序和运行时环境的多个(而…

    2023年5月19日
    16000
  • Windows server 2012 r2 修改用户名、修改密码、设置服务器禁止ping、修改远程连接端口为39527、增加一个内网ip、安装mysql/php。

    修改用户名 1.打开左下角的win标,然后点管理工具 2.打开本机安全策略 3.打开本地策略-安全选项-翻到最下面,打开重命名系统管理员账户 4.双击打开,输入自己的需要的,然后点击“应用”-“确定” 5.然后到“计算机管理”这边,点击“本地用户和组”-“用户”,发现管理员的名称已经更改成功 修改密码 1.选择想改变密码的账户右击,选择“设置密码” 2.点击…

    2022年7月18日
    83600
  • Nginx 的 ngx_stream_module模块安装后启动报错 unknown directive “stream”

    环境: nginx1.16 说明: 在安装好模块后,nginx.conf 中也配置了4层代理信息,可是启动后报错 报错内容:unknown directive “stream” 解决方法: 在 nginx 配置文件中 加上: load_module /home/webapp/nginx/modules/ngx_stream_modul…

    Linux系统 2023年2月3日
    31100
  • Ceph集群日常使用命令

    一、Ceph 集群服务维护 之前文章说了一下ceph的安装,安装其实比较简单,但是后续维护起来我们需要知道常用的维护命令 如果我们机器上osd、mon、rgw等服务都安装在一个节点,可以通过下面的命令直接管理所有服务 ceph target allowing to start/stop all ceph*@.service instances at once…

    2023年4月19日
    21100
  • VPS主机和服务器磁盘IO读写速度测试方法-VPS主机真实IO检测工具

    VPS主机磁盘IO的好坏直接影响到VPS主机性能的高低。对于测试VPS主机的性能,我们有非常多的脚本工具,例如:VPS主机速度和性能综合测试工具整理汇总中我们就分享了不少的脚本工具,可以快速地测试VPS主机的CPU、内存和带宽等。 不过,有好友反馈说对于VPS主机的磁盘IO测试,脚本测出来的结果差别比较大,甚至直到建站时才发现购买的VPS主机的IO太低,严重…

    2023年11月24日
    3500

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信