嵌入式 NtpClient 选项用法详解

用法:程序NtpClient[选项]
选项:
-c count count时间计数后停止(默认为0意味直到永远)
-d      打印诊断(功能可以在编译时关闭)
-g 选项会导致程序NtpClient后得到的结果更准确,而不仅仅是(微秒,默认为0意味直到永远停止)
-h 主机名(ip地址)(强制)NTP服务器,对系统时间来衡量
-i 间隔时间 每隔一定时间检查时间(默认值为600)
-I 尝试服务器使用adjtimex锁定本地时钟(2)
-p 端口名  锁定本地NTP客户端UDP端口(默认为0表示“任何可用的”)
-q 最小延时分钟 最小数据包的延迟交易(默认800微秒)
-r 在标准输入重播分析代码
-s 简单的时钟设置(相当于-c 1)
-t 信任网络和服务器,没有RFC-4330推荐使用的检查
(用法为本人翻译,有些不太准确,请看下面原版英文)
时间同步服务器一般用法示例:

#!/bin/sh #get params . /sbin/global.sh start() { if [ -f /bin/ntpclient ]; then echo "Starting NTP: " srv=`nvram_get 2860 NTPServerIP` sync=`nvram_get 2860 NTPSync` tz=`nvram_get 2860 TZ` backup_time=`date +%T` sync=`expr $sync \* 3600` if [ "$tz" = "" ]; then tz="UCT_000" fi echo $tz > /etc/tmpTZ sed -e 's#.*_\(-*\)0*\(.*\)#GMT-\1\2#' /etc/tmpTZ > /etc/tmpTZ2 sed -e 's#\(.*\)--\(.*\)#\1\2#' /etc/tmpTZ2 > /etc/TZ rm -rf /etc/tmpTZ rm -rf /etc/tmpTZ2 date +%T -s $backup_time if [ "$srv" != "" ]; then ntpclient -s -c 0 -h $srv -i $sync & fi fi } stop() { echo "Stopping NTP: " killall -q ntpclient } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac


Usage: ntpclient [options]
options:
-c count     stop after count time measurements (default 0 means go forever)
-d           print diagnostics (feature can be disabled at compile time)
-g goodness  causes ntpclient to stop after getting a result more accurate
                   than goodness (microseconds, default 0 means go forever)
