Thursday, March 15, 2007

Date and time on virtual machine....

I had this problem with date/time synchronizing on a virtual machine with its host machine. Result of this was that the clock on my virtual machines ran slower than the real clock. So my date and time was always behind. Because I did not want to restart the timeserver (ntp server) every time from the command line (when restarting the ntp server, the date/time was correct for a few minutes....), a colleague of mine suggested to put the restart in a cronjob. Great plan and also tested on a few other virtual machines...
I placed the following lines in a fiel called time.cron

[root@vamisux32 ~]# crontab -l
# ntp update statement - workaround
0-59 * * * * /usr/sbin/ntpdate amisnt10 >>/var/log/ntpdate 2>&1

But on my Oracle Linux virtual machines, the cron job did not run. So, the virtual clock was still running slower than the real clock.

In the logfile of the crontab, the following error was shown

"ntpdate[23109]: the NTP socket is in use, exiting"

So it seems the cronjob cannot connect to the external time server, because the NTP socket is already in use.
I found out that Oracle Linux starts a NTPD process when booted. This NTPD process is blocking my NTP socket....So, I stopped the NTPD process and made sure it would not start up again when booting the virtual machine. Checked the date and time and everything seems oke now. Even the crontab logfile is without errors...

"ntpdate[18258]: step time server 10.252.252.10 offset...."

So, don't run ntpd and ntpdate next to each other...

1 comment:

Anonymous said...

Bas, the solution described here is not the answer for VMware Virtual Machines.

The way to do it, is described here: http://www.vmware.com/pdf/vmware_timekeeping.pdf