Ric*_*wig 5 linux ntp time-synchronization clock-synchronization
我有一台 NTP 服务器,它的时间设置错误,是未来 7 小时(机器发货后时区已更改,但时间未更改)。服务器本身不同步,只有它的本地时钟。在这台服务器上,超过 10 个客户端同步他们的时钟,这导致整组服务器的时间错误。
我如何更改 NTP 服务器上的时间,使更正被转换并且所有客户端也将得到更正?我首先通过“date MMDDhhmm”进行了修复测试,它让客户端与服务器断开连接(ntpq 中服务器名称前面的星号消失了)。
我不知道当我手动更改所有服务器上的时间时,所有同步服务将如何运行,方法是将时钟设置回 7 小时,导致系统拥有来自未来的文件。可能会发生崩溃,系统会为晶圆厂生产提供服务。
当您谈论消磨时间时,您通常是在谈论少量的时间。修复是通过调用adjtime()或在 linux 上执行的adjtimex()。
从 ntpd 手册页:
-x Normally, the time is slewed if the offset is less than the step
threshold, which is 128 ms by default, and stepped if above the
threshold. This option sets the threshold to 600 s, which is
well within the accuracy window to set the clock manually.
Note: Since the slew rate of typical Unix kernels is limited to
0.5 ms/s, each second of adjustment requires an amortization
interval of 2000 s. Thus, an adjustment as much as 600 s will
take almost 14 days to complete. This option can be used with
the -g and -q options. Note: The kernel time discipline is dis?
abled with this option.
Run Code Online (Sandbox Code Playgroud)
我怀疑您是否会想要以这种速度等待 7 小时的修正。需要一年多的时间。在 32 位系统上的 linux adjtime 被有效地限制为大约 2000 秒的增量。64 位系统可能使这不是问题,但更改生效的速度仍然是一个问题。
所以在 linux 实现中有一个阈值,大概是其他的,在这个阈值下你会得到一个非常慢的“slew”,但在这个阈值之上,主和客户端上的系统时钟将被步进,这可以更快地进行。
还会有另一个阈值,如果 master 和 client 之间的时间差太大,则 client 将假设错误而不更新。从 ntpd 手册页:
-g Normally, ntpd exits with a message to the system log if the
offset exceeds the panic threshold, which is 1000 s by default.
This option allows the time to be set to any value without
restriction; however, this can happen only once. If the thresh?
old is exceeded after that, ntpd will exit with a message to the
system log. This option can be used with the -q and -x options.
Run Code Online (Sandbox Code Playgroud)
请注意,-g几乎可以肯定不会为守护程序设置该选项。它通常用作ntpd -gq,在系统启动时一次性运行,或手动运行,其行为与ntpdate. 不过,恐慌阈值可能在编译时是可配置的,因此请查看操作系统供应商的手册页。
编写一个程序非常简单,该程序将使用您选择的任何频率和调整大小进行一系列时间调整。您可以在 ntp master 上执行此操作,它会将调整后的时间提供给其客户端,但您需要知道客户端系统将接受的最大大小调整,以及会导致它们执行非常缓慢的转换的最小阈值是多少。为了安全起见,您应该调查客户端系统上的 ntp 实现。
如果您正在更新具有类似于 linux 上的默认 ntpd 特征的系统而没有该-x选项,那么您可以使用一种机制,例如每 5 秒进行半秒调整,并且您将在大约 3 天的时间内进入同步状态。进行不跨越第二个边界的亚秒级调整可能有助于避免诸如两次触发 cron 作业之类的事情,但预计您可能会发现某种副作用。
如果您最终遇到服务器不再相互同步的情况,那么它会变得更加混乱。如果可行,我想监视时间差异,并在某些服务器不再跟随时自动停止执行自动定期更新,并发出警报。