
我很難理解為什麼 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)
我的 /etc/resolv.conf 看起來像這樣:
# Generated by resolvconf
nameserver 8.8.8.8
nameserver 192.168.1.22
我可以在該 RPi 上訪問互聯網,我可以 ping 池地址,我可以 ping google,我可以 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
所以是的,我在這裡拉頭髮。我不明白為什麼 ntp 服務不起作用。我搜遍了互聯網,似乎沒有人遇到這個特殊問題(所有人的 dns 都出現故障,但我的正在工作)
我的唯讀設定如下:https://hallard.me/raspberry-pi-read-only/
你們有什麼想法嗎?
答案1
我在面臨類似問題時發現了這個問題。
事實證明,問題在於systemd
該PrivateTmp
功能在唯讀配置中不起作用。
- 請務必安裝
ntp
並ntpdate
sudo apt install -y ntp ntpdate
複製
/lib/systemd/system/ntp.service
到/etc/systemd/system/ntp.service
cp /lib/systemd/system/ntp.service /etc/systemd/system/ntp.service
打開
/etc/systemd/system/ntp.service
並註解掉PrivateTmp=true
。sudo nano /etc/systemd/system/ntp.service
現在,它應該可以正常工作了!
作為附加步驟,我現在也/var/lib/ntp
按照tmpfs
建議安裝了這裡
- 打開
/etc/fstab
並添加到tmpfs /var/lib/ntp tmpfs nosuid,nodev 0 0
文件末尾。sudo nano /etc/fstab
我發現這對我的情況來說沒有必要,但是對於在只讀檔案系統上運行有更多的見解。
答案2
馬克羅傑的回答有效,但我認為最好用戶覆蓋:
echo -e '[Service]\nPrivateTmp=false' > /etc/systemd/system/ntp.service.d/override.conf
然後重新啟動或者也許就systemctl daemon-reload
足夠了。