[Linux] Time Warp?

Danny Rathjens linux@flux.org
Fri, 15 Feb 2002 13:22:07 -0500


You guys are much more organized than we are.  My documentation on how
to setup ntp is in the form of a shell script, 8^)

Any of you are free to add ntp.vcn.net to your server list.
The more the merrier, as far as time synchronization goes.

## To install the ntpd client using ntp.vcn.net (nova) as the server
rpm -ivh ntp-4.1.0-4.i386.rpm
chkconfig ntpd on
mv /etc/ntp.conf /etc/ntp.conf.orig
echo server ntp.vcn.net > /etc/ntp.conf
echo driftfile /etc/ntp/drift >> /etc/ntp.conf
service ntpd start
tail -20 /var/log/messages

Adam Glass wrote:
>>"Gomez, Rudy (MDPD)" wrote:
>>
>>OUT OF SYNC computer clocks.  What is the REAL time?
>>"Does anybody really know what time it is? Does anybody really care?"
>>
> 
> Yes, the government knows, and they share the information.  There is a
> series of atomic clocks (I think all sync'd to one master but I don't
> remember) hosted at government and university sites.
> 
> You can install a daemon called ntpd or xntpd (ntp means network time 
> protocol) which checks the correct time at one of these sites via the 
> internet and then sets the Linux date to that.  There is also another
> command that syncs your computer's hardware clock.
> 
> FYI, xntpd is running on the FLUX machine.
> 
> Most distros have ntpd or xntpd packages on the CD set or FTP site but it 
> may not be installed by default.
> 
> Below is a copy of an internal Metro Link document on the topic, edited
> to remove references to internal addresses.  It was written by Jason
> Baietto, who some may recall spoke at a FLUX meeting once about Netscape's
> remote capabilities.  It may be a bit out of date (based on Red Hat 6.2
> with a note added later about Mandrake 8.0), but should still be accurate:
> 
> ===========================================================================
> 
> 1. Background
> 
> The majority of this document applies to the Red Hat 6.2 distribution. It is 
> hoped that much of this information will apply to other distributions, but 
> since I mainly use Red Hat I don't know if it will. 
> 
> The time server we use is ntp1.cs.wisc.edu
> 
> Note that NTP and XNTP are really the same thing. The "X" stood for 
> "experimental" and all versions of NTP prior to version 4.0 put the X in the 
> name.  The newer version is simply called NTP. My experience has been that 
> they both work identically, so there is no big motivation to grab the latest 
> one if you have an older one (unless you just like to run the latest stuff). 
> 
> 2. Installation
> 
> First, make sure that the NTP software is installed on your system. Red Hat
> 6.2 
> installs the xntp3-5.93-14 RPM by default. You can find recent RPMs for most 
> distributions, or you can go and get the source and build it from here: 
> 
>    http://www.eecis.udel.edu/~ntp
> 
> It is much better to get the RPMs for you distribution because they will 
> generally do all the right magic with the init files in order to ensure that 
> the NTP daemon starts up at various run levels. If you build from source, be 
> prepared to spend some time customizing scripts for inclusion in the rc 
> directories. 
> 
> 3. Init Setup
> 
> Once you have the NTP binaries installed, you need to go and make sure that 
> xntpd will start at the proper run levels. On Red Hat, issue the following
> commands as root: 
> 
>    cd /etc/rc.d/init.d
>    /sbin/chkconfig --list xntpd
> 
> (Note: replace xntpd with ntpd on systems with the newer software installed. 
>>From now on I will refer to this file as xntpd to keep things simple). 
> 
> After a fresh install, you should see the following output: 
> 
>    service xntpd does not support chkconfig
> 
> Red hat decided not to enable NTP by default in version 6.2. If you examine
> the 
> /etc/rc.d/init.d/xntpd script you should see the following following line: 
> 
>    # chkconfig: -- 55 10
> 
> The double-dash is where the list of run levels to start the service at is 
> located. In order to get things to work properly, you need to change this line 
> inside the xntpd script to read as follows: 
> 
>    # chkconfig: 345 55 10
> 
> This will make the xntpd daemon start at run levels 3, 4 and 5 and stop at all 
> other levels. 
> 
> Once you've done this, execute the following sequence of commands: 
> 
>    chkconfig --del xntpd
>    chkconfig --add xntpd
>    chkconfig --list xntpd
> 
> You should see the following output after the last command: 
> 
>    xntpd         0:off   1:off   2:off   3:on    4:on    5:on    6:off
> 
> This correctly indicates that xntpd will start up at run levels 3, 4 and 5. 
> 
> 4. Step Tickers
> 
> There is an NTP concept called "step tickers" which, IMHO, is very poorly
> named. 
> Basically, a step ticker is a machine that xntpd should consult at startup
> time in order to synchronize the clock. 
> 
> The list of step tickers is kept in the /etc/ntp/step-tickers file. Note that 
> this file does not exist by default and you need to create it. If you don't
> create the file and put at least one machine name in it, xntpd will simply 
> keep the time that was restored from the hardware clock, which is almost
> certainly not what you want (unless the machine is temporarily not going to 
> be on a network or something). 
> 
> Create the /etc/ntp/step-tickers file and simply put ntp1.cs.wisc.edu
> on the first line all by itself. That's all there is to do. 
> 
> 5. Config File
> 
> You also need to define the machine that xntpd will periodically synchronize 
> with. To do that, insert the following line at the top of your
> /etc/ntp.conf file: 
> 
>    server ntp1.cs.wisc.edu
> 
> That's all there is to do. Leave all other lines in the file alone.
> 
> Note: For those running Mandrake 8.0, comment out the last line of ntp.conf, 
> which should read (after commenting out):
> 
>    #restrict default ignore 
> 
> 6. Start xntpd
> 
> Once you've configured the step-tickers and the ntp.conf files, go ahead and 
> start the daemon. Issue the following commands as root: 
> 
>    cd /etc/rc.d/init.d
>    ./xntpd start
> 
> You should see the familiar green [ OK ] message. If you don't, go and review 
> all above steps and make sure that you haven't made a mistake. 
> 
> One common mistake is that xntpd may already be running. If this is the case, 
> it is likely that it was either started manually, or in rc.local because
> somebody didn't understand the correct way to configure it. You may need to 
> track down where it is getting started and remove any old incorrect setup
> before continuing. 
> 
> 7. System Time vs. Hardware Clock
> 
> Note that all the NTP stuff only affects the system time, which is kept in 
> software and maintained by the operating system. Once the time has been
> synchronized, you may want to write it to the hardware clock. Generally this 
> doesn't matter, however if you have a reason to keep the hardware clock in
> sync
> (for example, laptops that often run without a network connection) then add
> the 
> following line to your /etc/rc.d/rc.local script: 
> 
>    /sbin/hwclock --systohc
> 
> This forces the current system clock (software) to be written to the hardware 
> clock. If the machine is connected to the network and NTP has been
> configured correctly, the system time should be accurate at this point. If no 
> network connection is available, then this command is simply a noop because it
> just writes the time that was originally gotten from the hardware clock back
> to 
> the hardware clock. 
> 
> 8. Verification
> 
> Okay, you've done all this stuff and now you want to know whether it's working 
> or not. To tell if you've reached NTP synchronization, run the ntpq command. 
> The ntpq command gives you a command line prompt where you can type in all 
> sorts of commands, but the main one of interest is the peers command. Here's 
> sample output: 
> 
> ntpq> peers
> remote             refid      st t when poll reach   delay   offset  jitter
> ==============================================================================
> LOCAL(0)          LOCAL(0)        10 l   26   64  377 0.000  0.000   0.000
> *ntp1.cs.wisc.edu caesar.cs.wisc.  3 u  318 1024  377 62.565 -2.279  7.333
> 
> 
> The asterisk is the important thing to look for because it indicates which 
> system's clock you are synchronized to. If the asterisk is not present, it 
> generally means that you just started xntpd and the system hasn't had time 
> to reach synchronization yet. Wait half an hour an try the commands again. 
> 
> If the asterisk is in front of the LOCAL host, then you have a problem. This 
> means that you have not been able to connect to the remote time server and 
> that xntpd has chosen to synchronize with the local clock (bad). This can 
> happen when the network is down, but should never happen if the network is 
> up. If it happens when the network is up, try restarting xntpd. If it 
> continues, consult the NTP website for help (http://www.eecis.udel.edu/~ntp). 
> 
> If the asterisk is in front of the correct site as in the example above then 
> you have reached NTP synchronization. Relax and enjoy feel smug knowing the 
> fact that your machine's clock is now automatically being kept extremely 
> accurate. Don't forget to check after your next reboot to make sure that 
> everything starts and synchronizes as expected. 
> 
> =========================================================================
> 
> 


-- 
  _.,-*~`^'~*-,._ Danny Rathjens _.,-*~`^'~*-,._
"Round numbers are always false." -- Samual Johnson