安装 RAC时间同步简单方法

来源:互联网 发布:linux自动关机脚本 编辑:程序博客网 时间:2024/06/07 00:37

  这两天在VMServer上模拟oracle10g的双节点RAC,在集群配制时rac1和rac2的时间同步出问题,尝试过在本地搭建NTP服务器和以rac1和rac2分别为NTP Server同步,总感觉效果复杂容易出错,后来网上看到有学友如下解决,感觉比较简单,贴出来分享下


    在配置RAC的时候,特别是虚拟机上,如果不做任何的措施,时间同步几乎是不可能的,一般情况是哪个节点负载高,那个节点的时间就跑得快,比如在rac1执行clusterware的安装,则rac1时间明显跑得比rac2快;而当安装过程中rac1传输文件到远程rac2节点时,往往rac2时间就跑得比较快了。所以必须通过ntpdate 或 rdate 来对两台或多台节点Server进行时间同步。而rdate 更加方便一些,用过ntp但效果很差

同步时间:


1)在rac01上启动time-stream服务,并设置为自动开启

[root@rac01 ~]# chkconfig   time-stream on

注意:

在redhat 4中命令是:   #chkconfig time on


2)在rac02上添加任务,每一分钟和rac1进行一次时间同步。

[root@rac02 ~]# crontab  -l

*/1 * * * *    rdate    -s    10.254.119.50

10.254.119.50 是节点1的IP地址。


------------------------------------------下面是个人感觉学习ntp时间同步的经典资料--------------------------
在rac环境中,会要求各个节点之间的时间差不能超时。一般如果超过30秒,节点很可能会重启。
所以要同步各节点的时间。例如,我们需要配置一个ntp时钟服务器,来给rac的各个节点进行时
间同步。或者让节点之间进行时间同步,保证各节点的时间同步,但无法保证rac数据库的时间的准确性。

目录:
一. 节点间的时间同步方法:
        方法一:建立ntp时钟服务器,各节点与ntp server同步时间
        方法二:利用定时任务,让节点间时间同步(用rdate或ntpdate)
二. ntp相关错误及解决方法
三. ntp原理


--------------------------------------------------------------------------

一. 节点间的时间同步方法

环境:ntp server是wxp
      client是centos5

在这里,我以windows机器(192.168.2.29)做ntp server,以1台linux为clent客户端(192.168.2.245)来说明时间同步方法。

方法一:

1.ntp服务端配置

首先下载安装windows版的ntp server —— ntp-424p311502-foehr-v2-o-win32-setup

安装很简单,直接运行exe文件即可,安装后修改ntp.conf配置文件,添加如下两行内容:

server 127.127.1.0 prefer       
fudge 127.127.1.0 stratum 10


说明:
127.127.1.0 : 该IP为NTP定义的server自己的IP
prefer :这个参数表示该server是master server
fudge:这个参数表示该IP为NTPserver, 
stratum:表示该系统所在的NTP层级.

我的windows ntpserver的"C:/Program Files/NTP/etc/ntp.conf"文件如下:

# NTP Network Time Protocol 
# Configuration File created by Windows Binary Distribution Installer Rev.: 1.22  mbg
# please check 
http://www.ntp.org for additional documentation and background information
# Use drift file 
driftfile "C:/Program Files/NTP/etc/ntp.drift"

# your local system clock, could be used as a backup
# (this is only useful if you need to distribute time no matter how good or bad it is)
#server 127.127.1.0
# but it should operate at a high stratum level to let the clients know and force them to
# use any other timesource they may have.
#fudge 127.127.1.0 stratum 12

#skate add
server 127.127.1.0 prefer
fudge 127.127.1.0 stratum 10
#skate add

# End of generated ntp.conf --- Please edit this to suite your needs


配置完成后,重新启动ntp
重启方法:开始-》运行-》services.msc-》Network Time Protocol Daemon。

2.配置client的linux

