Sap*_*Sap 4 linux ntp time time-synchronization ntpd
我已经设置了一台 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
Run Code Online (Sandbox Code Playgroud)
客户端ntp配置
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
Run Code Online (Sandbox Code Playgroud)
编辑添加建议命令的结果
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
Run Code Online (Sandbox Code Playgroud)
bas*_*kat 11
您可以使用-g参数。从联机帮助页:
-G
通常,如果偏移量超过恐慌阈值(默认为 1000 秒),ntpd 会退出并在系统日志中显示一条消息。此选项允许将时间设置为任何值而不受限制;然而,这只能发生一次。如果此后超过阈值,ntpd 将退出并在系统日志中显示一条消息。此选项可与 -q 和 -x 选项一起使用。有关其他选项,请参阅 tinker 命令。
因此,在启动时,您必须运行一次(添加到一些启动脚本)以下命令(用您自己的 NTP 服务器替换 pool.ntp.org)以同步本地时钟:
ntpd -g -x -q pool.ntp.org
之后,您可以正常运行 ntpd。
除了上述-g
标志外,您还应该添加iburst
到server
客户端的行中。这将使它们更快地同步到服务器。
但是,您不能指望您的服务器设置运行良好,因为您没有外部参考时钟,并且您将服务器的本地时钟强制设置为高电平。您需要有一条通向第 1 层参考时钟的路径,无论是在您的 LAN 本地还是通过 Internet。
此外,如果您同时失去客户端和服务器的电源,您可以期望它们全部跳动(请参阅示例,尽管启动前 NTP 同步,但系统时间仍关闭数百毫秒)略有不同,并且您最终可能会在客户端向前跳转时服务器向后跳转,这意味着当客户端同步时,他们可以看到一个大的(在 NTP 术语中)向后跳转。如果您的服务器启动所需的时间比您的客户端长(这种情况并不罕见),则这可能会更大。
您真的无法摆脱在某处拥有第 1 层参考时钟的要求。如果时间对您来说很重要,最好投资购买低功耗 GPS 同步设备,例如 BeagleBone、Raspberry Pi 或 LeoNTP,所有这些设备都可以在小型 UPS 上运行数小时。
归档时间: |
|
查看次数: |
1309 次 |
最近记录: |