在 Debian 系统中,“日志时间同步”通常涉及两个方面:
下面分别说明。
Debian 9+ 一般自带 systemd-timesyncd
# 查看状态
timedatectl status
# 开启 NTP 同步
sudo timedatectl set-ntp true
# 再次查看
timedatectl status
应看到:
System clock synchronized: yes
NTP service: active
sudo apt install chrony
sudo systemctl enable --now chrony
查看同步状态:
chronyc tracking
sudo apt install ntp
sudo systemctl enable --now ntp
日志时间混乱,常因时区不对。
# 查看当前时区
timedatectl
# 设置时区(如中国)
sudo timedatectl set-timezone Asia/Shanghai
设置后,系统日志(如 /var/log/syslog)时间会统一。
确保:
sudo systemctl status rsyslog
journalctl
显示 UTC?可加:
journalctl --output=short-local
或修改:
sudo nano /etc/systemd/journald.conf
Storage=persistent
然后:
sudo systemctl restart systemd-journald
# 查看硬件时间
hwclock --show
# 同步硬件时间
sudo hwclock --systohc
✅ 推荐做法:
sudo timedatectl set-ntp true
sudo timedatectl set-timezone Asia/Shanghai
如果你是指 “多台服务器日志时间对齐” 或 “容器 / Docker 日志时间不同”,可以告诉我具体场景。