Ubuntu(或任何 Linux 系统)出现时间戳变慢 / 时间不对,通常不是“系统时钟走慢了”,而是时钟源或时间同步出了问题。下面按最常见原因给你梳理一下。
Ubuntu 默认用 systemd-timesyncd 或 chrony/ntpd 同步时间。
如果没同步:
检查:
timedatectl status
正常应看到:
System clock synchronized: yes
NTP service: active
如果 no / inactive,就是问题所在。
开启 NTP:
sudo timedatectl set-ntp true
解决:
open-vm-tools / qemu-guest-agent很多人以为是慢了,其实是时区不对。
检查:
date
timedatectl
如果是 UTC 而不是 Asia/Shanghai:
sudo timedatectl set-timezone Asia/Shanghai
主板电池没电或 RTC 精度差。
查看硬件时间:
sudo hwclock --show
同步系统时间到硬件:
sudo hwclock --systohc
比如:
date -s容器一般不能自己改时间,只能依赖宿主机。
timedatectl status
date
sudo hwclock --show
systemctl status systemd-timesyncd
timedatectl status 输出我可以直接告诉你具体是哪一步出问题。