-h hostname  (mandatory) NTP server, against which to measure system time
-i interval  check time every interval seconds (default 600)
-l           attempt to lock local clock to server using adjtimex(2)
-p port      local NTP client UDP port (default 0 means "any available")
-q min_delay minimum packet delay for transaction (default 800 microseconds)
-r           replay analysis code based on stdin
-s           simple clock set (implies -c 1)
-t           trust network and server, no RFC-4330 recommended cross-checks
以下为google翻译:
程序NtpClient NTP(RFC-1305,RFC-4330)客户端的UNIX相似的计算机。
它的功能的一小部分XNTPD,但恕我直言执行
更好的(或至少是有可能更好地运作)内
有限的范围内。由于它是远小于xntpd命令,它是
了解更多相关的嵌入式计算机。
程序NtpClient版权所有1997年,1999年,2000年,2003年,2006年,2007年拉里?杜利特尔,
并可以自由复制和修改的GNU的条款
通用公共许可证第2版。如果您要分发的程序NtpClient
在其他条款,请与我联系。我可能会同意一些其他的安排,
如果你跟我_before_启动违反GPL条款。
程序NtpClient主页:http://doolittle.icarus.com/ntpclient/
约阿希姆?尼尔森创造的一个分支,程序NtpClient,他坚持在
http://vmlinux.org/jocke/ntpclient.shtml。我们不具有相同的
修的,并建立系统的感情,有些人可能更喜欢他的。
特别是,他已经将他的守护程序和系统日志程序NtpClient。
两个版本的基本功能应该是相同的。
要在Linux上构建,输入“make”。 Solaris和其他Unix用户
可能需要稍微调整的Makefile。这并不复杂。
为了改变系统时钟频率,只在Linux adjtimex(2)
接口,在这个时候实施。非Linux系统只能
测量时间的差异和设置系统时钟,使用程序NtpClient
POSIX 1003.1-2001标准程序clock_gettime()和
clock_settime()。还可以看到“错误”,在下面。
有几个编译时配置可能的,这需要
编辑Makefile。无论是做或不定义
??ENABLE_DEBUG
??ENABLE_REPLAY
??USE_OBSOLETE_GETTIMEOFDAY
??PRECISION_SIOCGSTAMP
首先尝试没有更改默认:这会给你一个全
功能程序NtpClient,采用现代POSIX时间的功能,工作
合理的任何Linux内核。有在ntpclient.c评论
你应该读之前尝试与PRECISION_SIOCGSTAMP。
有些老,但以其他方式(几乎)维修的Linux系统(例如,红帽
EL-3.0和Ubuntu 4.10)有一个完全打破:POSIX clock_settime()
实施。如果你获得“clock_settime的:无效的参数”当你
运行程序NtpClient-S,重建与DUSE_OBSOLETE_GETTIMEOFDAY。 Linux系统
更老的甚至不会编译没有这种开关的设置。
用法:程序NtpClient[选项]
选项:
-c count count时间计数后停止(默认为0意味直到永远)
-d      打印诊断(功能可以在编译时关闭)
-g 选项会导致程序NtpClient后得到的结果更准确,而不仅仅是(微秒,默认为0意味直到永远停止)
-h 主机名(强制)NTP服务器,对系统时间来衡量
-i 间隔时间 每隔一定时间检查时间(默认值为600)
-I 尝试服务器使用adjtimex锁定本地时钟(2)
-p 端口名  锁定本地NTP客户端UDP端口(默认为0表示“任何可用的”)
-q 最小延时分钟 最小数据包的延迟交易(默认800微秒)
-r 在标准输入重播分析代码
-s 简单的时钟设置(相当于-c 1)
-t 信任网络和服务器,没有RFC-4330推荐使用的检查
死机的用户可以使用该程序进行监控,但没有时钟设置
(与-s或-l开关)。 -l开关被设计成强大的
在任何网络环境中,但已经看到了最广泛的测试,
低时延(小于2 ms)以太网环境中。在其他的用户
环境研究程序NtpClient的行为,并准备调整
内部调整参数。如何和为什么要使用一个长的描述
程序NtpClient的HOWTO文件。程序NtpClient始终将数据包发送到
服务器的UDP端口123。
通常需要调整参数锁定模式是min_delay,
最短的往返交易时间。这可以设置与
命令行-q开关。默认情况下为800微秒的历史
良好的本地以太网硬件在几年前。如果定得太高,
在时间锁定时,你会得到很多的“不一致”日志文件中的行
(-l开关)。唯一真正的面向未来的值是0,但会导致
本地时间比它应该多走。我使用我的工作站上200。
test.dat的文件有200行的样本输出。它的第几行,
-d选项时,将显示与输出列标题
选择是:
?日第二次经过的摊位歪斜分散频率
36765 00180.386 1398.0 40.3 953773.9 793.5 -1240000
36765 00780.382 1358.0 41.3 954329.0 915.5 -1240000
36765 01380.381 1439.0 56.0 954871.3 915.5 -1240000
一天,第二:时间的测量,UTC,相对于NTP的时代(1900年1月1日)
经过:从查询响应的总时间(微秒)
摊主:服务器报告的要求,它坐在(微秒)
歪斜:区别本地时间和服务器时间(微秒)
分散性:服务器报告的信息,请参阅RFC-1305(微秒)
频率:本地时钟频率调整(仅限于Linux,PPM * 65536)
一个相对较新的功能,是一个系列的完整性检查
UDP数据包,一般建议由RFC-4330。如果
失败这些测试之一,上述的线被替换
36765 01380.381拒绝包
或者,如果ENABLE_DEBUG在编译时,被选择的一个
36765 01380.381拒绝数据包:李== 3
36765 01380.381拒绝的数据包:VN <3
36765 01380.381拒绝数据包:MODE = 3
=发送36765 01380.381拒绝数据包:ORG!
36765 01380.381拒绝数据包:XMT == 0
36765 01380.381拒绝数据包:ABS(DELAY)> 65536
36765 01380.381拒绝数据包:ABS(DISP)> 65536
36765 01380.381拒绝数据包:地层== 0
要查看被拒绝的数据包的实际价值,与启动程序NtpClient
-d选项,这将会给人类可读的打印接收的每一个数据包,
包括拒绝的。要跳过这些检查,使用-t开关。
TEST.DAT是合适的管道到程序NtpClient-R的。我有超过200000
样品(系)存档的学习,我不包括在这里。
他们一般间隔10分钟,超过三
年的数据记录(从各种机器,而不是连续的,
不幸的是)。
作为一种特殊的,额外的奖励,我也有我的adjtimex(1)程序。
有关详细信息,请参阅手册页和HOWTO文件。
信封是一个perl脚本,我用我的锁研究。
这是一个黑客攻击的,不值得记录在这里。
广泛分布的ntpclient_2000_345版本的变化,因为:
? - 新的-g选项(已有限的测试)
? - 改变最大91 ppm的频率调整到150 ppm的
? - 固定的“不一致”的错误引发的大频率误差在phaselock.c
? - 新的文件:HOWTO,adjtimex.c,adjtimex.1,rate.awk,log2date.pl
? - 小源代码清理
? - 源是现在为64位,干净,实用,在Alpha测试
? - 可选的补丁提供的安迪华纳,看到andyw.patch
? - 由Linksys提供的可选的补丁,请参阅linksys.patch
? - 删除不合理的偏移15020天在日期列(XNTPD有这个的
??????偏移量,这将天以来-1900-划时代到修正的儒略日)
广泛分布的ntpclient_2003_194版本的变化,因为:
? - 默认的构建是现在,性病= C99,C89窗台的作品了
? - 交换机的默认编译的gettimeofday()到POSIX clock_gettime()
? - 更多的检查NTP应答报文,参考RFC-4330
? - 在调试输出的分数第二次印刷改变传统的十进制
? - 新的-f开关来设置初始频率
? - 工程同时指定-s和-L,将相位锁定,然后再设置
? - 错误修复程序选择()错误处理,由于沃尔特?哈姆斯
? - 新的手册页,由沃尔特?哈姆斯贡献
? - 最子程序是静态的编译器标记
? - 结构性变化的代码,如新的ntpclient.h文件
? - 下降(主要)过时的补丁,Linksys和安迪?华纳
自ntpclient_2006_318变化:
? - min_delay参数可调,使用的是硬编码的800微秒
? - 移除无用的听()调用,由于亚历山大Indenbaum的
? - 固定长度传递给recvfrom(),由于亚历山大Indenbaum的
? - 收拾的32位整数声明,敦促下布赖恩?麦卡利斯特
? - 增值rate2.awk,贡献娄Sortman
? - 提供简单的方式,覆盖15 MIN_INTERVAL在编译时
? - 放松MIN_INTERVAL执行一次性的使用,这要感谢米哈伊?布哈
自ntpclient_2007_365变化:
? - 固定式的sa_xmit_len,感谢vapier
? - 下降下划线的拼写adjtimex(2),可能使uClibc的更快乐
? - 包括netdb.h中的和总是定义_BSD_SOURCE的拿到的样机herror
? - 轻微的格式,以配合Nilsson的叉
? - 附加FNO严格的混叠所需要的传统的网络编码风格
错误:
? - 不明白李(闰年第二个指标)领域的NTP包
? - 不与adjtimex(2)状态值
? - 无法查询多个服务器
? - 仅限IPv4
? - 需要Linux风格的选择()的语义,超时值被修改
? - 总是返回成功(0)
遵守RFC-4330第10章,最佳做法:
?1。强制执行,除非有人动手脚的源代码
?2。没有退避,但不重;这不是TCP
?3。不在范围之内的上游源
?4。不在范围之内的上游源
?5。不在范围之内的上游源
?6。支持
?7。不支持
?8。不支持(吓人的机会到DOS的_client_),
原文:
ntpclient is an NTP (RFC-1305, RFC-4330) client for unix-alike computers.
Its functionality is a small subset of xntpd, but IMHO performs
better (or at least has the potential to function better) within
that limited scope.  Since it is much smaller than xntpd, it is
also more relevant for embedded computers.
ntpclient is Copyright 1997, 1999, 2000, 2003, 2006, 2007 Larry Doolittle,
and may be freely copied and modified according to the terms of the GNU
General Public License, version 2.  If you want to distribute ntpclient
under other terms, contact me.  I might agree to some other arrangement,
if you talk to me _before_ you start violating GPL terms.
ntpclient home page: http://doolittle.icarus.com/ntpclient/
Joachim Nilsson created a fork of ntpclient that he maintains at
http://vmlinux.org/jocke/ntpclient.shtml.  We don't have the same
maintainance and build system sensibilities; some people may prefer his.
In particular, he has converted his ntpclient to daemon and syslog.
The basic functionality of the two versions should be identical.
To build on Linux, type "make".  Solaris and other Unix users will
probably need to adjust the Makefile slightly.  It's not complex.
For changing the system clock frequency, only the Linux adjtimex(2)
interface is implemented at this time.  Non-Linux systems can only
use ntpclient to measure time differences and set the system clock,
by way of the POSIX 1003.1-2001 standard routines clock_gettime() and
clock_settime().  Also see "Bugs", below.
There are a few compile-time configurations possible, which require
editing the Makefile.  Either do or don't define
  ENABLE_DEBUG
  ENABLE_REPLAY
  USE_OBSOLETE_GETTIMEOFDAY
  PRECISION_SIOCGSTAMP
