新浪博客

ntp设置、启动、问题

2011-11-09 15:19阅读:

基本概念:


ntp设置、启动、问题
0层的服务器采用的是原子钟、GPS钟等物理设备,stratum 1stratum 0 是直接相连的,往后的stratum与上一层stratum通过网络相连,同一层的server也可以交互。
ntp设置、启动、问题

[from Wikipedia]

C/S合一

ntpd对下层client来说是service server,对于上层server来说它是client,也就是说新版的NTP服务程序已经不对服务端和客户端进行区分了,统一叫做ntpdntpd根据配置文件的参数决定是要为其他服务器提供时钟服务或者是从其他服务器同步时钟。所有的配置都在/etc/ntp.conf文件中。

NTP客户端同步间隔

NTP服务会间隔多长时间想时钟服务器请求一次时钟同步呢?默认最小时间间隔为64s,默认最大时间间隔是1024s17分钟左右)。64s是比较合理的,默认间隔也是可调的(Note that most device drivers will not operate properly if the poll interval is less than 64 s and that the broadcast server and manycast client associations will also use the default, unless overridden.)。

容忍误差范围

NTP服务并不是在任何情况下都会进行同步的。当时钟服务器时间和本地时间相差大于1000s时,NTP服务就会认为是人为调整了时钟或出现了硬件故障,例如CMOS电池损坏等。此时,NTP服务就会退出,需要人工(ntpdate …)进行时钟同步。
采用-g选项可以让ntpd忽略1000s或更大误差,设置时钟到server system time, 但是ntpd还是会因此退出。

层次(strata

stratum根据上层server的层次而设定(+1)。
对于提供network time service provider的主机来说,stratum的设定要尽可能准确。
而作为局域网的time service provider,通常将stratum设置为10 Stratum 10 is conventional for unsynchronized local clocks; it is high enough that nobody is likely to mistake it for a desirable clock to synchronize with.),如下:
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
#stratum设置为其它值也是可以的,其范围为0~15

设置与启动

文件路径:/etc/ntp.conf
# 1. 先处理权限方面的问题,包括放行上层服务器以及开放局域网用户来源:
restrict default kod nomodify notrap nopeer noquery <==拒绝 IPv4 的用户
restrict -6 default kod nomodify notrap nopeer noquery <==拒绝 IPv6 的用户
restrict 220.130.158.71 <==放行 tock.stdtime.gov.tw 进入本 NTP 的服务器
restrict 59.124.196.83 <==放行 tick.stdtime.gov.tw 进入本 NTP 的服务器
restrict 59.124.196.84 <==放行 time.stdtime.gov.tw 进入本 NTP 的服务器
restrict 127.0.0.1 <==底下两个是默认值,放行本机来源
restrict -6 ::1
restrict 192.168.100.0 mask 255.255.255.0 nomodify <==放行局域网用户来源,或者列出单独IP

# 2. 设定主机来源,请先将原本的 [0|1|2].centos.pool.ntp.org 的设定批注掉:
server 220.130.158.71 prefer <==以这部主机为最优先的server
server 59.124.196.83
server 59.124.196.84

# 3.默认的一个内部时钟数据,用在没有外部 NTP 服务器时,使用它为局域网用户提供服务:
# server 127.127.1.0 # local clock
# fudge 127.127.1.0 stratum 10

# 4.预设时间差异分析档案与暂不用到的 keys 等,不需要更动它:
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
文件路径:/etc/sysconfig/ntpd
OPTIONS='-u ntp:ntp -p /var/run/ntpd.pid'
SYNC_HWCLOCK=yes
# 将他改成 yes 吧!这样 BIOS 的时间也会跟着改变的!
启动
/etc/init.d/ntpd start /etc/init.d/ntpd restart
查看端口使用情况
netstat -tlunp | grep ntp
查看本机作为client更新time的过程
ntptrace
查看ntpd的运行信息
ntpstat
查看所有层次time service provider的详细信息
ntpq –pn
Client单独用ntpdate更新时间
ntpdate ntp_server_ip
其后可能需要hwclock -w clock -w)写入BIOS timer

可能的问题

Ø no server suitable for synchronization found
原因:ntpd启动过程需要5分钟左右!(或者ntpd根本没有启动)
ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
那么如何知道何时ntp server完成了和自身同步的过程呢?

我的更多文章

下载客户端阅读体验更佳

APP专享