Joh*_*hir 22 ubuntu ntp time ntpd openntpd
我的服务器上运行着 ntpd。这是所有默认设置,除了我注释掉它作为其他机器的服务器的能力:
# restrict -4 default kod notrap nomodify nopeer noquery
# restrict -6 default kod notrap nomodify nopeer noquery
restrict default ignore
Run Code Online (Sandbox Code Playgroud)
如果我运行ntpdate -q ntp.ubuntu.com
,我会被告知我机器的时钟关闭了 7 秒。
这是怎么回事?我如何诊断正在发生的事情,是否有我可以打开的日志?
更多信息#1
# ntpq -np
remote refid st t when poll reach delay offset jitter
==============================================================================
91.189.94.4 193.79.237.14 2 u 30 64 7 108.518 -0.136 0.361
Run Code Online (Sandbox Code Playgroud)
更多信息#2
这是我问这个问题时的样子:
# ntpdate -q ntp.ubuntu.com
server 91.189.94.4, stratum 2, offset 7.191308, delay 0.13310
10 Jan 20:38:09 ntpdate[31055]: step time server 91.189.94.4 offset 7.191308 sec
Run Code Online (Sandbox Code Playgroud)
这是现在的样子,在重新启动 ntpd 几次之后(我假设这就是修复它的原因):
# ntpdate -q ntp.ubuntu.com
server 91.189.94.4, stratum 2, offset 0.000112, delay 0.13164
10 Jan 20:47:03 ntpdate[31419]: adjust time server 91.189.94.4 offset 0.000112 sec
Run Code Online (Sandbox Code Playgroud)
更多信息#3
我卸载了 ntp 并安装了 openntpd 并运行了/usr/sbin/ntpd -d
,我看到了这样的输出:
reply from 64.73.32.134: offset 6.715003 delay 0.041152, next query 30s
reply from 208.53.158.34: offset 6.700224 delay 0.036263, next query 31s
adjusting local clock by 6.734120s
reply from 72.18.205.156: offset 6.708575 delay 0.035885, next query 30s
reply from 64.73.32.134: offset 6.701463 delay 0.044199, next query 33s
Run Code Online (Sandbox Code Playgroud)
对我来说,这很清楚地表明我无法在我的服务器上设置时间(尽管使用常规 ntp,它似乎有时会更新......)。
更多信息#4
我的 VPS 提供商说:
最新的内核不应将您的系统锁定到我们的 dom0 时钟,为了安全起见,您可以在 sysctl.conf 中设置 xen.independent_wallclock = 1。
我想这仍然没有解决 VPS 需要可用 CPU 才能进行正确计时计算的问题。
Dav*_*ger 12
您可以通过将其添加到 ntp.conf 来启用登录 ntpd:
logfile /var/log/ntpd.log
Run Code Online (Sandbox Code Playgroud)
来源:ntp手册
如果关闭ntpd,是否可以通过命令行更新时钟?如果您运行 ntpdate 命令并收到如下错误:
# ntpdate ntp.ubuntu.com
10 Jan 23:47:57 ntpdate[26284]: Can't adjust the time of day: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
这意味着您可能在 VPS 上,在这种情况下您无法修改系统时钟 - 这只能在主机上完成。
好吧,自从提出这个问题以来,我已经使用默认供应商(Ubuntu 10.0.4)配置重新安装了 ntp 并让它运行了几天。在撰写本文时,ntpdate -q ntp.ubuntu.com
显示我的时间精确到 0.000216 秒以内。所以,我遇到的问题一定是我的自定义配置(我试图让外部主机无法查询我的服务器,我已经用我的防火墙在做,所以我不太担心)。这是 Ubuntu 10.0.4 ntp.conf 的全部内容,删除了注释:
driftfile /var/lib/ntp/ntp.drift
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
server ntp.ubuntu.com
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
Run Code Online (Sandbox Code Playgroud)
我欢迎有关如何改进此配置的反馈。
我还与我的 VPS 提供商打了一张票,要求他们提供有关最佳做法的详细建议。我将它们指向这个线程,以及一些其他文档,表明 CPU 分配可能会导致计时问题。以下是他们所说的:
最新的内核不应将您的系统锁定到我们的 dom0 时钟,为了安全起见,您可以在 sysctl.conf 中设置 xen.independent_wallclock = 1。这将确保服务器实例不遵循主机服务器上的时钟。
和:
我认为您可能误解了此问题在虚拟化环境中影响 NTP 客户端的确切程度。根据我在 Xen 主机上的虚拟化系统上的经验(例如我们在 Rackspace Cloud 上的设置),即使在高负载系统上,由于没有专用系统时钟来处理中断而继承的不准确性也达到了几分之一秒。这种轻微的不准确性很容易被 NTP 管理,即使它只设置为每天更新一次服务器时间(甚至比这更不频繁)。
归档时间: |
|
查看次数: |
135468 次 |
最近记录: |