A.修改客户端linux的配置文件 /etc/ntp.conf,添加如下一行
server 192.168.2.29 prefer

如果是多个time server服务器的话,可以按如下的方式:

server 192.168.2.29 prefer        ---prefer表示该server是master server
server 192.168.3.29
server 192.168.4.29
server 192.168.5.29

注释掉如下一行
server 127.127.1.0 # local clock


在这里要另外说一下,网上的有朋友说要把
“fudge   127.127.1.0 stratum 10” 改成 “fudge   192.168.2.29 stratum 10”

但经过我的测试发现,如果这样修改的的话,就不能自动同步时间了。


我的客户端的linux的 /etc/ntp.conf 内容如下:

[root@localhost ~]# more /etc/ntp.conf 
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.

restrict default nomodify notrap noquery
# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 


# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service.  Do not permit those systems to modify the
# configuration of this service.  Also, do not use those
# systems as peers for synchronization.
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap


# --- OUR TIMESERVERS ----- 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (
http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org


# --- NTP MULTICASTCLIENT ---
#multicastclient                        # listen on default 224.0.1.1
# restrict 224.0.1.1 mask 255.255.255.255 nomodify notrap
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap


# --- GENERAL CONFIGURATION ---
#
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. The
# default stratum is usually 3, but in this case we elect to use stratum
# 0. Since the server line does not have the prefer keyword, this driver
# is never used for synchronization, unless no other other
# synchronization source is available. In case the local host is
# controlled by some external source, such as an external oscillator or
# another protocol, the prefer keyword would cause the local host to
# disregard all other synchronization sources, unless the kernel
# modifications are in use and declare an unsynchronized condition.
#

#server 127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

#skate add 
server 192.168.2.29 prefer
#skate add


#
# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /var/lib/ntp/drift
broadcastdelay  0.008

#
# Keys file.  If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
keys            /etc/ntp/keys
[root@localhost ~]# 

B.修改/etc/ntp/ntpservers文件,把里面的server IP改为自己的ntp server的IP,
   也就是windows机器,下面是我的/etc/ntp/ntpservers:

[root@localhost ~]# more /etc/ntp/ntpservers 
#This file contains a list of ntp servers to show in the system-config-date user interface.
#It is not recommended that you modify this file by hand.

0.centos.pool.ntp.org
1.centos.pool.ntp.org
2.centos.pool.ntp.org
3.centos.pool.ntp.org

#skate add 
192.168.2.29
#skate add 

[root@localhost ~]# 

C.修改/etc/hosts文件,加入windows主机的IP和主机名。---测试中发现不用修改这个

D。手工做一次时间同步,因为如果客户端和时间服务器的时间偏移量超过1000秒,在启动ntp服务后
   客户端不能自动与NTP master服务器进行同步。


[root@localhost ~]# service ntpd status
ntpd is stopped

[root@localhost ~]# service ntpd start
Starting ntpd: [  OK  ]

[root@localhost ~]# ntpdate 192.168.2.29
5 May 18:57:55 ntpdate[27167]: the NTP socket is in use, exiting

[root@localhost ~]# ps -ef |grep ntp
ntp      27164     1  0 19:08 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root     27185 26987  0 19:15 pts/4    00:00:00 grep ntp
[root@localhost ~]# kill 27164

[root@localhost ~]# ps -ef |grep ntp
root     27187 26987  0 19:15 pts/4    00:00:00 grep ntp

[root@localhost ~]# ntpdate 192.168.2.28
5 May 19:15:29 ntpdate[27188]: no server suitable for synchronization found

[root@localhost ~]# ntpdate -u 192.168.2.28
5 May 19:15:40 ntpdate[27190]: no server suitable for synchronization found

间隔一段时间后,就可以同步了,因在ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,
这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。

