Chrony 和 GPSD

来自 Alpine Linux

例如以下来源

描述如何将 Garmin gps 18 lvc 连接到串口以获取 PPS (每秒脉冲) 信号,从而创建一个 Stratum 1 时间源。其他来源显示使用 ntpd,并且 gpsd 手册页 提供了配置代码片段。


Alpine Linux gpsd 软件包 3.9-r1 及更高版本具有与 chrony 接口所需的 pps 代码。此页面列出了完整的工作示例的所有文件


  • /etc/modules 需要列出 pps_ldisc 模块 - 如果不重启,您需要手动加载它

/etc/modules 的内容

pps_ldisc
  • 如果 GPS 18 LVC 在 /dev/ttyS1 上,则

/etc/conf.d/gpsd 的内容

# Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Config file for gpsd server # Optional arguments # Options include: # -b = bluetooth-safe: open data sources read-only # -n = don't wait for client connects to poll GPS # -N = don't go into background # -F sockfile = specify control socket location # -G = make gpsd listen on INADDR_ANY # -D integer (default 0) = set debug level # -S integer (default 2947) = set port for daemon GPSD_OPTIONS="-n -b" DEVICES="/dev/ttyS1" GPSD_SOCKET="/var/run/gpsd.sock" BAUDRATE="4800" # Serial setup # # For serial interfaces, options such as low_latency are recommended # Also, https://gpsd.gitlab.io/gpsd/upstream-bugs.html#tiocmwait recommends # setting the baudrate with stty # Uncomment the following lines if using a serial device: # /bin/stty -F ${DEVICE} ${BAUDRATE} /bin/setserial ${DEVICE} low_latency


注:从 v3.11 开始,init.d 和 conf.d 文件已从 gentoo 合并。

目的是允许 gpsd 在不编辑 /etc/conf.d/gpsd 的情况下启动。请注意,虽然 gpsd 现在可以在不编辑 conf.d 文件的情况下启动,但它将在没有连接任何 gps 设备的情况下启动。

另请注意,如果您使用的是串行设备,仍然建议添加 stty 和 setserial 命令,如上面的示例配置中所述。


  • 这显示了从 gpsd 获取时间的所有四种方法

/etc/chrony/chrony.conf 的内容

server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org initstepslew 30 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org # SHM0 from gpsd is the NMEA data at 4800bps, so is not very accurate refclock SHM 0 delay 0.5 refid NMEA # SHM1 from gpsd (if present) is from the kernel PPS_LDISC # module. It includes PPS and will be accurate to a few ns refclock SHM 1 offset 0.0 delay 0.1 refid NMEA+ # SOCK protocol also includes PPS data and # it also provides time within a few ns refclock SOCK /var/run/chrony.ttyS1.sock delay 0.0 refid SOCK # PPS is from the /dev/pps0 device. Note that # chronyd creates the /var/run/chrony.ttyS1.sock device, but # gpsd creates the /dev/pps0 device # openrc rules start gpsd /after/ chronyd, so /dev/pps0 # is not created until after chronyd is started # If you want to use pps0, either edit the openrc rules # or add this source after gpsd is started # refclock PPS /dev/pps0 refid PPS # If you see something in ns... its good. # 1 second = # 1000 ms = # 1000000 us = # 1000000000 ns logchange 0.5 local stratum 10 logdir /var/log/chrony keyfile /etc/chrony/chrony.keys commandkey 10 dumpdir /var/log/chrony driftfile /var/log/chrony/chrony.drift allow all

Chronyc

如果一切正常,chronyc 'sources' 命令应如下所示

chronyc> sources
210 Number of sources = 6
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#x NMEA                          0   4   377    14   +684ms[ +684ms] +/-  252ms
#+ PPS                           0   4   377    13  +2040ns[+2060ns] +/-   50ms
#* SOCK                          0   4   377     7   +225ns[ +245ns] +/- 2217ns
^? tick.tock.com                 2  10   377   318  -5144us[-5144us] +/-   72ms
^? time.keeper.net               3  10   377   720  -4571us[-4567us] +/-  139ms
^? dead.time.server.org          0  10     0   10y     +0ns[   +0ns] +/-    0ns
  • NMEA (SHM0) 是 "x" - 它非常不稳定
  • PPS (SHM1) 很好,但 0.1 的延迟使其不是首选主服务器
  • SOCK 是首选主服务器
  • 其他 NTP 服务器仅在本地服务器宕机时使用。

注释

  • 在 /etc/chrony/chrony.conf 中,有四个可能的时间源
    • SHM 0 (NMEA 串行数据)
    • SHM 1 (带有 PPS 的 NMEA)
    • SOCK (PPS '专有' gpsd/chrony 接口)
    • PPS (仅来自串行接口脉冲的 PPS)
  • 您只需要其中 1 个,尽管上面显示了 3 个
  • 在上面的示例中,SHM1 指定了 0.1 的延迟,以防止它与 SOCK 协议竞争
    • 如果您更喜欢使用 SHM1 源而不是 SOCK,则可以
      • 注释掉 SOCK 协议行
      • 或反转延迟值。
  • 请注意,SHM0 源(仅 NMEA,没有 PPS)设置为更高的延迟 - 如果您有 PPS 可用,请不要使用它。
    • 您可能想要使用 SHM0 的一个示例是基于 USB 的 gps 接收器 - 它们没有 PPS 线
  • Chrony 创建 SOCK 接口;chrony 应在 gpsd 之前启动。如果您由于某种原因重启了 chronyd,请确保之后重启 gpsd。
  • SHM0 接口可以与基于 USB 的 gps 设备一起使用。在这种情况下,请在 /etc/conf.d/gpsd 文件中使用 /dev/ttyUSBX,并将 stty 和 setserial 行注释掉。