Try it first without changing the default: that will give you a full-
featured ntpclient, that uses modern POSIX time functions, and works
reasonably with any Linux kernel.  There are comments in ntpclient.c
that you should read before experimenting with PRECISION_SIOCGSTAMP.
Some older but otherwise (almost) serviceable Linux systems (e.g., Red Hat
EL-3.0 and Ubuntu 4.10) have a totally broken POSIX clock_settime()
implementation.  If you get "clock_settime: Invalid argument" when you
run ntpclient -s, rebuild with -DUSE_OBSOLETE_GETTIMEOFDAY.  Linux systems
that are even older won't even compile without that switch set.
Usage: ntpclient [options]
options:
-c count     stop after count time measurements (default 0 means go forever)
-d           print diagnostics (feature can be disabled at compile time)
-g goodness  causes ntpclient to stop after getting a result more accurate
                   than goodness (microseconds, default 0 means go forever)
-h hostname  (mandatory) NTP server, against which to measure system time
-i interval  check time every interval seconds (default 600)
-l           attempt to lock local clock to server using adjtimex(2)
-p port      local NTP client UDP port (default 0 means "any available")
-q min_delay minimum packet delay for transaction (default 800 microseconds)
-r           replay analysis code based on stdin
-s           simple clock set (implies -c 1)
-t           trust network and server, no RFC-4330 recommended cross-checks
Mortal users can use this program for monitoring, but not clock setting
(with the -s or -l switches).  The -l switch is designed to be robust
in any network environment, but has seen the most extensive testing in
a low latency (less than 2 ms) Ethernet environment.  Users in other
environments should study ntpclient's behavior, and be prepared to adjust
internal tuning parameters.  A long description of how and why to use
ntpclient is in the HOWTO file.  ntpclient always sends packets to the
server's UDP port 123.
One commonly needed tuning parameter for lock mode is min_delay, the
shortest possible round-trip transaction time.  This can be set with the
command line -q switch.  The historical default of 800 microseconds was
good for local Ethernet hardware a few years ago.  If it is set too high,
you will get a lot of "inconsistent" lines in the log file when time locking
(-l switch).  The only true future-proof value is 0, but that will cause the
local time to wander more than it should.  I use 200 on my workstation.
The test.dat file has 200 lines of sample output.  Its first few lines,
with the output column headers that are shown when the -d option is
chosen, are:
day   second     elapsed    stall     skew  dispersion  freq
36765 00180.386    1398.0     40.3  953773.9    793.5  -1240000
36765 00780.382    1358.0     41.3  954329.0    915.5  -1240000
36765 01380.381    1439.0     56.0  954871.3    915.5  -1240000
day, second: time of measurement, UTC, relative to NTP epoch (Jan 1, 1900)
elapsed:     total time from query to response (microseconds)
stall: time the server reports that it sat on the request (microseconds)
skew:        difference between local time and server time (microseconds)
dispersion:  reported by server, see RFC-1305 (microseconds)
freq:        local clock frequency adjustment (Linux only, ppm*65536)
A relatively new feature is a series of sanity checks on
UDP packets received, generally as recommended by RFC-4330.  If it
fails one of these tests, the line described above is replaced by
36765 01380.381  rejected packet
or, if ENABLE_DEBUG was selected at compile time, one of
36765 01380.381  rejected packet: LI==3
36765 01380.381  rejected packet: VN<3
36765 01380.381  rejected packet: MODE!=3
36765 01380.381  rejected packet: ORG!=sent
36765 01380.381  rejected packet: XMT==0
36765 01380.381  rejected packet: abs(DELAY)>65536
36765 01380.381  rejected packet: abs(DISP)>65536
36765 01380.381  rejected packet: STRATUM==0
To see the actual values of the rejected packet, start ntpclient with the
-d option; this will give a human-readable printout of every packet received,
including the rejected ones.  To skip these checks, use the -t switch.
test.dat is suitable for piping into ntpclient -r.  I have over 200000
samples (lines) archived for study, that I don't include here.
They are generally spaced 10 minutes apart, representing over three
years of data logging (from a variety of machines, and not continuous,
unfortunately).
As a special, added bonus, I also include my adjtimex(1) program.
See its man page and the HOWTO file for more information.
envelope is a perl script that I have used for my lock studies.
It's kind of a hack and not worth documenting here.
Changes since the widely distributed ntpclient_2000_345 version:
-- new -g option (has had limited testing)
-- changed max frequency adjustment from 91 ppm to 150 ppm
-- fixed "inconsistent" bug in phaselock.c triggered by large freq errors
-- new files: HOWTO, adjtimex.c, adjtimex.1, rate.awk, log2date.pl
-- minor source code cleanups
-- source is now as 64-bit clean as practical; tested on Alpha
-- optional patches provided by Andy Warner, see andyw.patch
-- optional patches provided by Linksys, see linksys.patch
-- removed unreasonable 15020 day offset in date column (xntpd has this
      offset, which turns days-since-1900-epoch into Modified Julian Day)
