首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行ntpd但不同步的VM

运行ntpd但不同步的VM
EN

Unix & Linux用户
提问于 2015-09-29 13:46:40
回答 1查看 7.7K关注 0票数 6

TL;

博士

VM使用KVM,时间不同步。暂停2分钟后,它将保持一个永久性的2分钟间隔。设置另一个具有不同网络配置的VM显示,网络配置阻止ntp工作。解决这个网络问题是不合适的。

但是,没有网络问题的新VM在简历之后也不会同步。同样的测试:暂停2分钟。用一台同步的机器检查日期差异。2分钟的延迟是永久性的。

这似乎是一个常见的问题,关于如何保持VM同步以及同时使用NTP和kvm时钟存在争议。我找到了很多关于这一点的参考资料,但没有回答。

问题

我有一个ntpd运行的Debian,但没有校正时间。例如,在暂停/恢复之后,我将得到一个永久的2分钟偏移。

/etc/ntp.conf是默认的或接近默认的,没有什么特别之处:

代码语言:javascript
复制
# /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 ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst


# 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

ntpq似乎报告了一个问题:

代码语言:javascript
复制
# cat ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 37.187.7.160    .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 195.154.211.37  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 195.154.216.44  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 95.81.173.155   .INIT.          16 u    - 1024    0    0.000    0.000   0.000

但是,我不是netcat向导,但是UDP端口123上的AFAIU传出通信量可以通过:

代码语言:javascript
复制
# nc -vvzu 37.187.7.160 123
mail.lafkor.de [37.187.7.160] 123 (ntp) open
 sent 0, rcvd 0

这个测试是否足以排除防火墙问题?

主机(也是Debian机器)具有相同的NTP配置,并且同步工作。这两台机器的网络配置是不同的,这就是为什么我认为这可能是一个网络问题。

还有其他有用的测试吗?

我不认为tinker panic 0参数在这里是相关的,因为它是为了强制更新巨大的间隙,而不是2分钟的间隙。无论如何,AFAIU,它会影响在时间偏移的情况下的行为,但是它不会解决ntpq -pn只返回零的问题。

FWIW,来自这个问题的其他测试输出:

代码语言:javascript
复制
# ntpq
ntpq> pe
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 mail.lafkor.de  .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 atoll.tropicdre .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 oods.roflcopter .INIT.          16 u    - 1024    0    0.000    0.000   0.000
 ntp-3.arkena.ne .INIT.          16 u    - 1024    0    0.000    0.000   0.000
ntpq> as

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 21025  8011   yes    no  none    reject    mobilize  1
  2 21026  8011   yes    no  none    reject    mobilize  1
  3 21027  8011   yes    no  none    reject    mobilize  1
  4 21028  8011   yes    no  none    reject    mobilize  1
ntpq> rv
associd=0 status=c012 leap_alarm, sync_unspec, 1 event, freq_set,
version="ntpd 4.2.6p5@1.2349-o Fri Apr 10 19:04:04 UTC 2015 (1)",
processor="x86_64", system="Linux/3.16.0-4-amd64", leap=11, stratum=16,
precision=-23, rootdelay=0.000, rootdisp=6683.055, refid=INIT,
reftime=00000000.00000000  Mon, Jan  1 1900  0:09:21.000,
clock=d9b51587.b7a1085f  Tue, Sep 29 2015 15:49:59.717, peer=0, tc=3,
mintc=3, offset=0.000, frequency=-0.125, sys_jitter=0.000,
clk_jitter=0.000, clk_wander=0.000
ntpq> rv 21025
associd=21025 status=8011 conf, sel_reject, 1 event, mobilize,
srcadr=mail.lafkor.de, srcport=123, dstadr=147.210.157.185, dstport=123,
leap=11, stratum=16, precision=-23, rootdelay=0.000, rootdisp=0.000,
refid=INIT, reftime=00000000.00000000  Mon, Jan  1 1900  0:09:21.000,
rec=00000000.00000000  Mon, Jan  1 1900  0:09:21.000, reach=000,
unreach=1137, hmode=3, pmode=0, hpoll=10, ppoll=10, headway=0,
flash=1600 peer_stratum, peer_dist, peer_unreach, keyid=0, offset=0.000,
delay=0.000, dispersion=15937.500, jitter=0.000, xleave=0.167,
filtdelay=     0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00,
filtoffset=    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00,
filtdisp=   16000.0 16000.0 16000.0 16000.0 16000.0 16000.0 16000.0 16000.0

tcpdump / ntpdate测试

在NTP同步正常工作的机器上,我启动tcpdump udp port ntp,当我重新启动ntpd时,我看到这样的输出:

代码语言:javascript
复制
# tcpdump udp port ntp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
17:31:33.719166 IP 10.0.2.15.ntp > spica.beduzar.fr.ntp: NTPv4, Client, length 48
17:31:33.736804 IP spica.beduzar.fr.ntp > 10.0.2.15.ntp: NTPv4, Server, length 48
17:31:35.973551 IP 10.0.2.15.ntp > ntp.tuxfamily.net.ntp: NTPv4, Client, length 48
17:31:35.992671 IP ntp.tuxfamily.net.ntp > 10.0.2.15.ntp: NTPv4, Server, length 48
[...]

在我遇到问题的机器上,在重新启动ntpd时,我根本没有看到任何输出(没有请求,也没有回复)。我至少应该看看这些请求吗?

在好机器上:

代码语言:javascript
复制
# ntpdate 0.debian.pool.ntp.org
29 Sep 17:24:49 ntpdate[700]: adjust time server 193.55.167.1 offset -0.005196 sec

在坏机器上:

代码语言:javascript
复制
# ntpdate 0.debian.pool.ntp.org
29 Sep 17:43:18 ntpdate[3180]: no server suitable for synchronization found

用另一个VM进行

测试我们使用相同的NTP配置设置了另一个VM,但设置了另一个网络配置。 tcpdumpntpdate的这一结果是正确的,ntpq -pn返回了很好的结果。因此,显然,网络配置确实是一个有缺陷的VM的问题。 但是,新的VM也不同步。如果我挂起它,使它有大约100秒的延迟,它就不会同步(我的意思是几分钟后,间隔仍然是相同的秒数)。但是,当重新启动ntpd时,它会立即同步。 我似乎有两个问题:

  • 第一个VM上的网络配置
  • ntp不会在两者上同步(除非重新启动)
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2015-10-20 07:40:56

问题解决了。

网络发布

VM存在网络问题,阻碍了ntpd的成功。它有两个eth接口,其中一个带有网关,它通过一个我们不直接管理的路由器。虽然我的测试没有显示出来,但我想一些UDP帧被阻止了。我们用另一个网络配置设置了另一个VM,ntpq获得了更好的结果。

最后,我们更改了ntp配置,以便主机在本地广播时间,并在其上同步所有VM。这样做更有意义,并将公共ntp服务器上的负载降到最低。

ntpd在几分钟后立即设置时钟

在测试中可能误导我的一件事是ntpd没有立即同步。我认为它会立即检测到一个间隙,然后修改时钟速度,以便时钟逐步加入源时钟。事实上,我们注意到(除非ntpd被重新启动)时钟在几分钟内没有变化,然后突然被设置为立即出现的东西。同时,ntpq输出中最右边的列显示同步正在进行。

这种ntpd行为可能解释了为什么我认为ntpd没有工作,即使它工作了。我只是等待的时间不够长,也不了解ntpq的输出。

票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/232770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档