我正在努力理解为什么 ntp(服务)不会在我的树莓派上正确设置时间。
我已将文件系统配置为只读,以保存我的 SD 卡,但它曾经可以工作,而且我似乎无法弄清楚为什么 ntp 现在无法工作。
在日志中,我收到了该消息的许多行:
ntpd[415]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
ntpd[415]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
ntpd[415]: error resolving pool 0.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 1.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 2.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 3.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 3.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 2.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 1.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 0.debian.pool.ntp.org: Temporary failure in name resolution (-3)
Run Code Online (Sandbox Code Playgroud)
我的 /etc/resolv.conf 看起来像这样:
# Generated by resolvconf
nameserver 8.8.8.8
nameserver 192.168.1.22
Run Code Online (Sandbox Code Playgroud)
我可以在那个 RPi 上访问互联网,我可以 ping 池地址,我可以 ping 谷歌,我可以 apt 更新(在 rw 中重新安装后)...
我也可以手动发出 ntpdate 命令并且它可以工作!
$ sudo ntpdate -u 0.fr.pool.ntp.org 1.fr.pool.ntp.org
24 Nov 23:04:34 ntpdate[578]: step time server 129.250.35.250 offset 2418.621037 sec
Run Code Online (Sandbox Code Playgroud)
所以是的,我在这里拉头发。我不明白为什么 ntp 服务不起作用。我在互联网上肆虐,似乎没有人遇到这个特殊问题(所有 dns 都出现故障,但我的工作正常)
我的只读设置如下:https : //hallard.me/raspberry-pi-read-only/
你们有什么想法吗?
小智 6
我在遇到类似问题时发现了这个问题。
这个问题竟然是那systemd的PrivateTmp特征没有在一个只读的配置工作。
ntp并ntpdate
sudo apt install -y ntp ntpdate
Run Code Online (Sandbox Code Playgroud)复制/lib/systemd/system/ntp.service到/etc/systemd/system/ntp.service
cp /lib/systemd/system/ntp.service /etc/systemd/system/ntp.service
Run Code Online (Sandbox Code Playgroud)打开/etc/systemd/system/ntp.service并注释掉PrivateTmp=true。
sudo nano /etc/systemd/system/ntp.service
Run Code Online (Sandbox Code Playgroud)现在,它应该可以正常工作了!
另外还有一个步骤我现在也安装/var/lib/ntp作为tmpfs推荐这里
/etc/fstab并添加tmpfs /var/lib/ntp tmpfs nosuid,nodev 0 0到文件末尾。
sudo nano /etc/fstab
Run Code Online (Sandbox Code Playgroud)在我的情况下,我认为这没有必要,但还有其他关于在只读文件系统上运行的见解。