[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
howtos:network_services:ntp [2012/09/25 03:14 (UTC)] – moved page from the general howtos namespace mfillpothowtos:network_services:ntp [2014/02/17 06:35 (UTC)] kikinovak
Line 6: Line 6:
   * configuring an NTP server on Slackware Linux;   * configuring an NTP server on Slackware Linux;
   * synchronizing client PCs with your local NTP server.   * synchronizing client PCs with your local NTP server.
 +
 +===== Introduction =====
 +
 +When several users manipulate shared data on different client PCs on a network, it's important that these machines are all synchronized. This is especially true if you share files over NFS, or if you use NIS for centralized authentication. You'll get all sorts of weird errors if your clocks are out of sync. Unfortunately, the clients' onboard clocks aren't sufficiently precise.
 +
 +That's where NTP (//Network Time Protocol//) comes in handy. It allows networked machines to adjust their clocks so as to be perfectly synchronized. A series of public time servers on the Internet allow the reception of the exact time. From this point, we can use NTP in several ways.
 +
 +  * The ''ntpdate'' command makes an initial correction of the BIOS clock.
 +  * This one-time-adjustment isn't sufficient for a server that is supposed to be up 24/7, since its clock will drift away gradually from the exact time. In that case, we have to configure the ''ntpd'' daemon (shipping with the ''ntp'' package). This daemon contacts public time servers at regular intervals and proceeds with incremental corrections of the local clock.
 +  * The ''ntpd'' daemon can in its turn be configured as a time server for the local client machines.
 +
 +It's considered good practice to use ''ntpdate'' for the initial adjustment and ''ntpd'' for regular time synchronization.
 +
 +===== Firewall considerations =====
 +
 +The NTP services uses UDP port 123. Open this port if you want to allow remote machines to connect to your NTP server.
  
 ===== Synchronize a LAN server or a public root server with an NTP server on the Internet ===== ===== Synchronize a LAN server or a public root server with an NTP server on the Internet =====
Line 58: Line 74:
  
 <code> <code>
-# chmod 0755 /etc/rc.d/rc.ntpd+# chmod +x /etc/rc.d/rc.ntpd
 </code> </code>
  
Line 82: Line 98:
 The little ''*'' asterisk preceding one of the above lines means your machine is effectively synchronized with the respective NTP server. The little ''*'' asterisk preceding one of the above lines means your machine is effectively synchronized with the respective NTP server.
  
-=== Synchronizing at boot time === +<note tip>The first synchronization can take few minutessometimes up to half an hour.</note>
-If instead of using daemonall you want to do is to synchronize time once per boot, it is possible to add the command ''ntpd -qg &'' in the bottom of the file ''/etc/rc.d/rc.local''. This will synchronize the time once in the background and will exit and it needs ''/etc/rc.d/rc.ntpd'' to not be an executable. +
-   +
-  ~# cat /etc/rc.d/rc.local +
-  #!/bin/sh +
-  # +
-  # /etc/rc.d/rc.local:  Local system initialization script. +
-  # +
-  # Put any local startup commands in here.  Also, if you have +
-  # anything that needs to be run at shutdown time you can +
-  # make an /etc/rc.d/rc.local_shutdown script and put those +
-  # commands in there. +
-  . +
-  . +
-  . +
-  ntpd -qg &+
  
-<note tip>The first synchronization can take a few minutes, sometimes up to half an hour.</note> 
 ===== Synchronize your client PC(s) with your local NTP server ===== ===== Synchronize your client PC(s) with your local NTP server =====
  
Line 139: Line 139:
  
 <code> <code>
-# chmod 0755 /etc/rc.d/rc.ntpd+# chmod +x /etc/rc.d/rc.ntpd
 # /etc/rc.d/rc.ntpd start # /etc/rc.d/rc.ntpd start
 </code> </code>
Line 154: Line 154:
  
 <note tip>Again, you might have to wait a few minutes before the first synchronization takes place.</note> <note tip>Again, you might have to wait a few minutes before the first synchronization takes place.</note>
 +  
 +===== Monitor the performance of ntpd =====
  
-===== Firewall considerations =====+You will notice that the logfile ''/var/log/ntp.log'' does not contain any information about the actual accuracy of your system clock. If it's important to you, you can log the statistics of time corrections applied by NTP daemon to the system clock. To do this, add the following lines to ''/etc/ntp.conf'':
  
-The NTP services uses UDP port 123Open this port if you want to allow remote machines to connect to your NTP server.+<code> 
 +statsdir /var/log/ntp/ 
 +statistics loopstats 
 +filegen loopstats file loops type day link enable 
 +</code> 
 + 
 +You have to create the statsdir manually. Once the configuration changes are in effect, ''ntpd'' will create files named ''loops.YYYYMMDD'' in that directory. Below is an example line from one of these files: 
 +<code> 
 +56690 3950.569 0.001199636 2.297 0.001830770 0.571576 10 
 +</code> 
 + 
 +The first and second number are the UTC time (expressed as [[http://en.wikipedia.org/wiki/Julian_day|Modified Julian Date]] and seconds elapsed since midnight). The third and fourth number are the offsets of time (in seconds) and of frequency (in parts per million). The fifth and sixth number are their respective uncertainties. 
 + 
 +To monitor the performance of ''ntpd'', you can examine the plot of clock offset or frequency offset vs. time: 
 + 
 +<code> 
 +$ awk '{printf("%f %f %f\n", $1+$2/86400, $3, $5)}' /var/log/ntp/loops.* > time 
 +$ awk '{printf("%f %f %f\n", $1+$2/86400, $4, $6)}' /var/log/ntp/loops.* > freq 
 +$ gnuplot 
 +gnuplot> set xzeroaxis 
 +gnuplot> plot 'time' with yerror 
 +gnuplot> plot 'freq' with yerror 
 +</code> 
 + 
 +Given enough data, visual examination of the plots will allow you to see peculiarities in ''ntpd'' performance, should they arise. For example, in the case illustrated by [[http://www.astro.uni.wroc.pl/ludzie/drobek/ntp_time+freq.png|this figure]], the rapid decrease of the frequency offset was caused by replacing the power supply unit of the machine.
  
 ====== Sources ====== ====== Sources ======
 +
   * Originally written by [[wiki:user:kikinovak|Niki Kovacs]]   * Originally written by [[wiki:user:kikinovak|Niki Kovacs]]
 +  * Performance monitoring section contributed by Dominik Drobek
  
 <!-- Please do not modify anything below, except adding new tags.--> <!-- Please do not modify anything below, except adding new tags.-->
 <!-- You must remove the tag-word "template" below before saving your new page --> <!-- You must remove the tag-word "template" below before saving your new page -->
-{{tag>howtos ntp time clock synchronization author_kikinovak}}+{{tag>howtos time clock synchronization author_kikinovak}}
 howtos:network_services:ntp ()