这个问题与这个问题和我在 serverfault 上问过的这个问题有关。
根据我之前的问题,我有兴趣以快速(理想情况下少于一秒)、同步(如果进程以 0 状态完成,时间应该同步)和稳健的方式(“稳健”)同步我的机器上的时间” 这里的意思是只要我们收到来自ntp服务器的响应,时间就要根据响应来设置)。ntp在这个快速的初始同步之后,我将在后台运行。
使用ntpdate似乎太不稳定,无论如何都不推荐(我偶尔会遇到“没有服务器可用的错误”,我认为主要是由于与 ntp 服务器的差异,而不是无法访问 ntp 服务器)。然而,一件好事ntpdate是它有一个选项-p可以让我缩短将时间设置为仅毫秒(当它工作时)所需的时间。
使用sudo ntpd -gq,如前面问题中所建议的,似乎使时钟同步更可靠,但在我的机器上至少需要 7-8 秒,大概是因为ntpd在中间睡眠时间中采集了多个样本。更糟糕的是,ntpd在成功退出之前通常会挂起几分钟。我不确定为什么会发生这种情况,因为 ntp 服务器可以访问并在整个时间跨度内响应请求。
因此,我正在寻找一种方法,希望能够加快使用 同步机器时钟所需的时间ntpd -gq,并且我愿意牺牲几毫秒的初始时钟精度以实现更快的时钟同步。我愿意做出这种牺牲的原因是同步是我每天运行多次的引导程序的一部分,每次运行 ntp 等待 8 秒到几分钟都会减慢进程的速度(到点我别无选择,只能接受ntpdate's 快速但不推荐和不可靠的行为)。
有没有办法实现可靠的快速性能ntpd?
编辑:这是我的 ntp.conf (如果您想知道 的位置server,它是在剥离所有现有服务器后以编程方式附加到文件中的):
# /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
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
# Use Ubuntu's ntp server as a fallback.
# 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
server pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
当您发布配置时,事情很容易:
改变:
server pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
到:
server 0.COUNTRY-CODE.pool.ntp.org iburst
server 1.COUNTRY-CODE.pool.ntp.org iburst
server 2.COUNTRY-CODE.pool.ntp.org iburst
server 3.COUNTRY-CODE.pool.ntp.org iburst
Run Code Online (Sandbox Code Playgroud)
其中国家代码是 us / ca / uk / fr
此响应的核心是 iburst,如果一台服务器无法访问,则额外的两条服务器线允许设置时钟。
还要安装 fake-hwclock,以便时间在重新启动后仍然存在。每次机器启动的时候都不会是 1970 年。
更新:我看到了你的答案。为什么不运行本地 ntp 服务器,这样时间设置起来非常快,而且您不必担心连接到互联网上的 ntp 服务器?
| 归档时间: |
|
| 查看次数: |
10388 次 |
| 最近记录: |