Linux 中 syslog 时间不准是一个比较常见的现象,通常不是“系统时间错了”,而是由 syslog 本身的工作机制、时区配置或日志来源 导致的。下面按常见原因逐一说明。
结果:日志时间比实际时间 差 8 小时(或 N 小时)
✅ 检查方式:
date
timedatectl
✅ syslog 常见配置:
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
例如:
%timegenerated%
%timereported%
timegenerated:rsyslog 接收时间timereported:设备/应用上报时间如果日志来自:
就可能 时间不一致
✅ 示例(推荐统一):
template TmplAuth, "/var/log/auth.log"
结果:
✅ 解决方式:
timedatectl status
如果看到:
NTP synchronized: no
✅ 解决:
systemctl enable --now chronyd
# 或
apt install ntp
表现在:
✅ 可禁用缓冲(性能换准确):
$ActionQueueType Direct
journalctl 用 UTC/var/log/messages 用本地时间✅ 查看对比:
journalctl -n 5
tail -n 5 /var/log/messages
hwclock --show
date
timedatectl
tail /var/log/messages
journalctl -n 5
grep time /etc/rsyslog.conf
如果你愿意,可以告诉我:
我可以直接给你一份精准修复配置。