您的位置:首页 > 理论基础

NTP协议以及ntpclinet使用 From Evernote: NTP协议以及ntpclinet使用 NTP全称是Network Time Protocol,是用来让计算机之间实现时间同步的协议

2014-04-16 17:31 716 查看
NTP全称是Network Time Protocol,是用来让计算机之间实现时间同步的协议。发布这种校对时间的服务器,就是NTP Server;而在Internet中的任何主机上都可以使用NTP客户端程序从NTP Server上读取时间,以实现网络时间同步的功能。

国内的NTP Server基本都属于科研教育机构所有,普通社会组织发布的NTP Server并不多,以下是搜集的一些国内可用的NTP Server:

1.cn.pool.ntp.org

2.cn.pool.ntp.org

3.cn.pool.ntp.org

0.cn.pool.ntp.org

cn.pool.ntp.org

tw.pool.ntp.org

0.tw.pool.ntp.org

1.tw.pool.ntp.org

2.tw.pool.ntp.org

3.tw.pool.ntp.org

ntpclient是可在类Unix系统上运行的ntp客户端程序,用于从网络上的NTP服务器上读取时间并设置到本地主机上。源码的下载地址为:http://doolittle.icarus.com/ntpclient/。
ntpclient的使用方法:

pavel@pavel-desktop ~/test/ntpclient-2010 $ ./ntpclient

Usage: ./ntpclient [-c count] [-d] [-f frequency] [-g goodness] -h hostname

[-i interval] [-l] [-p port] [-q min_delay] [-r] [-s] [-t]

主要选项说明:

-h hostname:NTP Server地址

-c count:从NTP Server上读取时间的执行次数

-i:执行多次校时操作的时间间隔,默认为600s

-s:读取到时间后设置到本地主机中

-g goodness:当读取时间与本地时间的差值精确度好于goodness(以ms为单位)时程序退出,否则一直执行。goodness默认为0,表示一直执行

-p port:ntpclient访问ntp服务器时所使用的本地UDP端口,默认为任何可用的端口

-d:打印调试信息,该特性可在编译时禁止掉

ntpclient应用程序的执行说明:

$ sudo ./ntpclient -h 114.80.81.1 -c 10 -i 10 -s

以上调用表示NTP服务器地址为114.80.81.1,连续执行10次,每次间隔时间为10s,从NTP服务器上读取到时间后设置到本地主机中。

pavel@pavel-desktop ~/test/ntpclient-2010 $ sudo ./ntpclient -h 114.80.81.1 -c 10 -i 10 -s

day second elapsed stall skew dispersion freq

40678 20520.811 49937.0 31.5 7163.7 41885.4 0

其中:

day,second:表示当前时间距离1900年1月1日的时间,分别为天数和秒

elapsed:表示从发出读取时间命令到时间信息收到总共花费的时间,以us为单位

skew:表示服务器时间与本地主机时间的偏差,以us为单位
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: