systemd journalctl 日志清理

systemd journalctl 日志清理

systemd 日志文件使用了多少磁盘空间

journalctl --disk-usage

配置文件自动删除

用 /etc/systemd/journald.conf 中的日志配置文件来控制日志日志文件清理过程。

root@cloud:~# cat /etc/systemd/journald.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.

[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
#ReadKMsg=yes
#Audit=no

保存配置文件后记得重新启动日志

systemctl restart systemd-journald

手动删除

首先刷新和轮换日志文件。轮换是将当前活动日志文件标记为存档并从此时开始创建新日志文件的一种方法。

journalctl --flush --rotate

在刷新和旋转之后,需要运行带有vacuum-size、vacuum-time和vacuum-files开关的journalctl来强制systemd清除日志。

仅适用于存档日志文件,不适用于活动日志文件。
清理指定时间之前的日志

journalctl --vacuum-time=1s

保留日志文件个数

journalctl --vacuum-files=1

限制日志占用的空间大小

journalctl --vacuum-size=1M

清理文件后检查日志文件的完整性。该命令显示日志文件的 PASS、FAIL。

journalctl --verify
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值