ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

journald 持久化 + 限额脚本

journald 持久化 + 限额脚本
#!/usr/bin/env bash
# ---------------------------------------------------------
# Enable persistent systemd-journald logs with disk limits
# Tested on: AlmaLinux 9 / CentOS Stream 9
# Author: 四点
# ---------------------------------------------------------
set -euo pipefailecho "[1/4] Create persistent directory..."
install -d -m 2755 -o root -g systemd-journal /var/log/journal
systemd-tmpfiles --create --prefix /var/log/journal || trueecho "[2/4] Write journald limit configuration..."
mkdir -p /etc/systemd/journald.conf.d
cat >/etc/systemd/journald.conf.d/99-limits.conf <<'EOF'
[Journal]
# 存储方式:持久化到 /var/log/journal
Storage=persistent# 日志总占用上限(所有 .journal 文件总和)
SystemMaxUse=6G# 单个日志文件上限
SystemMaxFileSize=200M# 日志最长保留时间
MaxRetentionSec=90day# 节流:30 秒内最多收 2000 条,防止日志风暴刷爆磁盘
RateLimitIntervalSec=30s
RateLimitBurst=2000
EOFecho "[3/4] Restart systemd-journald..."
systemctl restart systemd-journaldecho "[4/4] Check results..."
journalctl --disk-usage
systemctl status systemd-journald --no-pager -l | head -n 10
ls -ld /var/log/journal

 

 

  1. 保存为 enable-journald-persistent.sh

 

返回列表