I have several servers in Amazon EC2. Having noticed time difference on the instances I have installed ntp
. I see /etc/cron.daily/ntp
Cron job was added.
Still I notice that, for some reason, the time drifts quite fast.
I am planning to make a symlink in /etc/cron.hourly
to /etc/cron.daily/ntp
.
Will this help?
I know you've already figured this out, but I wanted to add some information for anyone who might stumble across this. It seems that you were confusing
ntpd
(thentp
package) withntpdate
.ntpd
is a daemon that continuously keeps time in sync. It does this in a very involved, very safe, and fairly complex manner, and typically involves multiple timeservers. You can see the status of NTP's time synchronization, and the servers it is syncing with, by running:It's output is explained here.
The cronjob
/etc/cron.daily/ntp
is for the sole purpose of processing daily stats fromntpd
'sstatsdir
. As far as whether this can be run multiple times per day, I'm sure there's a way, but you probably don't need to, and it might cause problems :)What I believe you were originally thinking of was the manual NTP command
ntpdate
.ntpdate <timeserver>
simply synchronizes time with a remote timeserver a single time. And, sure, you could run this command incron
as frequently as you want. However,ntpdate
synchronization is not only less performant, but it results in considerably-less-synchronized time. It's a good way to quickly synchronize time for a server not runningntpd
, or if the clock is very badly out of sync, for an initial synchronization (ntpd
will only change the clock by so much at one time). You can't runntpdate
whilentpd
is running, though.ntpdate -b <timeserver>
is actually run by many Linux distributions at boot time, beforentpd
starts.Ensure that you have installed the ntp package (ntp daemon and utilities).
Ensure that you have configured the ntp daemon. (RHEL
/etc/ntp.conf
)Ensure that the service is working correctly. (RHEL
service ntpd status
,date
)These steps are all distribution specific, but a simple search will find instructions on how to set this up.
For RHEL:
ntpdate is depracated, and you can use ntpd -gq to update time forcefully rather than on a schedule.
This works for VMs that don't have guest os tools installed, and experience periodic clock drift, although there may be a better way.