Linux OS Service 'ntpd' (文档 ID 551704.1)
APPLIES TO:
Linux OS - Version Oracle Linux 4.4 to Oracle Linux 6.5 with Unbreakable Enterprise Kernel [3.8.13] [Release OL4U4 to OL6U5]
Linux x86
Linux x86-64
Linux Kernel - Version: 4.4 to 6.5
***Checked for relevance on 11-July-2014***
PURPOSE
This is a reference document to describe Linux operating system service 'ntpd' with respect to its use, scope, nature and applicability.
SCOPE
This document is useful for Linux operating system administrators for the specific Linux OS service 'ntpd'
DETAILS
Service Name
ntpd
Description
This service executes the Network Time Protocol (NTP) daemon ntpd. The purpose is to synchronize the time of the local computer to a NTP server or other reference time source such as a radio or satellite receiver or modem. The NTP time protocol provides accuracies typically within a millisecond on LANs and up to a few tens of milliseconds on WANs relative to Coordinated Universal Time (UTC) via a Global Positioning Service (GPS) receiver. The Linux NTP package is a complete implementation of the Network Time Protocol (NTP) version 4, but also retains compatibility with prior versions 1, 2, and 3.
The NTP system uses two main roles for participating computers: server or client. Time servers supply time to one or more NTP clients. NTP clients use the reference time from one or more NTP servers to determine the local time. This scheme allows an NTP client to reject bogus time from an NTP server; to compensate for network-induced delays; and to determine which NTP server has the best time. An NTP client may also server as an NTP server for other machines.
The ntpd program operates by exchanging messages with one or more configured servers at designated poll intervals. The program requires several exchanges from the majority of chosen servers so the signal processing and mitigation algorithms can accumulate and groom the data before setting the local clock.
Usually each country provides an official time reference. In the USA, the National Institute of Standards (NIST) provides this service. The national time reference is called a tier 1 server. NTP servers who use this source for their reference time are called tier 2servers. NTP servers who connect to tier 2 servers are known as tier 3 servers, and so on. NTP clients who use their own atomic clocks are also called tier 1 servers. NTP clients must connect to an NTP server to synchronize their clocks. Some ISPs provide NTP server access to their clients, but publicly-accessible servers at pool.ntp.org are also available. Higher-tier NTP servers are usually no less accurate than their lower-tier counterparts, which can get overburdened. Many companies implement their own NTP server by connecting to external NTP servers, reducing the load on these external servers.
Most machines have a real-time chip (RTC) to maintain the time during periods when the power is off. When the machine is booted, the calendar chip is used to initialize the operating system time; the ntpdate(1) program can also be used to set the local time from a reference NTP server.. After the machine has synchronized to an NTP server, the operating system corrects its notion of time gracefully. Under ordinary condition, ntpd adjusts the O/S clock in small steps so that the timescale is effectively monotonic, without discontinuities. Once the clock has been set, its accuracy is continuously checked and adjustments for any drift are stored into a local file and are thus saved across reboots. Usually at system shutdown the O/S updates this RTC clock chip with the current time, thus closing the cycle.
The Linux NTP service is quite configurable. Comprehensive on-line documentation is supplied in both ntpd(1) manual pages and/usr/share/doc/ntp-<version> documentation.
Note: this service is needed even for NTP clients. The server/client role is distinguished by its configuration.
The RPM package containing this service:
ntp
Nature
Daemon service
Service Control
This service is handled by init.d script /etc/init.d/ntp. Its usage is as follows:
# /sbin/service ntpd
usage: /etc/init.d/ntpd {start|stop|restart|condrestart|status}
#
Start the service as follows:
# /sbin/service ntpd start
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
#
Stop the service as follows:
# /sbin/service ntpd stop
Shutting down ntpd: [ OK ]
#
Check if the serivce is started or stopped:
# /sbin/service ntpd status
ntpd is stopped
#
If the service is started, then restart it; otherwise do nothing. Typically used only by the RPM install scripts.
# /sbin/service ntpd condrestart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
#
Determine which system run levels the service is active:
# /sbin/chkconfig --list ntpd
ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
#
Configuration
Ordinarily, ntpd reads the ntp.conf configuration file at startup time in order to determine the synchronization sources and operating modes. It is also possible to specify a working, although limited, configuration entirely on the command line, obviating the need for a configuration file.
Usually, the configuration file is installed in the /etc directory, but could be installed elsewhere (see the -c conffile command line option). The file format is similar to other Unix configuration files - comments begin with a # character and extend to the end of the line; blank lines are ignored.
The default ntp.conf file like this:
restrict default nomodify notrap noquery
restrict 127.0.0.1
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
In addition, ntpd daemon can be run with various options. In order to add command line options to the ntpd service (/etc/init.d/ntpd), one has to edit /etc/sysconfig/ntpd file and add the desired option to the OPTIONS variable, and restart the service via 'service ntpd restart'.
For example, the -x argument is mandatory for RAC configurations and the /etc/sysconfig/ntpd file looks as:
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"
# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=no
# Additional options for ntpdate
NTPDATE_OPTIONS=""
You can check the settings from that /etc/sysconfig/ntpd file but it will not be reliable if the ntpd process is started manually for some reason. To check the arguments you can use command line:
# ps -o args -p `cat /var/run/ntpd.pid`
COMMAND
ntpd -x -u ntp:ntp -p /var/run/ntpd.pid
#
Files:
/etc/ntp/ntp.conf - the default name of the configuration file
/var/lib/ntp/drift - the default name of the drift file
/etc/ntp/keys - the default name of the key file
/etc/sysconfig/ntpd - setting command line options for ntpd daemon
Recommendation
There should be at least three ntp servers configured, preferably four or five. See the NTP "faq" for additional information. The main reason is that in case of failure of one or more servers there can still greater than 50% consensus of the correct time.
See Also
See the man page ntpd(1)
See the man page ntpdate(1)
http://www.ntp.org/
Notes
None