NTPd 在 RaspberryPi 上不同步

NTPd 在 RaspberryPi 上不同步

由于我的硬件 (RasberryPi) 没有硬件时钟,每次启动都会让我们回到 1970 年代,所以我使用 NTP。我所在网络上的网关提供 NTP 服务器服务。

我的/etc/ntp.conf看起来像以下(省略注释行)

server 192.168.170.254 //gateway that hosts the service
driftfile /var/lib/ntp/ntp.drift

/etc/profile:

[connect wifi...]
timeout 15 ntpd -q -g //forces update so I have a time to work with, times out so I don't get a total hang if it doesn't work
systemctl start ntpd.service //in hopes that I will work at some point and to keep it in sync
date //see if it worked
[start main program...]

我错过了什么吗?

编辑
输出ntpd -q

DEC 31 17:00:43 alarmpi ntpd[349]: ntpd [email protected] Wed Jul  2 03:23:39 UTC 2014 (1): Starting
DEC 31 17:00:43 alarmpi ntpd[349]: Command line: /usr/bin/ntpd -q
DEC 31 17:00:43 alarmpi ntpd[349]: proto: precision = 3000 usec (-18)
DEC 31 17:00:43 alarmpi ntpd[349]: Listen and drop on 0 v4wildcard 0.0.0.0:123
DEC 31 17:00:43 alarmpi ntpd[349]: Listen normally on 1 lo 127.0.0.1:123
DEC 31 17:00:43 alarmpi ntpd[349]: Listen normally on 2 wlan0 192.168.170.100:123
DEC 31 17:00:43 alarmpi ntpd[349]: Listening on routing socket on fd #19 for interface updates
#hangs here till interrupted

输出systemctl status ntpd

* ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled)
Active: active (running) since Wed 1969-12-31 17:00:43 MST, 16s ago
Process: 332 ExecStart=/usr/bin/ntpd -g -u ntp:ntp -p /run/ntpd.pid (code=exited, status=0/SUCCESS)
Main PID: 335 (ntpd)
CGroup: /system.slice/ntpd.service
        `-335 /usr/bin/ntpd -g -u ntp:ntp -p /run/ntpd.pid

DEC 31 17:00:43 alarmpi ntpd[332]: ntpd [email protected] Wed Jul  2 03:23:39 UTC 2014 (1): Starting
DEC 31 17:00:43 alarmpi ntpd[332]: Command line: /usr/bin/ntpd -g -u ntp:ntp -q /run/ntpd.pid
DEC 31 17:00:43 alarmpi systemd[1]: PID file /run/ntpd.pid not readable (yet?) after start.
DEC 31 17:00:43 alarmpi ntpd[335]: proto: precision = 3000 usec (-18)
DEC 31 17:00:43 alarmpi ntpd[335]: Listen and drop on 0 v4wildcard 0.0.0.0:123
DEC 31 17:00:43 alarmpi ntpd[335]: Listen normally on 1 lo 127.0.0.1:123
DEC 31 17:00:43 alarmpi ntpd[335]: Listen normally on 2 wlan0 192.168.170.100:123
DEC 31 17:00:43 alarmpi ntpd[335]: Listening on routing socket on fd #19 for interface updates
DEC 31 17:00:43 alarmpi systemd[1]: Started Network Time Service

答案1

@ason​​wryan的回答另一个问题很好的解决了这个问题。硬件问题(缺乏实时时钟)使这有点困难。

考虑到 RaspberryPi 的不足实时时钟,我建议您确保使用一个可以将上次时间存储到磁盘的工具,然后在启动时引用该工具将时钟从UNIX时代的黎明

使用组合systemd-时间同步,以及您的首选时间服务器的可选配置文件/etc/systemd/timesyncd.conf,以及systemd-networkd将在启动时快速启动您的网络并纠正时钟中的任何偏差尽早。然后,守护进程将定期(大约每 30 分钟)同步您的时钟。

相关内容