Eric R. Thern ————–=[ thern dot org ]=————–

3Oct/070

Keeping servers and workstations on time using cron and ntpdate

I'm a fan of having all my computers report the same time, especially when I have to cross reference logs on different servers and require the times to all match up.

I've used rdate to update time in the past, but lately have been using ntpdate, which seems to be quite a bit better.

One of the easiest ways to keep a system up to date is to put ntpdate in a cron job, via root's crontab:

Add the following to crontab via `crontab -e`

1 2,10 * * * /usr/sbin/ntpdate {0,1,2,3}.pool.ntp.org >/dev/null 2>&1

Here I have the cron running at 2:01 and 10:01, quite randomly picked times to run it. I'd suggest once a day or twice a day, please change the time to whatever suits you best.

I've got ntpdate running off of any one of the pool.ntp.org servers. Using the {0,1,2,3}.pool.ntp.org here allows for this to expand using any one of those servers, 0.pool.ntp.org etc. By the very nature of the pool.ntp.org addresses, they already represent a large pool of servers, so you can just choose one that suits you best. The pool servers also include continent and country specific pools of servers to use.

If you require ntpdate to update a bit quicker, you can always tune the -t (timeout) and -p (samples) settings accordingly. A setting of -p 1 will just have ntpdate get a single sample from the server to use as the time. These shouldn't really be used typically, but are useful if you run into problems.

I had a system with a broken i8254 timer chip which caused the system to not keep correct time, and also have a major CPU slowdown. It was an odd problem to have, but a script in crontab to run ntpdate on different servers using only a single sample of -p 1 allowed the system to have the proper time (a very temporary band-aid solution).

-p samples

Specify the number of samples to be acquired from each server as
the integer samples, with values from 1 to 8 inclusive. The
default is 4.

-t timeout

Specify the maximum time waiting for a server response as the
value timeout, in seconds and fraction. The value is rounded to
a multiple of 0.2 seconds. The default is 1 second, a value
suitable for polling across a LAN.

For futher reading:
http://www.ntp.org/
NTP Pool timeserver lists:
http://support.ntp.org/bin/view/Servers/NTPPoolServers

VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)
Tagged as: , , No Comments