All About LAMP Create web applications with Linux, Apache, MySQL, PHP and other open source technologies

How to avoid Time Reset in a Cloud Computing environment such as Xen VPS (Virtual Private Server)

10.09.2009 · Posted in Cloud Computing
This article was written by Daniel Lam. About the author: Daniel Lam is an IT consultant residing in Sydney, Australia. He is enthusiastic about internet and open-source technologies and runs a few collaboration sites. If you are interested in contributing in this site, check this out.

Overview

Your server is a virtual private server running Fedora (or other linux distro) on a cloud computing service such as RackSpace Cloud Server. For some reason, whenever you change the system time, it gets reset back after a system restart. Why did that happen? Could it be fixed?

Context

Solution described in this article applies to Fedora Core 11 hosted in a Xen VPS environment. Other Fedora verions or linux distro in other virtualisation environment may have similar setup. Xen configuration is outside the scope of this article.

Solution

As a virtual server hosted using Xen virtualisation technology, such as those offered by RackSpace Cloud Server offer, system time will get reset by Xen to match the physical machine’s clock whenever the virtual server is restarted.

This time-reset behaviour can be modified if you can change the Xen configuration. However as a user of the cloud computing service, you most likely do not have such access.

You can however do the following to set your system to the time you want.

1. Change time zone

Changing the time zone of your system will set your system time to the correct time of that time zone, given that your virtualisation provider gives your server a correct UTC time.

To change the time zone in Fedora Core 11,

  • Change the ZONE parameter value in /etc/sysconfig/clock according to your desired time zone, e.g. ZONE=”Australia/Sydney”. The list of possible values for ZONE can be found in /usr/share/zoneinfo/. The UTC parameter in /etc/sysconfig/clock can be omitted.
  • Copy the correct time zone file to /etc/localtime. For example, if you want to set time zone to Sydney in Australia, do cp /usr/share/zoneinfo/Australia/Sydney /etc/localtime

2. Use a time-synchronising tool

After you have set your system to the correct time zone, the time may still be inaccurate because it simply relies on the time given by the virtualisation provider.

To compensate any inaccuracy from virtualisation provider, use time-synchronising tool like ntpdate to sychronise your server with publicly-available time servers.

  1. Install ntpdate if it is not already installed in your system. Run yum install ntpdate to install ntpdate.
  2. Turn on ntpdate service using chkconfig --level 3 ntpdate on so that time will be sync’d on boot time. Note that your “level” may be different, check /etc/inittab to be sure.
  3. Use cron job to run ntpdate hourly or daily to keep an accurate time in the long term.

Note that in a virtualisation environment, ntpd will not be able to set the time of guest system properly because of the CPU time-sharing nature of virtualisation technology. Refer to ntp docs for more information: http://support.ntp.org/bin/view/Support/VMWareNTP

3. Use date command to change system date and do not restart

If setting your system to match specific time zones accurately still does not fulfill your requirement (e.g. if you want your time to be 15 minutes behind, for testing purpose), you can still change your system time using date command. However keep in mind that this will be reset back to the correct time of your time zone after a restart.

Reference

Leave a Reply