-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)