[root@localhost ~]# ntpdate 192.168.2.28
5 May 19:55:49 ntpdate[27226]: step time server 192.168.2.28 offset 939.130626 sec
[root@localhost ~]# ntpdate 192.168.2.28
5 May 19:56:25 ntpdate[27227]: adjust time server 192.168.2.28 offset 0.000300 sec

E. 启动客户端的ntp服务



[root@localhost ~]# service ntpd status
ntpd dead but pid file exists



[root@localhost ~]# service ntpd start
Starting ntpd: [  OK  ]

[root@localhost ~]# service ntpd status
ntpd (pid 27248) is running...

[root@localhost ~]#

配置其自启动的级别

[root@localhost ~]# chkconfig --list |grep ntp
ntpd            0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
[root@localhost ~]# chkconfig --level 5 ntpd on
[root@localhost ~]# chkconfig --list |grep ntp
ntpd            0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:启用  6:关闭
[root@localhost ~]# 

##########################################################################

方法二:

环境:ntp server是redhat4
      client是centos5

除了用上面的ntp协议来实现时间的同步外,还可以用date和ntpdate命令做定时任务来实现和远程服务器同步时间。例如

(一).ntp server端的配置:

1.查看ntp协议是否安装
2.修改ntp.conf
3.启动ntp服务

实际步骤:

1.查看ntp协议是否安装

[root@svr-db-test ~]# rpm -qa | grep ntp
ntp-4.2.2p1-5.el5
chkfontpath-1.10.1-1.1
You have new mail in /var/spool/mail/root

如果没有安装,可以用rpm -Uvh ntp*.rpm或者yum命令安装

2.修改ntp.conf

修改这个配置文件是为了让远程客户端有权来同步时间

[root@svr-db-test ~]# vi /etc/ntp.conf 
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.


#skate modify
#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod nomodify notrap nopeer noquery
#skate modify

#skate add
restrict default kod nomodify  nopeer noquery
restrict -6 default kod nomodify  nopeer noquery
#skate add


# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (
http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org

#broadcast 192.168.1.255 key 42         # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 key 42             # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 key 42  # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  127.127.1.0     # local clock
server  192.168.2.245
fudge   127.127.1.0 stratum 10

# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8
[root@svr-db-test ~]# 

注意:这个文件这里有两种修改方法:

A、第一种配置:允许任何IP的客户机都可以进行时间同步
将“restrict default kod nomodify notrap nopeer noquery”这行修改成:
restrict default kod nomodify notrap nopeer 

B、第二种配置:只允许192.168.211.***网段的客户机进行时间同步
在restrict default kod nomodify notrap nopeer noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.211.0 mask 255.255.255.0 nomodify notrap

但是在我的修改中我只是把”restrict default kod nomodify notrap nopeer noquery“改为
”restrict default kod nomodify  nopeer noquery“

为什么这么做呢?如果不去掉notrap的话,在客户端同步时间会报错,例如:

[root@localhost ~]# ntpdate 192.168.2.203
5 May 21:35:14 ntpdate[27467]: no server suitable for synchronization found

[root@localhost ~]# ntpdate -u 192.168.2.203
5 May 21:35:07 ntpdate[27466]: no server suitable for synchronization found

[root@localhost ~]# ntpdate -d 192.168.2.203
5 May 21:35:20 ntpdate[27470]: ntpdate 4.2.0a@1.1190-r Mon Jul 28 11:06:17 EDT 2008 (1)
Looking for host 192.168.2.203 and service ntp
host found : 192.168.2.203
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
transmit(192.168.2.203)
192.168.2.203: Server dropped: no data
server 192.168.2.203, port 123
stratum 0, precision 0, leap 00, trust 000
refid [192.168.2.203], delay 0.00000, dispersion 64.00000
transmitted 4, in filter 4
reference time:    00000000.00000000  Thu, Feb  7 2036 14:28:16.000
originate timestamp: 00000000.00000000  Thu, Feb  7 2036 14:28:16.000
transmit timestamp:  cf8bf29b.578ef34d  Wed, May  5 2010 21:35:23.342
filter delay:  0.00000  0.00000  0.00000  0.00000 
         0.00000  0.00000  0.00000  0.00000 
