ntpd 没有更新正确时间

ntpd 没有更新正确时间

尝试配置我的 Ubuntu 服务器以与 pool.ntp.org 同步。按照本指南操作https://help.ubuntu.com/community/UbuntuTime

我已经将 ntp.conf 配置如下

cat /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift


# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


# You do need to talk to an NTP server or two (or three).
server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org
server 3.north-america.pool.ntp.org


# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

然后我把系统更新到了很远很远

date -s "2 OCT 2006 18:00:00"

并尝试重新启动ntpd,时间仍然是2006年。

ntpq --peers; date
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 dev1-c.sje007.i 209.81.9.7       2 b   48   64  177   80.623  1205991 1100914
 ox.eicat.ca     139.78.135.14    2 b   18   64  377   24.743  1205991 1019249
 ntp1.Housing.Be 169.229.128.214  3 b   62   64  177   94.714   -5.160 6962796
 ns1.your-site.c 10.1.5.2         3 b   26   64  177   10.913   -9.521 6962796
Mon Oct  2 18:02:29 UTC 2006

为什么 ntp 不响应?

答案1

当本地时间和池时间之间的差值超过一定值时,ntp 将“延迟”更新,即始终执行微小更改。这样您的系统行为就不会完全超出限制。以下是手册页的摘录:

-x 通常,如果偏移量小于步进阈值(默认为 128 毫秒),则时间会倾斜;如果偏移量高于阈值,则时间会步进。
              此选项将阈值设置为 600 秒,这完全在手动设置时钟的精度窗口内。注意:由于
              典型的 Unix 内核被限制为 0.5 ms/s,每一秒的调整需要 2000 s 的摊销间隔。因此,调整如下
              多达 600 秒将需要将近 14 天才能完成。此选项可以与 -g 和 -q 选项一起使用。注意:内核时间规则
              使用此选项可禁用。

鉴于您当前的时差,您需要很长时间才能赶上。我建议您手动将时差调小,然后观察是否有效。

答案2

可能是 ntpd 调整时间很慢或者存在一些错误,请在 /var/log/daemon.log 或 /var/log/syslog 中查找(grep -i ntpd /var/log/daemon.log)。

一个快速的解决方案是添加一个 cron 作业ntpdate 0.pool.ntp.org

相关内容