Time server setup
Jump to navigation
Jump to search
Some steps to remember when setting up a Raspberry Pi based network time server.
Boot setup files
Add to /etc/modules
i2c-dev
pps-gpio
Add to /boot/config.txt
dtoverlay=pi3-miniuart-bt
dtoverlay=pps-gpio
Add to /boot/cmdline.txt at end of single line
init_uart_baud=9600
Installations
Install several extra tools
- ntp-utils
- ntpsec
- minicom
- gpsd
- pps
- pps-tools
- ptpd
Disable serial login on AMA0 device.
systemctl mask serial-getty@ttyAMA0.service
Disable unused services like cupsd.
Defaults
Update /etc/defaults/gpsd to
# Default settings for the gpsd init script and the hotplug wrapper.
# Start the gpsd daemon automatically at boot time
START_DAEMON="true"
# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="false"
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0"
# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"
Update /etc/defaults/ntpsec to
NTPD_OPTS="-g -N"
# Set to "yes" to ignore DHCP servers returned by DHCP.
IGNORE_DHCP=""
Update /etc/defaults/ptpd to
# /etc/default/ptpd
# Set to "yes" to actually start ptpd automatically
START_DAEMON=yes
# Add command line options for ptpd
PTPD_OPTS="-c /etc/ptpd2.conf"
Service setup files
Update /etc/ntpsec/ntp.conf to
# /etc/ntpsec/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
# You must create /var/log/ntpsec (owned by ntpsec:ntpsec) to enable logging.
statsdir /var/log/ntpsec/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# Comment this out if you have a refclock and want it to be able to discipline
# the clock by itself (e.g. if the system is not connected to the network).
#tos minclock 4 minsane 3
# Specify one or more NTP servers.
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <https://www.pool.ntp.org/join.html>
pool 0.de.pool.ntp.org iburst maxpoll 5
#pool 1.de.pool.ntp.org iburst
#pool 2.de.pool.ntp.org iburst
#pool 3.de.pool.ntp.org iburst
# Access control configuration; see /usr/share/doc/ntpsec-doc/html/accopt.html
# for details.
#
# 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 default kod nomodify nopeer noquery limited
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# GPS Serial data reference (NTP0)
server 127.127.28.0
fudge 127.127.28.0 time1 +0.100 refid GPS
# GPS PPS reference (NTP1)
server 127.127.28.1 prefer
fudge 127.127.28.1 refid PPS
Update /etc/ptpd2.conf to
#
# config
#
ptpengine:interface=eth0
ptpengine:preset=masteronly
ptpengine:transport=ethernet
#ptpengine:transport=ipv4
ptpengine:ptp_timesource=GPS
ptpengine:ptp_clock_accuracy=ACC_100US
#ptpengine:prefer_ntp=Y
#ntpengine:enabled=Y
global:use_syslog=Y
global:log_status=Y
Final result
With some luck and reboots the ntpq -p command should show:
root@clock:/etc# ntpq -p
remote refid st t when poll reach delay offset jitter
=======================================================================================================
0.de.pool.ntp.org .POOL. 16 p - 32 0 0.0000 0.0000 0.0010
+SHM(0) .GPS. 0 l 59 64 377 0.0000 -2.5372 0.6387
*SHM(1) .PPS. 0 l 58 64 377 0.0000 0.0027 0.0020
-static.102.162.46.78.clients.your-serve 131.188.3.223 2 u 4 32 377 23.0398 5.2349 2.0621
-ntp1.sul.t-online.de 172.20.96.197 2 u 29 32 377 24.0259 2.1013 3.3369
-kuehlich.com 131.188.3.221 2 u 19 32 377 28.6138 4.2736 5.8902
-ntp2.wtnet.de 10.129.9.96 2 u 26 32 377 28.5456 -9.2126 4.9001
+time.cloudflare.com 10.48.8.4 3 u 19 32 377 18.1886 6.0767 5.8235
-telesto.hot-chilli.net 131.188.3.222 2 u 26 32 277 24.0233 2.5571 5.9801
-nono.com 242.71.143.169 2 u 10 32 377 25.0837 3.8292 3.0114
Which is good enough for me to play with.