System Clock Synchronization on Virtual Machines

Due to various technical details, ntp is not an suitable option on all virtual machines.
 
The current best practice is generally to perform a periodical stepping of the system clock to keep it relatively close to an acceptable time source (such as the system clock on the host machine).
 
This may be implemented via a cron job. Create a script in '/etc/cron.hourly/syncclock':

#!/bin/bash
logger -p daemon.notice -t syncclock "$0 started"
#
compareTimes () {
   RT=`rdate -np 10.10.2.1`
   LT=`date`
   logger -p daemon.notice -t syncclock "Local  time reported by  date: ${LT}"
   logger -p daemon.notice -t syncclock "Remote time reported by rdate: ${RT}"
}
compareTimes
/usr/sbin/ntpdate -b -p 8 -s -v 10.10.2.1 194.239.168.251 194.239.168.193
compareTimes
logger -p daemon.notice -t syncclock "$0 done"
#
EOF

 

Set apropriate permissions and ownership on the script:

chmod u+x /etc/cron.hourly/syncclock
chown root.root /etc/cron.hourly/syncclock

Make sure that rdate and ntpdate are available by executing:

sudo apt-get install rdate ntp

Please be aware that cron job filenames in `/etc/cron.hourly` and friends have obscure restrictions, please see `run-parts(8)`.

The configuration was sucessfull if `/var/log/syslog` contains something similar to this:

Please be aware that cron job filenames in `/etc/cron.hourly` and friends have obscure restrictions, please see `run-parts(8)`.

The configuration was sucessfull if `/var/log/syslog` contains something similar to this:

Dec  7 00:04:23 www01 syncclock: /etc/cron.hourly/syncclock started
Dec  7 00:04:23 www01 syncclock: Local  time reported by  date: Wed Dec  7 00:04:23 CET 2011
Dec  7 00:04:23 www01 syncclock: Remote time reported by rdate: Wed Dec  7 00:04:23 CET 2011
Dec  7 00:04:23 www01 ntpdate[24637]: ntpdate 4.2.6p2 @ 1.2194 Fri Sep  2 18:37:16 UTC 2011 (1)
Dec  7 00:04:25 www01 ntpdate[24637]: the NTP socket is in use, exiting
Dec  7 00:04:25 www01 syncclock: Local  time reported by  date: Wed Dec  7 00:04:25 CET 2011
Dec  7 00:04:25 www01 syncclock: Remote time reported by rdate: Wed Dec  7 00:04:25 CET 2011
Dec  7 00:04:25 www01 syncclock: /etc/cron.hourly/syncclock done