
ubuntu systemd-timesyncd 时间同步(ntp同步)报错:Server has too large root distance. Disconnecting.解决办法(根距离过大)
这个错误信息表示,服务器无法从指定的 Windows NTP 服务器同步时间,原因是 “Server has too large root distance.” 这表明,NTP 服务器的 “根距离”(root distance)过大。30 秒可能会奏效。例如,如果服务器或客户端的硬件时钟电池耗尽,或者由于其他原因造成系统时钟无法保持准确,那么即使网络状况良好,也可能出现根距离过大的问题。例如,如果
问题复现
今天用AI盒子同步ntp服务器时间的时候报错了,提示Server has too large root distance. Disconnecting.
:
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-01-23 17:42:51 HKT; 46s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 145723 (systemd-timesyn)
Status: "Idle."
Tasks: 2 (limit: 8134)
Memory: 988.0K
CGroup: /system.slice/systemd-timesyncd.service
└─145723 /lib/systemd/systemd-timesyncd
Jan 23 17:42:51 ubuntu systemd[1]: Starting Network Time Synchronization...
Jan 23 17:42:51 ubuntu systemd-timesyncd[145723]: Configuration file /etc/systemd/timesyncd.conf is marked executable. Please remove executable permission bits. Proceeding anyway.
Jan 23 17:42:51 ubuntu systemd-timesyncd[145723]: Configuration file /etc/systemd/timesyncd.conf is marked world-writable. Please remove world writability permission bits. Proceeding anyway.
Jan 23 17:42:51 ubuntu systemd-timesyncd[145723]: Configuration file /etc/systemd/timesyncd.conf.d/nv-fallback-ntp.conf is marked executable. Please remove executable permission bits. Proceeding anyway.
Jan 23 17:42:51 ubuntu systemd-timesyncd[145723]: Configuration file /etc/systemd/timesyncd.conf.d/nv-fallback-ntp.conf is marked world-writable. Please remove world writability permission bits. Proceeding>
Jan 23 17:42:51 ubuntu systemd[1]: Started Network Time Synchronization.
Jan 23 17:42:51 ubuntu systemd-timesyncd[145723]: Server has too large root distance. Disconnecting.
Jan 23 17:43:23 ubuntu systemd-timesyncd[145723]: Server has too large root distance. Disconnecting.
分析原因
这个错误信息表示,服务器无法从指定的 Windows NTP 服务器同步时间,原因是 “Server has too large root distance.” 这表明,NTP 服务器的 “根距离”(root distance)过大。
在 NTP 中,“根距离” 是一个测量网络延迟和时钟偏移量的重要参数。它用于表示从参考源(通常是 UTC 时间)到当前服务器的总预期误差。如果根距离太大,就意味着同步时间可能不准确,因此 systemd-timesyncd 服务会断开连接并尝试寻找另一个 NTP 服务器。
关于NTP 服务器的 “根距离”(root distance)
在NTP(网络时间协议)中,"根距离"是指从当前服务器到参考时间源(通常是一个准确的原子钟或GPS时钟)的预期最大误差。这个误差包括了所有的网络延迟、时钟偏移和抖动等因素。
以下是可能导致 "根距离过大"问题的一些原因:
-
Windows NTP服务器可能没有正确地同步到一个准确的参考时间源。例如,如果它是配置为手动设置时间,或者同步到了一个根距离本身就很大的上游NTP服务器,那么它的根距离就可能会变得很大。
-
Windows NTP服务器或Ubuntu客户端的系统时钟可能存在较大的偏移。例如,如果服务器或客户端的硬件时钟电池耗尽,或者由于其他原因造成系统时钟无法保持准确,那么即使网络状况良好,也可能出现根距离过大的问题。
-
网络环境中存在导致时钟抖动的因素。即使网络的总体状态看起来良好,但如果存在频繁的网络阻塞或丢包等问题,也可能导致NTP的根距离变大。
具体分析
罪魁祸首似乎是“根距离”。这是从每个客户端通过本地 NTP 服务器(通过任何其他 NTP 服务器)到具有 GNSS 接收器或原子钟的“第 1 层”服务器的整个路由引入的延迟。
+---------------------+ +---------------------+
+---------+ | Stratum 1 server | 20ms delay | Stratum 2 server |
|GNSS rcvr|---| Root distance: 0ms +--------------+ Root distance: 20ms |
+---------+ | nasa.gov | | 0.pool.ntp.org |
+---------------------+ +----------+----------+
|
| 5040ms delay
|
==LAN=FIREWALL==+================
|
+-----------------------+ +-----------+-----------+
| Clients | 1ms delay | Stratum 3 server |
| Root distance: 5061ms +--------------+ Root distance: 5060ms |
| 10.10.1.0/24 | | 10.10.1.30 |
+-----------------------+ +-----------------------+
由于与第 1 层服务器的对齐不如与第 3 层服务器的对齐重要,因此您可以RootDistanceMaxSec=在每个客户端上增加一个更舒适的值。30 秒可能会奏效。默认值为 5 秒,因此您可能会非常接近这个数字。编辑/etc/systemd/timesyncd.conf
:
# See timesyncd.conf(5) for details.
[Time]
NTP=10.10.1.30
#FallbackNTP=
RootDistanceMaxSec=30
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
这将导致客户端接受10.10.1.30作为 NTP 服务器,即使它可能远离第 1 层服务器。
解决方法
我将RootDistanceMaxSec取消注释并改成30秒(默认为5秒):
vi /etc/systemd/timesyncd.conf
然后重启服务,再看就可以了:
systemctl restart systemd-timesyncd
systemctl status systemd-timesyncd.service
同步后的效果:
左上为AI盒子,坐下为NVR,右边为windows NTP服务器:
更多推荐
所有评论(0)