我已经安装了一个ntp服务器和5个客户端。我想强制同步客户端到启动时的服务器时钟。使用我当前的ntp设置,计算机正在同步,但在几分钟后。我不能等他们这么久才能同步。我不使用RTC/GPS,所有的机器都在局域网中。我需要使用什么配置或命令来迫使它们在引导时立即与不受约束的服务器时钟同步所有客户端?
服务器ntp.conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
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 127.127.1.0
fudge 127.127.1.0 stratum 8
# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Needed for adding pool entries
restrict source notrap nomodify noquery
# (Again, the address is an example only.)
broadcast 192.168.0.255客户端ntp conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
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 192.168.0.51
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Needed for adding pool entries
restrict source notrap nomodify noquery
# 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编辑建议命令的添加结果
root@displaypi:~# ntpd -g -x -q 192.168.0.71
23 Feb 16:36:22 ntpd[446]: ntpd 4.2.8p12@1.3728-o (1): Starting
23 Feb 16:36:22 ntpd[446]: Command line: ntpd -g -x -q 192.168.0.71
23 Feb 16:36:22 ntpd[446]: proto: precision = 0.815 usec (-20)
23 Feb 16:36:22 ntpd[446]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): good hash signature
23 Feb 16:36:22 ntpd[446]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): loaded, expire=2021-06-28T00:00:00Z last=2017-01-01T00:00:00Z ofs=37
23 Feb 16:36:22 ntpd[446]: Listen and drop on 0 v6wildcard [::]:123
23 Feb 16:36:22 ntpd[446]: Listen and drop on 1 v4wildcard 0.0.0.0:123
23 Feb 16:36:22 ntpd[446]: Listen normally on 2 lo 127.0.0.1:123
23 Feb 16:36:22 ntpd[446]: Listen normally on 3 eth0 192.168.0.72:123
23 Feb 16:36:22 ntpd[446]: Listen normally on 4 lo [::1]:123
23 Feb 16:36:22 ntpd[446]: Listen normally on 5 eth0 [fe80::dea6:32ff:fee4:8867%2]:123
23 Feb 16:36:22 ntpd[446]: Listening on routing socket on fd #22 for interface updates
23 Feb 16:36:22 ntpd[446]: Listen for broadcasts to 192.168.0.255 on interface #3 eth0
23 Feb 16:36:29 ntpd[446]: ntpd: time slew +25.555462 s
ntpd: time slew +25.555462s
root@displaypi:~# date
Tue Feb 23 16:36:31 IST 2021
root@displaypi:~# date
Tue Feb 23 16:36:39 IST 2021
root@displaypi:~# date
Tue Feb 23 16:36:59 IST 2021
root@displaypi:~# ntpq -p
ntpq: read: Connection refused
root@displaypi:~# service ntp start
root@displaypi:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.0.71 LOCAL(0) 4 u 1 16 1 0.192 25533.4 0.001
root@displaypi:~# service ntp sto
Usage: /etc/init.d/ntp {start|stop|restart|try-restart|force-reload|status}
root@displaypi:~# service ntp stop
root@displaypi:~# ntpd -g -x -q 192.168.0.71
23 Feb 16:38:03 ntpd[513]: ntpd 4.2.8p12@1.3728-o (1): Starting
23 Feb 16:38:03 ntpd[513]: Command line: ntpd -g -x -q 192.168.0.71
23 Feb 16:38:03 ntpd[513]: proto: precision = 0.778 usec (-20)
23 Feb 16:38:03 ntpd[513]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): good hash signature
23 Feb 16:38:03 ntpd[513]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): loaded, expire=2021-06-28T00:00:00Z last=2017-01-01T00:00:00Z ofs=37
23 Feb 16:38:03 ntpd[513]: Listen and drop on 0 v6wildcard [::]:123
23 Feb 16:38:03 ntpd[513]: Listen and drop on 1 v4wildcard 0.0.0.0:123
23 Feb 16:38:03 ntpd[513]: Listen normally on 2 lo 127.0.0.1:123
23 Feb 16:38:03 ntpd[513]: Listen normally on 3 eth0 192.168.0.72:123
23 Feb 16:38:03 ntpd[513]: Listen normally on 4 lo [::1]:123
23 Feb 16:38:03 ntpd[513]: Listen normally on 5 eth0 [fe80::dea6:32ff:fee4:8867%2]:123
23 Feb 16:38:03 ntpd[513]: Listening on routing socket on fd #22 for interface updates
23 Feb 16:38:03 ntpd[513]: Listen for broadcasts to 192.168.0.255 on interface #3 eth0
23 Feb 16:38:10 ntpd[513]: ntpd: time slew +0.000000 s
ntpd: time slew +0.000000s发布于 2021-02-23 09:06:23
您可以使用-g参数。在这篇文章中:
-g通常情况下,如果偏移量超过恐慌阈值(默认为1000 S),ntpd将带消息退出系统日志。此选项允许不受限制地将时间设置为任何值;然而,这种情况只能发生一次。如果在此之后超过阈值,ntpd将退出,并向系统日志发送一条消息。此选项可与-q和-x选项一起使用。有关其他选项,请参见tinker命令。
因此,在启动时,您必须运行一次(添加到某个启动脚本)以下命令(用您自己的NTP服务器替换pool.ntp.org )来同步本地时钟:ntpd -g -x -q pool.ntp.org
之后,您可以正常运行ntpd。
发布于 2021-02-23 10:34:06
除了上面描述的-g标志之外,您还应该将iburst添加到客户机上的server行中。这将使它们更快地同步到服务器。
但是,您不能期望您的服务器设置能够很好地工作,因为您没有外部引用时钟,而且您正在将服务器的本地时钟强制到一个较高的层次。您需要有一条通往第一层参考时钟的路径,无论是在本地局域网上,还是通过Internet。
此外,如果同时在客户端和服务器上都失去了功能,您可以预期所有客户机都会跳到稍微不同的位置(请参阅尽管在引导前NTP同步,系统时间却被关闭了数百毫秒. ),最终可能导致服务器向后跳,而客户机则会向前跳,这意味着当客户端同步时,他们可能会看到一个大的(按NTP术语表示)向后跳。如果您的服务器需要比客户端更长的启动时间,这可能会更大(这种情况并不少见)。
你真的无法摆脱在某个地方有一个1层参考时钟的要求。如果时间对你如此重要,最好投资于一个低功耗的GPS同步设备,比如BeagleBone、Raspberry Pi或LeoNTP,所有这些都可以在一个小型的GPS上运行好几个小时。
发布于 2021-02-23 22:53:19
你想做的事是不可能的。两个时钟是同步的当且仅当两个时钟的流量已被平衡。否则,它们是不同步的。没有即时的方法来观察一个时钟的流动速度或比较两个时钟流动的速度。
给定每个时钟的时间分辨率,它们之间的通信延迟,该延迟中的抖动,该延迟的最大不对称性,以及所需的时钟同步精度,可以确定完成同步所需的最小时间。
如果您使用适当的ntp设置(如burst或iburst),那么它很可能与您所得到的大小相同。
https://serverfault.com/questions/1054687
复制相似问题