2

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?

Will
  • 1,147
  • 10
  • 26
warvariuc
  • 358
  • 1
  • 5
  • 14
  • 4
    Why not run the NTP daemon? (Yes, it's "ok" to run NTP hourly.) – Aaron Copley Dec 29 '15 at 15:19
  • @AaronCopley `ntp` package is the NTP daemon in Ubuntu, afaik – warvariuc Dec 29 '15 at 15:31
  • 1
    Ah, I see. `/etc/cron.daily/ntp` doesn't do what I thought it does. It doesn't force time synchronization, it just gathers some stats. – warvariuc Dec 29 '15 at 15:34
  • If you run `ntpq -p` you will probably find your clocks are already synched by ntpd; the daemon runs automatically when the package is installed. – Michael - sqlbot Dec 29 '15 at 15:57
  • Got it. I am more familiar with the Red Hat side of things where there is a daemon package and an NTP client package each available. Still, you shouldn't have drift if the daemon is running and configured. – Aaron Copley Dec 29 '15 at 16:34

3 Answers3

7

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 (the ntp package) with ntpdate. 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:

ntpq -p

It's output is explained here.

The cronjob /etc/cron.daily/ntp is for the sole purpose of processing daily stats from ntpd's statsdir. 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 in cron 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 running ntpd, 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 run ntpdate while ntpd is running, though.

ntpdate -b <timeserver> is actually run by many Linux distributions at boot time, before ntpd starts.

Will
  • 1,147
  • 10
  • 26
1
  1. Ensure that you have installed the ntp package (ntp daemon and utilities).

  2. Ensure that you have configured the ntp daemon. (RHEL /etc/ntp.conf)

  3. 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:

 # yum install ntp
 # vim /etc/ntp.conf
 make sure you have valid, available time servers listed
 # service ntpd restart
Jeter-work
  • 845
  • 4
  • 15
-1

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.

  • `ntpdate` is only deprecated in rolling release and short cycle distributions. Most servers use long term support releases (or should, by best practice). `ntpd -gq` tells a RHEL system to allow the first adjustment to be big, and to set the time and quit. Far better to install and correctly configure the NTP client. – Jeter-work Feb 23 '17 at 19:51