当服务器与 NTP 同步时间时,如何保持更新硬件时钟?

当服务器与 NTP 同步时间时,如何保持更新硬件时钟?

当服务器与 NTP 服务器同步时,是否有任何方法可以定期同步硬件时钟?我使用的是 Centos 6.7。以下是我的 ntp.conf 文件内容

# File for including partners custom ntp configurations
leapfile "/etc/ntp/leap-seconds.list"


# Permit general access to this service.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Replacement for the Undisciplined Local Clock. Allows a
# group of ntpds to autonomously select a leader in the
# event that all real time sources become unreachable.
tos orphan 10

# NTP Drift file.
# Put this in a directory to which the daemon can write.
# No symbolic links allowed, either, since daemon renames.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used
# when operating with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8
server  127.127.1.0      # local clock
server x.x.x.x

答案1

您可以在 root 中尝试以下操作crontab

1 0 * * *  /usr/sbin/hwclock --systohc

它将每天午夜后同步一次;--utc如果您的主板时钟是 UTC,请不要忘记标记。如果您的硬件时钟漂移得如此之快,以至于每天需要校正多次,您可能会遇到更大的问题!

答案2

通常,RHEL 和 CentOS 已经通过 init 脚本在正常重启和关闭期间将硬件时钟与系统时间同步ntpdate

没有什么可以阻止你通过/sbin/hwclock --systohccron 作业调用更频繁地执行此操作。

相关内容