在 Ubuntu 上同步系统时间(时间戳)通常有以下几种常用方法,最推荐的是使用 systemd-timesyncd 或 NTP。
Ubuntu 16.04 及以后版本默认使用 systemd-timesyncd 做时间同步。
timedatectl status
如果看到:
System clock synchronized: yes
说明已经同步。
sudo timedatectl set-ntp true
sudo systemctl restart systemd-timesyncd
journalctl -u systemd-timesyncd
适合临时同步一次时间。
sudo apt update
sudo apt install ntpdate
sudo ntpdate pool.ntp.org
⚠️ 注意:如果 systemd-timesyncd 正在运行,可能需要先停止:
sudo systemctl stop systemd-timesyncd
sudo ntpdate pool.ntp.org
sudo systemctl start systemd-timesyncd
适合对时间精度要求高的场景(如数据库、集群)。
sudo apt install chrony
sudo systemctl enable --now chrony
查看同步状态:
chronyc tracking
sudo timedatectl set-timezone Asia/Shanghai
查看当前时区:
timedatectl
sudo date -s "2026-01-15 12:00:00"
确保能访问 UDP 123 端口
如果你能说明是:
我可以给你更精确的配置方案。