-bash-3.00# ntpq -p
remote refid st t when poll reach delay offset disp ============================================================================== *10.0.2.71 LOCAL(0) 4 u 4 64 377 0.58 -0.584 0.09前导符:
The character in the left margin indicates the fate of this peer in the clock selection process. The codes mean:
SPACE Discarded due to high stratum and/or failed sanity checks.
x Designated falsticker by the intersection algorithm.
. Culled from the end of the candidate list.
- Discarded by the clustering algorithm.
+ Included in the final selection set.
# Selected for synchronization; but distance exceeds maximum.
* Selected for synchronization.
remote:
the hostname or IP of the remote machine. (ntp.conf文件中配置的server和peer主机)
refid:
the identification of the time source to which the remote machines is synced. (0.0.0.0 if the ref ID is unknown) (远程主机的NTP Server地址)
st:
the stratum of the remote machine. 16 is "unsynchronized". 0 is the best value, that could be (for example) a radio clock or the ntp servers private caesium clock.
NTP采用分层同步方式,一般第n+1级与第n级时钟源进行同步。NTP最多支持16层同步,即0-15层。多于16层将无法同步。注意st的值表示的是远程主机的层级。如果远程主机是当前主机的NTP Server的话,一般情况下本级主机的层级是st+1。
t:
The type of the peer (local, unicast, multicast or broadcast) when the last packet was received.
l local (such as a GPS clock)
u unicast (this is the common type) (单播,即NTP client向NTP server发送NTP请求,NTP server回复的模式) m multicast (多播,可跨子网。) b broadcast (广播,不可跨子网。NTP server定时向广播地址发送NTP包,NTP client通过广播地址获取NTP包,同步本地时钟) - netaddr (usually 0)when:
how many seconds since the last poll of the remote machine.
自上次时钟同步以来经过了多少秒。当when=poll时,进行一次时钟同步,同时when被清零,从头开始计时。通过when可以知道上一次同步时间(当前时间-when)和下一次同步时间(当前时间+poll-when)。
poll:
polling interval to the remote host, defined with the "minpoll" value in ntp.conf file
时钟同步时间间隔。ntp服务刚启动时,缺省的最小同步间隔是64(minpoll=6)秒,然后依次增加,128, 256, ……, 1024。缺省的最大值是1024(maxpoll=10)秒。这两个值分别可以通过minpoll和maxpoll参数修改。
reach:
an 8-bit left-rotating register. Any 1 bit means that a "time packet" was received.
八进制数,表示最近8次时钟同步包接收情况。1表示接收成功,0表示接收失败。每接收一个包左移一位。对于一个运行较长时间的NTP client而言,这个值应该是377->11,111,111,即最近8次包接收均成功;否则表示有丢包情况发生。NTP启动后reach值的变化如下:
1->00,000,001
3->00,000,011
7->00,000,111
17->00,001,111
37->00,011,111
77->00,111,111
177->01,111,111
377->11,111,111
……
377->11,111,111
如果最近的一次包接收失败,则变化情况如下:
376->11,111,110
375->11,111,101
373->11,111,011
……
177->01,111,111
377->11,111,111
delay:
roundtrip delay, the time delay (in milliseconds) to communicate with the remote.
表示NTP client从发出NTP请求到接收到NTP服务器回复所经过的时间。
offset:
the offset (in milliseconds) between our time and that of the remote.
即NTP client的本地时间与NTP服务器时间的差异。也就是NTP client需要调整的时间差异。
disp:
DISP=indicates the difference in the offset measurement between two samples. This is an error-bound estimate. The dispersion is a primary measure of the network service quality.
表示两次时钟同步之间的offset的差值。
Note: According to Sun, NTP can only sync time if it is off by no more than 17 minutes. Furthermore, adjusting time being off by seconds will take several minutes because NTP is architected to slowly adjust to the NTP master's time.(时钟差异超过17分钟将无法同步)
如果在solaris10上出现了因为时钟差异较大而无法进行时钟同步,最简单的方式就是重启一下NTP client端的ntp服务。
#> svcadm restart ntp
ntp的启动脚本中使用了ntpdate命令先与NTP server同步一次时间,然后再启动xntpd进程。
ntp服务的启动脚本:/lib/svc/method/xntp
……
# Run ntpdate to sync system to peer before starting xntpd [ -n "$ARGS" ] && /usr/sbin/ntpdate $ARGS /usr/lib/inet/xntpd
在solaris上使用snoop查看时钟同步包
-bash-3.00# snoop -d e1000g0 udp port 123 Using device /dev/e1000g0 (promiscuous mode) node2 -> 10.0.2.71 NTP client [st=5] (2011-12-06 16:52:18.57994)
主机node2(NTP client)向10.0.2.71发NTP请求包, node2层级是5, 包中是node2本地时间 10.0.2.71 -> node2 NTP server [st=4] (2011-12-06 16:52:18.57914)
10.0.2.71(NTP server)向node2回复,10.0.2.71层级是4,包中是10.0.2.71的本地时间
node2 -> 10.0.2.71 NTP client [st=5] (2011-12-06 16:53:22.57963) 10.0.2.71 -> node2 NTP server [st=4] (2011-12-06 16:53:22.57871) node2 -> 10.0.2.71 NTP client [st=5] (2011-12-06 16:54:26.57921) 10.0.2.71 -> node2 NTP server [st=4] (2011-12-06 16:54:26.57825)
……
-bash-3.00# snoop -V port 123 Using device /dev/e1000g0 (promiscuous mode) ________________________________ node2 -> 10.0.2.71 ETHER Type=0800 (IP), size = 90 bytes node2 -> 10.0.2.71 IP D=10.0.2.71 S=10.0.2.72 LEN=76, ID=61706, TOS=0x0, TTL=255 node2 -> 10.0.2.71 UDP D=123 S=123 LEN=56 node2 -> 10.0.2.71 NTP client [st=5] (2011-12-06 16:58:42.57762) ________________________________ 10.0.2.71 -> node2 ETHER Type=0800 (IP), size = 90 bytes 10.0.2.71 -> node2 IP D=10.0.2.72 S=10.0.2.71 LEN=76, ID=12572, TOS=0x0, TTL=255 10.0.2.71 -> node2 UDP D=123 S=123 LEN=56 10.0.2.71 -> node2 NTP server [st=4] (2011-12-06 16:58:42.57666)