filter offset: 0.000000 0.000000 0.000000 0.000000
         0.000000 0.000000 0.000000 0.000000
delay 0.00000, dispersion 64.00000
offset 0.000000
5 May 21:35:24 ntpdate[27470]: no server suitable for synchronization found


出现这个问题的原因可能有二:

1。检查ntp的版本,如果你使用的是ntp4.2(包括4.2)之后的版本,
   在restrict的定义中使用了notrust的话,会导致以上错误。

解决方法:把restrict定义中的notrust去掉

2。检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。
   如果关闭防火墙,再尝试从ntp客户端的同步,如果成功,证明是防火墙
   的问题,需要更改iptables的设置。
   
解决方法: service iptables stop


开始诊断:

在ntp server端执行

首先看是不是ntp server的防火墙的问题:
[root@svr-db-test ~]# service iptables status
防火墙已停

在查看ntp的版本:
[root@svr-db-test ~]# ntpq -c version
ntpq 4.2.2p1@1.1570 Wed Nov 29 15:16:31 UTC 2006 (1)中

在我的ntp server的ntp.conf中restrict的定义中使用了notrust,然后修改配置文件
把notrust去掉,再重起ntp server 的ntp服务,从客户端就可以同步时间了,不过要等几分钟
因为ntp server要先自己同步一段时间,前面有介绍。在这期间你要尝试同步的话,会得到
错误”no server suitable for synchronization found“


下面是来自ntp官方网站的说明:
A. The behavior of notrust changed between versions 4.1 and 4.2.
B. In 4.1 (and earlier) notrust meant "Don't trust this host/subnet for time".
C. In 4.2 (and later) notrust means "Ignore all NTP packets that are not 
   cryptographically authenticated." This forces remote time servers to authenticate themselves to your (client) ntpd

3.启动ntp服务

[root@svr-db-test ~]# service ntpd restart
ntpd (pid 13608 13597) 正在运行...
或者
[root@svr-db-test ~]# /etc/init.d/ntpd restart
ntpd (pid 13608 13597) 正在运行...
[root@svr-db-test ~]# 

开机启动ntp服务的方法:

[root@svr-db-test ~]# chkconfig --list |grep ntp
ntpd            0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
[root@svr-db-test ~]# chkconfig --level 5 ntpd on
[root@svr-db-test ~]# chkconfig --list |grep ntp
ntpd            0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:启用  6:关闭
[root@svr-db-test ~]# 

(二)。客户端的配置
利用crontab来执行
crontab -e
0 21 * * * ntpdate 192.168.2.29 >> /root/ntpdate.log 2>&1
每天晚上9点进行同步
说明:rdate命令时间同步的方法要简单些,也没有ntpdate时间精确。就不介绍了啊

参考:
http://www.oracleblog.cn/working-case/install-ntp/
http://liuchao11006-163-com.**.com/blog/576421


-------------------------------------------------------------------------------

二。ntp相关错误及解决方法

ntpdate相关命令:
ntpdate  192.168.2.29 
ntpdate -d 192.168.2.29 调试模式
ntpdate -u 192.168.2.29  用非授权端口
ntpdate -s 5 192.168.2.29 延时5秒看行否

1. ntpdate同步时间时经常出错如下:“no server suitable for synchronization found”

A。
  在重启ntp服务的时候,ntp server自身或者与其server的同步的需要一个时间段,
   这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生
   no server suitable for synchronization found的错误。

那么如何知道何时ntp server完成了和自身同步的过程呢?可以用如下的命令

在ntp server上执行:
[root@svr-db-test ~]# watch ntpq -p
Every 2.0s: ntpq -p                                                               Wed May  5 22:07:19 2010
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.          10 l   54   64  377    0.000    0.000   0.001
192.168.2.245   .INIT.          16 u    -  256    0    0.000    0.000   0.000