Changes since the widely distributed ntpclient_2003_194 version:
-- default build is now -std=c99, but c89 sill works too
-- switch default compile from gettimeofday() to POSIX clock_gettime()
-- more sanity checking on the NTP reply packet, reference RFC-4330
-- fractional second printing in debug output changed to traditional decimal
-- new -f switch to set initial frequency
-- works to specify both -s and -l, will jump-set first and then phase lock
-- bug fix for select() error handling, thanks to Walter Harms
-- new man page, contributed by Walter Harms
-- most subroutines are now flagged static to the compiler
-- structural changes to the code, such as the new ntpclient.h file
-- dropped (mostly) obsolete patches from Linksys and Andy Warner
Changes since ntpclient_2006_318:
-- adjustable min_delay parameter, used to be hard-coded 800 microseconds
-- remove useless listen() call, thanks to Alexander Indenbaum
-- fix length passed to recvfrom(), thanks to Alexander Indenbaum
-- tidy up 32-bit integer declarations, prodding from Brian McAllister
-- added rate2.awk, contributed by Lou Sortman
-- provide easy way to override 15 second MIN_INTERVAL at compile time
-- relax MIN_INTERVAL enforcement for one-shot use, thanks to Mihai Buha
Changes since ntpclient_2007_365:
-- fixed type of sa_xmit_len, thanks vapier
-- dropped underscores in spelling of adjtimex(2), might make uClibc happier
-- include netdb.h and always define _BSD_SOURCE to get prototype for herror
-- minor formatting to align with Nilsson's fork
-- add -fno-strict-aliasing as needed by traditional network coding style
Bugs:
-- Doesn't understand the LI (Leap second Indicator) field of an NTP packet
-- Doesn't interact with adjtimex(2) status value
-- Can't query multiple servers
-- IPv4 only
-- Requires Linux-style select() semantics, where timeout value is modified
-- Always returns success (0)
Adherence to RFC-4330 chapter 10, Best practices:
1.  enforced, unless someone tinkers with the source code
2.  no backoff, but no retry either; this isn't TCP
3.  not in scope for the upstream source
4.  not in scope for the upstream source
5.  not in scope for the upstream source
6.  supported
7.  not supported
8.  not supported (scary opportunity to DOS the _client_)
       - Larry Doolittle 

你可能感兴趣的:(linux系统)