Software:NtpServer
From ROBOVIS Public Wiki
Sometimes when out in the field, several machines need to be time-synchronised. It usually isn’t super-important if the absolute time is wrong, just so long as the relative time differences between machines is very small. To do this:
- Pick a master computer. All the others will synch to this.
- Set up the master to sync to absolute time when in the lab, and itself
when in the field.
- Set up all the others to sync to the master.
Note that this how-to refers to some debian/ubuntu specific commands. For the most part, the ntp stuff is OS independent.
Contents[hide] |
[edit] Install
Before you start, install everything with:
# apt-get install ntp ntpdate
on all machines.
[edit] Set up the Master
Copy the following into the master’s /etc/ntp.conf:
# /etc/ntp.conf, configuration for ntpd driftfile /var/lib/ntp/ntp.drift statsdir /var/log/ntpstats/ 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 # You do need to talk to an NTP server or two (or three). server ntp0.uq.edu.au # ... and use the local system clock as a reference if all else fails # NOTE: in a local network, set the local stratum of *one* stable server # to 10; otherwise your clocks will drift apart if you lose connectivity. server 127.127.1.0 fudge 127.127.1.0 stratum 5 # By default, exchange time with everybody, but don't allow configuration. # See /usr/share/doc/ntp-doc/html/accopt.html for details. restrict default kod notrap nomodify nopeer noquery # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 nomodify
Note:
- We try to lock to ntp0.uq.edu.au
- 127.127.1.0 says ‘lock to myself’ (ignore the fact that this isn’t your
IP). – It is an ID for an internal ntp reference clock based on your hardware clock.
- Our stratum (5) is lower than ntp.uq’s (2). This tells ntp that
ntp.uq’s clock is more reliable than ours.
[edit] Set up the Slaves
Copy the following into /etc/ntp.conf on each slave (ntp clients):
# /etc/ntp.conf, configuration for ntpd driftfile /var/lib/ntp/ntp.drift statsdir /var/log/ntpstats/ 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 # You do need to talk to an NTP server or two (or three). server <master> # By default, exchange time with everybody, but don't allow configuration. # See /usr/share/doc/ntp-doc/html/accopt.html for details. restrict default kod notrap nomodify nopeer noquery # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 nomodify
Note:
- replace <master> with the name or IP of your master.
[edit] Start and Test Everything
Start the ntp daemon on the master:
[root@master]# /etc/init.d/ntp stop [root@master]# /usr/sbin/ntpdate ntp.usyd.edu.au [root@master]# /etc/init.d/ntp start
Wait for the master to lock to something. You can see what’s going on with:
# ntpq -p
An ‘*’ in the first column signifies the server that we’re locked to. Be patient, it takes a few minutes for things to synch.
Then fire up the slaves:
[root@slave]# /etc/init.d/ntp stop [root@slave]# /usr/sbin/ntpdate <master> [root@slave]# /etc/init.d/ntp start
The ‘ntpdate’ line does a coarse synch to the master.
Then watch with ‘ntpq -p’. Hopefully the slaves will eventually lock to the master.