Tobias Kreidl
|
Genius
|
9,492
| CTP Member | 19,493 posts
Genius
|
9,492
| CTP Member | 19,493 posts
Greetings:
There are many threads on this forum and information elsewhere dealing with NTP (Network Time Protocol) issues, so I thought I'd share a few things that I've learned over the years and summarize a number of these tips and experiences. These practices pertain, of course, to Linux OS installations, in general.
Part 1
NTP synchronization is important for a number of reasons. For one, XenServer depends internally on having members of pools close in time as they are intercommunicating important information over the primary management network and Citrix mandates that for proper functionality that this be done.
There are two general ways of setting up NTP. One is to not run the NTP daemon (ntpd) and simply run a periodic "ntpdate ntp-server-host" to update the clock. This is not the standard way of doing things, since it doesn't take into account issues such as latency or internal clock drifts. It is, however, a good one-time means of synchronizing the server's clock if it's a new installation or is way off for some other reason. Adding a host to a pool that has a large time offset can in of itself lead to issues, so it's a good idea to make sure the time is set close. With the ability to storage Xenmotion running VMs even to different pools, keeping all XenServers (as well as other servers that support Citrix and other products and services) all in proper time sync is as important as ever. To check how far a host is off from the local NTP standard setting, run "ntpstat -s" from the CLI.
The preferred way of implementing NTP is to run the NTP daemon (ntpd), which gets its settings from the /etc/ntp.conf file. This is pre-configured with some basic settings as delivered with a XenServer installation.
NTP depends on external machines to be used for synchronization -- using three is recommended, as (1) a single host may be unavailable at one time or another, (2) using more than one allows NTP to find the "best" source, and (3) it delivers peace of mind to see when all NTP servers are close to each other, providing confidence that all is working correctly,
As to the selection of NTP servers, one can of course choose any ones, as long as they are accessible (they use tcp/udp port 123 (or if SSL is used, 563) for communication. The typical setup involves establishing a secondary NTP server group within one's organization, that in turn receives its input from "official" external NTP sources. A comprehensive list of suggested servers can be found, for example, at http://pool.ntp.org/ or specifically for the US, the National Institute of Standards and Technology provides a suggested list by region at http://tf.nist.gov/tf-cgi/servers.cgi. The primary reason to synchronize to a set of local NTP servers within one's organization is that in the event of Internet connectivity issues, the local hosts can continue to internally synchronize to the same common source, as long as Intranet functionality is still present.
This is all well and good, but what happens if there is a partial outage within one's organization that prevents access to the local NTP servers? If short, the systems can of course continue to still keep reasonable time, but computer clocks are notoriously not that accurate (you can buy a $10 watch that keeps better time!). One very simple option is to make use of the "peer" feature within ntpd. This is as simple as adding a line for each of the hosts within, say a single XenServer pool, which all share the same management interface. The purpose of the peer option is to provide a means of at least keeping the server pool internally synchronized in such a case. The ntpd is smart enough to assign peers a high stratum value (basically, a hierarchy of dependencies off the primary source machines, which are at stratum 0; the greater the stratum value, the further down the chain lies the machine). Typical machines used to connect to directly have a stratum of 2 - 4.
When access to NTP servers within one's organization fail, the peer mechanism takes over. The host itself will negotiate with the other named peers and together they will all decide on common primary and secondary sources. These are combined in a weighted scheme to come up with a single time that's used for synchronizing all members that share this same group of sources (be they real NTP server or just peers). When the NTP server once again become available, ntpd will automatically switch back and recalibrate the polling times (which initially drop to much shorter time intervals) and reset the server clocks.
As an example of a basic setup, here is a sample /etc/ntp/conf file and note the in-line comments:
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#===# this restricts who can talk to this server to obtain NTP information
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#===# self-explanatory
restrict 127.0.0.1
## restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use Xen's public servers.
#===# This is in case your organization does not have its own internal NTP servers.
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
## server 127.127.1.0 # local clock
#===# I add this to force the local machine to have a low stratum compared to external NTP servers.
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#===# This is where your machine stores its drift file, which is the estimated clock frequency error
driftfile /var/lib/ntp/drift
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
### our local specifics ###
#===# This deals with how self-modifying the local server can be to its own settings, as well
#===# as not permitting external queries.
restrict X.Y.0.0 mask 255.255.0.0 nomodify notrap
restrict 10.15.9.0 mask 255.255.255.0 nomodify notrap
#===# A list of your local (organizational) NTP servers
server ntp1.mydomain.org
server ntp2.mydomain.org
server ntp3.mydomain.org
#===# Here is the option to add local peers (within a subnet, server pool, etc.)
# peers in case the standard NTP servers cannot be reached. These are the three XenServers in the pool.
peer 10.15.9.17
peer 10.15.9.18
peer 10.15.9.19
That's basically it. Anytime a change is made, it's a good idea to restart ntpd: "service ntpd restart".
What does a typical running system deliver in terms of stability? To be continued in the next post, as space has run out...
Share this post
Link to post
Share on other sites