NTP and Your Xen-based Linux VM

Posted on in System Administration

As every system administrator is aware, keeping precise time on your servers can be critical. For example, if you use QueueMetrics for your Asterisk-based call center and the QM and MySQL servers are running with different times, users will notice confusing behavior as calls seem to arrive in the future!

<!--more-->

Virtual machines rely on a psuedo hardware clock that is actually based on the time of the host (dom0) server. Therefore, all virtual machines on a single host should have the same time without the need to another application to synchronize time. If multiple host servers are involved, then time can be synchronized between the hosts to ensure that the guest virtual machines have the same time. Unfortunately, there are cases where the clock provided by the host machine is inaccurate due to extenuating circumstances such as processor load. In those cases, you may have to use another method to keep proper time on your virtual machines.

The usual way to keep time synchronized among a group of servers is to use ntpd to synchronize all servers to the same time source. In a virtualized environment, running ntpd when your system expects the clock to behave normally can result in strange time behavior. Therefore, to get ntpd to operate properly, you need to instruct your Linux server to ignore the hardware clock. For a Xen-based Linux virtual machine, you must instruct the operating system to ignore the hardware clock via one of the following options:

  • Make the change in /etc/sysctl.conf

    Add the following line to /etc/sysctl.conf:

    xen.independent_wallclock = 1
    

    After saving the file, force the system to re-read the configuration file by issuing the sysctl -p command.

  • Make the change in /proc/sys/xen
    /proc/sys/xen/independent_wallclock is the /proc file that controls this behavior. echo 1 > /proc/sys/xen/independent_wallclock will update the file and change the system's behavior.

After making this change, you can continue to configure ntpd as you always would.

My Bookshelf

Reading Now

Other Stuff