注意LOCAL的这个就是与自身同步的ntp server
注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,
从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。
如果之后从ntp客户端同步ntp server还失败的话,用ntpdate –d来查询详细错误信息,再做判断。

2.用ntpdate –d ip可能诊断出两个错误

A。错误1.Server dropped: Strata too high

在ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。
在ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,
并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。

这是因为NTP server还没有和其自身或者它的server同步上。

以下的定义是让NTP Server和其自身保持同步,如果在/ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。

server 127.127.1.0               
fudge 127.127.1.0 stratum 8 


B。错误2.Server dropped: no data

这个问题上面已经说过了啊,这里就不说了啊。

参考:
http://www.blogjava.net/spray/archive/2008/07/10/213964.html

---------------------------------------------------------------------


三。ntp原理

     NTP(Network Time Protocol)是由美国德拉瓦大学的David L. Mills教授于1985年提出,除了可以估算封包在网络上的往返延迟外,
还可独立地估算计算机时钟偏差,从而实现在网络上的高精准度计算机校时,它是设计用来在Internet上使不同的机器能维持相同时间
的一种通信协议。时间服务器(time server)是利用NTP的一种服务器,通过它可以使网络中的机器维持时间同步。在大多数的地方,
NTP可以提供1-50ms的可信赖性的同步时间源和网络工作路径。

      网络时间协议(NTP)的详细说明在RFC-1305[Mills 1992]中。RFC-1305对 NTP协议自动机在事件、状态、转变功能和行为方面给出了明确的说明。它以合适的算法以增强时钟的准确性,并且减轻多个由于同步源而产生的差错,实现了准确性低于毫秒的时间服务,以满足目前因特网中路径量测的需要。

NTP是一个跨越广域网或局域网的复杂的同步时间协议,它通常可获得毫秒级的精度。RFC2030[Mills 1996]描述了SNTP(Simple Network Time Protocol),目的是为了那些不需要完整NTP实现复杂性的主机,它是NTP的一个子集。通常让局域网上的若干台主机通过因特网与其他的NTP主机同步时钟,接着再向局域网内其他客户端提供时间同步服务。

NTP的特点

1,从UTC获取标准时间
网络时间协议,提供在互连的网络上提供校时服务和发送标准时间给计算机。目前已成为Internet上时间同步的标准协议。NTP提供准确时间,首先要有准确的时间来源,这一时间应是国际标准时间UTC。NTP获得UTC的时间来源可以是原子钟,天文台,卫星,也可以从Internet上获取。这样就有了准确而可靠的时间源。

2,NTP服务器分层提供服务
时间按NTP服务器的等级传播。按照离外部UTC源的远近将所有服务器归入不同的Stratum(层)中。Stratum-1在顶层,由外部UTC接入,而Stratum-2则从Stratum-1获取时间,Stratum-3从Stratum-2获取时间,以此类推,但Stratum层的总数限制在15以内。所有这些服务器在逻辑上形阶梯式的架构相互连接,而Stratum-1的时间服务器是整个系统的基础。

3,过滤算法选择时间的最佳路径和来源
计算机主机一般同多个时间服务器连接,利用统计学的算法过滤来自不同服务器的时间包,以选择最佳的路径和来源来校正主机时间。即使主
机在长时间无法与某一时间服务器相联系的情况下,NTP服务依然有效运转。

4,识别机制抗干扰和恶意破坏
为防止对时间服务器的恶意破坏,NTP使用了识别(Authentication)机制,检查来对时的信息是否是真正来自所宣称的服务器并检查资料的返回路径,以提供对抗干扰的保护机制。

NTP的实现方式

1,无线时钟:服务器系统可以通过串口连接一个无线时钟。无线时钟接收GPS(全球卫星定位系统)的卫星发射的信号来决定当前时间。
   无线时钟是一个非常精确的时间源,但是需要花一定的费用。 

