我不知道为什么我的 Ubuntu 20.04 中显示的时间与实际时钟不同。如下所示,我已经同步了时钟,然后date
命令显示它是02:54:49 PM CEST
,但来自互联网的查询时间显示10:55:18 UTC
。由于 CEST 提前 +2 小时,正确的 CEST 时间应该是 10+2=12 AM,我的手表也显示这个时间。
$ sudo hwclock --systohc
$ timedatectl status
Local time: Mon 2022-10-17 14:54:41 CEST
Universal time: Mon 2022-10-17 12:54:41 UTC
RTC time: Mon 2022-10-17 12:54:41
Time zone: Europe/Brussels (CEST, +0200)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
$ date
Mon 17 Oct 2022 02:54:49 PM CEST
$ cat </dev/tcp/time.nist.gov/13
59869 22-10-17 10:55:18 21 0 0 543.3 UTC(NIST) *
$ cat /etc/systemd/timesyncd.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.
[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
有什么办法可以修复这个问题吗?
更新:
在系统上,chrony 正在运行,而 ntp 被屏蔽。
$ dpkg -l | grep ntp
rc ntp 1:4.2.8p12+dfsg-3ubuntu4.20.04.1 amd64 Network Time Protocol daemon and utility programs
ii ntpdate 1:4.2.8p12+dfsg-3ubuntu4.20.04.1 amd64 client for setting system time from NTP servers (deprecated)
ii sntp 1:4.2.8p12+dfsg-3ubuntu4.20.04.1 amd64 Network Time Protocol - sntp client
$ dpkg -l | grep chrony
ii chrony 3.5-6ubuntu6.2 amd64 Versatile implementation of the Network Time Protocol
$ systemctl status ntp.service
● ntp.service
Loaded: masked (Reason: Unit ntp.service is masked.)
Active: inactive (dead) since Mon 2022-10-17 13:04:47 CEST; 1 day 4h ago
Main PID: 1773 (code=exited, status=0/SUCCESS)
$ systemctl status chronyd.service
● chrony.service - chrony, an NTP client/server
Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-10-17 13:09:20 CEST; 1 day 4h ago
因此,似乎系统上的 ntp 已被 chrony 取代(不记得了)。但我不知道如何同步 chrony。
答案1
使用这些命令来获取有关当前时间同步状态的更多信息:
timedatectl status
(比较时间、同步状态等)timedatectl timesync-status
(时间服务器、间隔、延迟、层等)
您的输出timedatectl status
明确表明系统时钟未同步。
重新启动timesyncd.service
以强制同步:
sudo systemctl restart systemd-timesyncd.service
如果这不起作用,则您的时间服务器配置无效。
如果是这种情况,请包含内容/etc/systemd/timesyncd.conf
以找出其不起作用的原因。