ntp支持的外部时钟源

公司先后采购过多种GPS授时服务器。之前一直不是太明白ntpd是如何使用外接的这些硬件。
这两年树莓派比较流行,也有很大人利用外接的扩展件让树莓派成为一级时钟源。其中关键的ntp.conf配置如下


driftfile /var/lib/ntp/ntp.drift

# coarse time ref-clock, not really needed here as we have LAN & WAN servers
server 127.127.28.0  minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 +0.350 refid GPS  stratum 15

# Kernel-mode PPS ref-clock for the precise seconds
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0  refid PPS

# LAN servers
server 192.168.0.3  minpoll 5 maxpoll 5 iburst prefer
server 192.168.0.2  minpoll 5 maxpoll 5 iburst
server 192.168.0.7  minpoll 5 maxpoll 5 iburst

对比了公司采购的GPS授时服务器的配置


NTP-SERVER:/#ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*127.127.20.1    .GPS.            0 l   16   16  377    0.000    0.002   0.001
 127.127.1.0     .LCK.            0 l    -   16  377    0.000    0.000   0.001
NTP-SERVER:/#cat /etc/ntp.conf|grep -v "^#"|grep '[a-z]'
server  127.127.20.1 prefer mode 17 minpoll 4
fudge   127.127.20.1 stratum 0 refid GPS flag2 1 flag3 1
server  127.127.1.0 minpoll 4   maxpoll 4
fudge   127.127.1.0 stratum 0 refid LCK
driftfile /var/drift
broadcastdelay  0.008
authenticate yes
keys        /etc/ntp/keys
logconfig =clockevents +syncevents +sysevents +clockall +syncall +sysall

server和fudge的相关说明如下


       The  fudge  command  is  used  to provide additional information for individual clock drivers and normally follows immediately after the server command. The address
       argument specifies the clock address. The refid and stratum options control can be used to override the defaults for the device.  There  are  two  optional  device-
       dependent time offsets and four flags that can be included in the fudge command as well.
       The  stratum  number  of  a  reference clock is by default zero. Since the ntpd daemon adds one to the stratum of each peer, a primary server ordinarily displays an
       external stratum of one. In order to provide engineered backups, it is often useful to specify the reference clock stratum as greater than zero. The stratum  option
       is  used  for  this  purpose.  Also, in cases involving both a reference clock and a pulse-per-second (PPS) discipline signal, it is useful to specify the reference
       clock identifier as other than the default, depending on the driver. The refid option is used for this purpose. Except where noted, these options apply to all clock
       drivers.
REFERENCE CLOCK COMMANDS
       server 127.127.t.u [prefer] [mode int] [minpoll int] [maxpoll int]
               This command can be used to configure reference clocks in special ways. The options are interpreted as follows:
               prefer  Marks  the reference clock as preferred. All other things being equal, this host will be chosen for synchronization among a set of correctly operat‐
                       ing hosts. See the Mitigation Rules and the prefer Keyword page for further information.
               mode int
                       Specifies a mode number which is interpreted in a device-specific fashion. For instance, it selects a dialing protocol in  the  ACTS  driver  and  a
                       device subtype in the parse drivers.
               minpoll int
               maxpoll int
                       These  options specify the minimum and maximum polling interval for reference clock messages in seconds, interpreted as dual logarithms (2 ^ x). For
                       most directly connected reference clocks, both minpoll and maxpoll default to 6 (2^16 = 64 s). For modem reference clocks, minpoll  defaults  to  10
                       (2^10 = 1024 s = 17.1 m) and maxpoll defaults to 14 (2^14 = 16384 s = 4.5 h). The allowable range is 4 (16 s) to 17 (36.4 h) inclusive.
       fudge 127.127.t.u [time1 sec] [time2 sec] [stratum int] [refid string] [flag1 0|1] [flag2 0|1] [flag3 0|1] [flag4 0|1]
               This command can be used to configure reference clocks in special ways. It must immediately follow the server command which configures the driver. Note that
               the same capability is possible at run time using the ntpdc program. The options are interpreted as follows:
               time1 sec
                       Specifies a constant to be added to the time offset produced by the driver, a fixed-point decimal number in seconds. This is used as  a  calibration
                       constant  to  adjust  the nominal time offset of a particular clock to agree with an external standard, such as a precision PPS signal. It also pro‐
                       vides a way to correct a systematic error or bias due to serial port or operating system latencies, different cable  lengths  or  receiver  internal
                       delay.  The  specified offset is in addition to the propagation delay provided by other means, such as internal DIPswitches. Where a calibration for
                       an individual system and driver is available, an approximate correction is noted in the driver documentation pages.  Note: in  order  to  facilitate
                       calibration  when more than one radio clock or PPS signal is supported, a special calibration feature is available. It takes the form of an argument
                       to the enable command described in the Miscellaneous Options page and operates as described in the Reference Clock Drivers page.
               time2 secs
                       Specifies a fixed-point decimal number in seconds, which is interpreted in a driver-dependent way. See the descriptions of specific drivers  in  the
                       reference clock drivers page.
               stratum int
                       Specifies  the  stratum  number  assigned  to  the  driver, an integer between 0 and 15. This number overrides the default stratum number ordinarily
                       assigned by the driver itself, usually zero.
               refid string
                       Specifies an ASCII string of from one to four characters which defines the reference identifier used  by  the  driver.  This  string  overrides  the
                       default identifier ordinarily assigned by the driver itself.
               flag1 flag2 flag3 flag4
                       These  four  flags are used for customizing the clock driver. The interpretation of these values, and whether they are used at all, is a function of
                       the particular clock driver. However, by convention flag4 is used to enable recording monitoring data to the clockstats  file  configured  with  the
                       filegen command. Further information on the filegen command can be found in the Monitoring Options page.

因此127.127.20.1实际是代表了type 20的时钟类型,1是代表单元号。当前ntpd支持的驱动如下

类型 编号
REFCLK_LOCALCLOCK 1
REFCLK_WWV_PST 3
REFCLK_WWVB_SPECTRACOM 4
REFCLK_TRUETIME 5
REFCLK_IRIG_AUDIO 6
REFCLK_CHU 7
REFCLK_GPS_MX4200 9
REFCLK_GPS_AS2201 10
REFCLK_GPS_ARBITER 11
REFCLK_IRIG_TPRO 12
REFCLK_ATOM_LEITCH 13
REFCLK_IRIG_BANCOMM 16
REFCLK_GPS_DATU 17
REFCLK_NIST_ACTS 18
REFCLK_WWV_HEATH 19
REFCLK_GPS_NMEA 20
REFCLK_GPS_VME 21
REFCLK_ATOM_PPS 22
REFCLK_GPS_HP 26
REFCLK_ARCRON_MSF 27
REFCLK_SHM 28
REFCLK_PALISADE 29
REFCLK_ONCORE 30
REFCLK_JUPITER 31
REFCLK_CHRONOLOG 32
REFCLK_DUMBCLOCK 33
REFCLK_ULINK 34
REFCLK_PCF 35
REFCLK_WWV 36
REFCLK_FG 37
REFCLK_HOPF_SERIAL 38
REFCLK_HOPF_PCI 39
REFCLK_JJY 40
REFCLK_TT560 41
REFCLK_ZYFER 42
REFCLK_RIPENCC 43
REFCLK_NEOCLOCK4X 44
REFCLK_TSYNCPCI 45
REFCLK_GPSDJSON 46
此条目发表在NTP分类目录。将固定链接加入收藏夹。

发表回复