Linux OS Service 'ntpd' [ID 551704.1]

Linux OS Service 'ntpd' [ID 551704.1]

 修改时间 25-JAN-2011     类型 REFERENCE     状态 PUBLISHED 

In this Document
  Purpose
  Scope
  Linux OS Service 'ntpd'
     Service Name
     Description
     Nature
     Service Control
     Configuration
     Oracle Enterprise Linux Version(s)
     See Also
     Notes
  References


Applies to:

Linux OS - Version: 4.4 to 5.1 - Release: OEL4U4 to OEL5U1
Linux x86
Linux x86-64
Linux Kernel - Version: 4.4 to 5.1
***Checked for relevance on 25-Jan-2011***

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'

Linux OS Service 'ntpd'

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 2 servers.  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- 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

Oracle Enterprise Linux Version(s)

  • OEL 4 (Base to Update 6)
  • OEL 5 (Base to Update 1)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/611609/viewspace-691912/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/611609/viewspace-691912/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值