Tuesday, July 21, 2015

XenServer and NTP

After spending hours and hours trying to set up the timezone and hwclock via ntp on a Debian 7.8 Wheezy VM on XenServer 6.5 I gave up and ended up setting the timezone to UTC because the clock was only displayed correctly if the tz was UTC (damn bad).

I came up this morning with the idea of checking the time of the XenServer dom0 to see if at least the physical box had its time ok. Big was my surprise when I realized the dom0's time was also skewed just like in the VMs as stated on [1]

I restarted the NTP daemon because I configured it to point to the ntp pool when setting up the box. Big was my surprise when I realized the NTP daemon was starting, but the synchronization was failed:

[root@xenserver ~]# service ntpd restart
Shutting down ntpd:                   [  OK  ]
ntpd: Synchronizing with time server: [FAILED]
Starting ntpd:                        [  OK  ]


I restarted the NTP daemon on the old fashioned way, since the XenServer 6.5 is based on CentOS, that shouldn't be an issue.

[root@xenserver ~]# /bin/bash -vx /etc/init.d/ntpd restart

After some output, I realized the script runs ntpdate to get the synchronization done like this:

ntpd: Synchronizing with time server: + /sbin/ntpdate -U ntp -s -b 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org

After running the command with debug and verbose flags I realized that there was something wrong with using an privileged port and dropping privileges to the ntp user, so turning on the -u flag on /etc/sysconfig/ntpd was the right way to do it. [2] [3]

[root@xenserver ~]# cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -x"

# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=no

# Additional options for ntpdate
NTPDATE_OPTIONS="-u"


After the change everything went smoothly:

[root@xenserver ~]# service ntpd restart
Shutting down ntpd:                   [  OK  ]
ntpd: Synchronizing with time server: [  OK  ]
Starting ntpd:                        [  OK  ]


--
= ^ . ^ =

[1] http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/guest.html#time_linux
[2] https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sect-Date_and_Time_Configuration-Command_Line_Configuration-Network_Time_Protocol.html
[3] http://linux.die.net/man/8/ntpdate

No comments:

Post a Comment