我正在尝试在运行 Ubuntu 20.04(无头)的 SBC 上设置 GPS NTP 服务器,但遇到了配置问题。重新启动时,我收到以下信息:
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*_gateway 163.237.218.18 2 u 22 64 1 2.727 0.011 0.159
/etc/ntp.conf 说:
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
# 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
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# 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
# GPS Serial data reference
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.0 refid GPS
# GPS PPS reference
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid PPS
/etc/ntp/step-tickers
为空
我在互联网上找到了制作作为 GPS 时间服务器运行的“设备”的配置,它说要这样做:
$ su -
# killall -9 gpsd ntpd
# gpsd -n /dev/ttyXX
# sleep 2
# ntpd -gN
# sleep 2
# cgps
而且有效
root@ubuntu:/home/zach# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
*SHM(0) .GPS. 0 l 8 16 1 0.000 -40.232 0.000
SHM(1) .PPS. 0 l - 16 0 0.000 0.000 0.000
知道为什么我无法让 ntp 在启动时读取 /etc/ntp.conf 吗?
编辑:我不确定 gpsd 是否在启动时运行。
我执行了 dmesg | grep gps 但什么也没有出现。
然后我编写了一个包含该 killall 行的 bash 脚本。但我认为它不会运行(crontab 中的 @startup sh),因为它必须被提升。我尝试将其作为 init.d(我真的不知道我在那里做什么),然后收到一条错误消息 audit: type=1400 audit(1636322022.316:45): apparmor="DENIED" operation="ptrace" profile="/usr/sbin/gpsd" pid=2794 comm="gpsd" requested_mask="read" denied_mask="read" peer="/usr/sbin/ntpd"
答案1
好的,感谢@ChristianEhrhardt,出于某些我不知道的原因,Chrony 的使用似乎运行得很好。
我已经运行了 gpsd,所以不需要再去弄它了,但在这里指出这一点很重要。我使用通过 USB 插入的 GPS,不是PPS。设备是 ttyACM0
我在网上使用了几个指南,但我不确定精确的我采取了以下措施但结果如下:
sudo apt install chrony
然后我必须配置 .conf 文件
sudo nano /etc/chrony/chrony.conf
我发现,为了让 GPS 时间服务器真正为其他计算机提供时间,我必须取消注释,如下所示。我有多个子网,所以我把它打开了
#Allow to be a NTP server
allow 192.168.0.0/24
我需要添加我的 GPS 源,因此我添加了:
#GPS Sources
refclock SHM 0 refid GPS precision 1e-1 offset 0 delay 0 stratum 2
refclock SOCK /var/run/chrony.ttyACM0.sock refid PPS
我知道重新启动服务是一回事,但我更喜欢重新启动。
sudo reboot now
然后我将其启用为服务
systemctl enable chrony
然后我检查了一下,确保它能正常工作
chronyc sources
最后我确认它正在为其他计算机提供服务。我去了另一台机器并检查ntpq -p
和 TA-DA