服务器的本地时钟如何成为网络中的 NTP 时间源?

服务器的本地时钟如何成为网络中的 NTP 时间源?

我想让 Stratum 1 服务器中的本地时钟成为我的网络的网络时间源(我不想使用带天线的 Stratum 0 服务器)。如何在网络中设置它?是否有教程解释如何使用网络时间协议并进行设置?到目前为止,我在 Google 上还没有找到任何关于如何实现这一点的信息。非常感谢您的帮助。

答案1

相对于现代设备所期望的精度,通用计算机中的时钟是垃圾。没有精确校准,服务器的热变化会导致漂移变化。因此,它需要某种方法来更新,否则最终会变得不准确,在极端情况下会差几分钟。有时只要时钟一致就足够了,但人们往往期望更好。

接下来是实际配置。例如,在 Linux 上,chrony 很受欢迎,它具有手动设置时钟和处理断开连接的功能。从以下示例开始RHEL 时间记录文档,并参阅 chrony 手册。

大多数时间服务器至少具有互联网接入、卫星导航天线或精确时钟硬件之一。默认情况下,如果时间最终来自 NTP 的参考时钟,chrony 将提供时间。将允许指令设置为您的网络并使用您的 NTP 服务器。但是,如果您没有这些,您可以使用本地指令让 chrony 提供时间。

如果这确实是一个没有时间硬件的隔离网络,也请启用手动指令,这样您就可以使用 手动告诉它时间chronyc settime

chrony.conf 启用这些内容,对 NTP 服务器的使用进行一些评论,以及我喜欢的 EL 默认配置中的一些内容:

# chrony.conf that still serves time if not syncronized 

# Options for time sources

# NTP appliance
# For example, sat nav modules are inexpensive
# Assuming it is available over IP, it is an NTP server
#server time.zone.example.net iburst

# Isolated computers need software updates too!
# If there is an update server on the local net via IP,
# it can serve NTP as well as patches
#server updateproxy.example.net iburst

# Public internet NTP
# Use if you actually have internet
# But no local time source somehow
#pool 2.pool.ntp.org iburst


# Pretend local clock is syncronized
# Enabling serving time
# Use a high stratum, as a lower priority over better clocks 
local stratum 10

# Allow "chronyc settime"
# Run this with input time based on e.g. a watch or other clock
# Regularly and when the time is wrong
manual

# Allow clients to query this server
# Replace with your local net prefix
allow 2001:db8:2ea1::/48


### End source customization
### Begin other configuration

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

logdir /var/log/chrony
log measurements statistics tracking

相关内容