2,时间服务器:还可以使用网络中NTP时间服务器,通过这个服务器来同步网络中的系统的时钟。http://www.eecis.udel.edu/~mills/ntp/servers.html 列出了Internet上有效的一级时间服务器。 

3,局域网内的同步:如果只是需要在本局域网内进行系统间的时钟同步,那么就可以使用局域网中任何一个系统的时钟。你需要选择局
   域网中的一个节点的时钟作“权威的”的时间源,然后其它的节点就只需要与这个时间源进行时间同步即可。使用这种方式,所有的节
   点都会使用一个公共的系统时钟,但是不需要和局域网外的系统进行时钟同步。如果一个系统在一个局域网的内部,同时又不能使用
   无线时钟,这种方式是最好的选择。

NTP的工作模式

1,Sever/Client mode:用户向一个多几个服务器提出服务请求,根据所交换的信息,从中选择认为最准确的时间,并调整本地的时钟。
2,Multicast/Broadcast mode:此种模式是适用于用在高速的LAN上。利用一个或多个服务器在固定的周期向某个多播地址做广播。
3,Symmetric mode:二个以上的Server互相进行时间消息的通讯,可以互相校正对方的时间,以维持整个subnet的时间一致性。

NTP协议结构

NTP packet = NTP header + Four TimeStamps = 48bytes
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[header, 16bytes]
2   3      3         8              8      8      共32bits
LI  VN  Mode  Stratum  Poll  Precision
Root Delay (32bits)
Root Dispersion (32bits)
Reference Identifier (32bits)
[Timestamp 1, 8bytes]
Reference Timestamp (64bits)
[Timestamp 2, 8bytes]
Originate Timestamp (64bits)
[Timestamp 3, 8bytes]
Receive Timestamp (64bits)
[Timestamp 4, 8bytes]
Transmit Timestamp (64bits)
Key Identifier (optional) (32bits)
Message digest (optional) (128bits)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

字段说明:
* LI:LeapYearIndicator, 跳跃指示器,警告在当月最后一天的最终时刻插入的迫近闺秒(闺秒)。
* VN:VersionNumber, 版本号。
* Mode:模式, 0-预留;1-对称行为;3-客户机;4-服务器;5-广播;6-NTP 控制信息
* Stratum:层级。
* Poll:PollInterval, 有符号整数表示连续信息间的最大间隔。
* Precision:有符号整数表示本地时钟精确度。
* Root Delay:有符号固定点序号表示主要参考源的总延迟,很短时间内的位15到16间的分段点。
* Root Dispersion:无符号固定点序号表示相对于主要参考源的正常差错。
* Reference Identifier:识别特殊参考源。
* Reference Timestamp
* Originate Timestamp:这是向服务器请求分离客户机的时间,采用64位时标格式。
* Receive   Timestamp:这是向服务器请求到达客户机的时间,采用64位时标(Timestamp)格式。
* Transmit  Timestamp:这是向客户机答复分离服务器的时间,采用64位时标(Timestamp)格式。
* Authenticator(可选):主要标识符和信息数字域就包括已定义的信息认证代码(MAC)信息。


网络延时与时钟偏差的测量

Timestamp Name             ID        When Generated
Originate Timestamp       T1        time request sent by client
Receive Timestamp         T2        time request received at server
Transmit Timestamp        T3        time reply sent by server
Destination Timestamp   T4        time reply received at client
t 为服务器和客户端之间的时间偏差;
d 为两者之间的往返时间

∵ T2 = T1 + t + d/2; ∴ T2 - T1 = t + d/2; 
∵ T4 = T3 - t + d/2;  ∴ T3 - T4 = t - d/2;
∴ d = (T2 - T1) + (T4 - T3); t = [(T2 - T1) + (T3 - T4)] / 2;


-------end-----

0 0
原创粉丝点击