我需要创建设备(当前基于 Raspberry Pi 3),该设备声明为 NTP 服务器,它没有与互联网的连接,并且 NTP 应该从本地系统时钟读取实际时间(该时钟是从应用程序设置的)。我的/etc/ntp.conf是:
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict ::1
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 1
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log
当使用命令测试连接(之后service ntp restart
)时,ntpdate -du localhost
我得到以下输出:
transmit(::1)
receive(::1)
transmit(127.0.0.1)
receive(127.0.0.1)
transmit(::1)
receive(::1)
transmit(127.0.0.1)
receive(127.0.0.1)
transmit(::1)
receive(::1)
transmit(127.0.0.1)
receive(127.0.0.1)
transmit(::1)
receive(::1)
transmit(127.0.0.1)
receive(127.0.0.1)
::1: Server dropped: strata too high
127.0.0.1: Server dropped: strata too high
server ::1, port 123
stratum 16, precision -20, leap 11, trust 000
refid [::1], delay 0.02573, dispersion 0.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Thu, Feb 7 2036 6:28:16.000
originate timestamp: ddbf0da9.473a860b Tue, Nov 21 2017 20:40:09.278
transmit timestamp: ddbf0da9.47320583 Tue, Nov 21 2017 20:40:09.278
filter delay: 0.02579 0.02573 0.02574 0.02573
0.00000 0.00000 0.00000 0.00000
filter offset: 0.000018 -0.00001 -0.00000 -0.00001
0.000000 0.000000 0.000000 0.000000
delay 0.02573, dispersion 0.00000
offset -0.000011
server 127.0.0.1, port 123
stratum 16, precision -20, leap 11, trust 000
refid [127.0.0.1], delay 0.02570, dispersion 0.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Thu, Feb 7 2036 6:28:16.000
originate timestamp: ddbf0da9.7a812105 Tue, Nov 21 2017 20:40:09.478
transmit timestamp: ddbf0da9.7a7990a1 Tue, Nov 21 2017 20:40:09.478
filter delay: 0.02571 0.02570 0.02570 0.02570
0.00000 0.00000 0.00000 0.00000
filter offset: -0.00000 -0.00001 -0.00001 -0.00001
0.000000 0.000000 0.000000 0.000000
delay 0.02570, dispersion 0.00000
offset -0.000013
21 Nov 20:40:09 ntpdate[1181]: no server suitable for synchronization found
我究竟做错了什么?为什么ntp
无法从系统时钟获取时间?
答案1
由于该server
语句不包含iburst
关键字,ntpd 重新启动后可能需要几分钟才能与时间源同步。在此期间,它向其他服务器提供的答案被认为是不可靠的。
是的,即使它有效地与自身同步。
在ntpdate -d
输出中,这stratum 16, precision -20, leap 11
意味着 ntpd 认为“我现在还没有准备好向任何其他人提供时间服务。”