LinuxTOY 是一个致力于提供 Linux 相关资讯的专题站点。如果您发现了好用好玩的 Linux 东东并愿意发扬自由、分享的精神,可以点击顶部导航 Contact 按钮进行投稿。

Recommended books

Popular entries

OpenNTPD 的误差……

{ 撰文/shadow }

我一直认为 OpenNTPD 能使我电脑的时间保持准确,但我直到昨天才发现电脑的时间跟实际的有两分钟左右的误差,不太准确……

我刚才查出了原因——只有当 OpenNTPD 发现系统时间与 NTP 服务器所提供的时间相差超过 180 秒时才会校正时间。

奇怪的是,该软件并没有提供修改这 180 秒的误差范围的方法……

显然,这 180 秒的范围实在太大了,远不能满足我的要求(误差 1 秒内)。

于是,我想到了个不是办法的办法,就是先把系统时间弄得很离谱,然后再让 OpenNTPD 来同步时间……

具体命令如下(Arch 下):

(sudo) date -s 00:00:00 (先随便设个时间)
(sudo) ntpd -s (同步)
(sudo) hwclock -w (把系统时间写进硬件)

……不知大家能否提供更好的解决方案?

{ Source. Thanks shadow. }

Read More:

  • No related posts

13 Comments

  1. 1 tangyl Commented @ 2010-01-02 12:54Reply to this comment

    误差小的时候,ntpd不会直接修改系统时间的,只是对时钟频率进行校正。这种方式好处是系统时间不会有跳变,不会影响像crontab这样程序的运行,缺点是校正需要一定的时间。一般在ntpd运行前会先用ntpdate同步,可以代替上面几步。

  2. 2 Jungle Commented @ 2010-01-02 13:08Reply to this comment

    用原子钟吧。。

  3. 3 adam8157 Commented @ 2010-01-02 13:20Reply to this comment

    alias ntp='sudo ntpdate pool.ntp.org && sudo hwclock --systohc'

  4. 4 HolmesConan Commented @ 2010-01-02 14:19Reply to this comment

    不是开源的吗?checkout然后自己改一下哈。

  5. 5 flydragon Commented @ 2010-01-02 14:25Reply to this comment

    我也是只用archlinux的... 要对时只要一个命令:

    sudo ntpd -qg

    我碰到过的问题刚好相反, 误差超过1000秒它不对时了, -g 就是防这个的. 可是低于180秒就是0.5秒它也纠正啊...

    楼主是不是哪里搞错了?

  6. 6 ihipop Commented @ 2010-01-02 14:39Reply to this comment

    楼主看看是否是你设置的问题,我管理的centos就是用cron设置为ntp对时的,每次对时完有个offset值,这个值会随着连续运行次数而减小,越小表示误差越小,所以我都是用cron设置为每天连续对时三遍的,这样可以保持一个非常小的offset值!

  7. 7 shadow Commented @ 2010-01-02 15:02Reply to this comment

    我之前说的是openntpd,不是ntp,估计不一样的,发现改用后者后该问题解决了…… 我使用前者的原因是它设置比较简单(几乎不用设置),而后者的设置好像比较复杂(相对而言),不过我刚才才知道如果只需校时的话,后者也不需要设置的(archwiki那里说得很复杂)。 谢谢大家!

  8. 8 qiang_liu8183 Commented @ 2010-01-02 18:41Reply to this comment

    中国国家授时中心 210.72.145.44

  9. 9 kerojiang Commented @ 2010-01-02 22:50Reply to this comment

    openntpd在我电脑上无法对时,连接对时服务器的时候总是失败 用ntpd就没问题了

  10. 10 walkerxk Commented @ 2010-01-02 23:35Reply to this comment

    我的ntp也是误差超过多少时间就不调正了,时间差小的话,肯定调正的。

  11. 11 Steven Commented @ 2010-01-04 11:05Reply to this comment

    openNTPD校准的时间是上海(东经121度29分)还是北京时间(东经120度)?

  12. 12 adam8157 Commented @ 2010-01-05 19:10Reply to this comment

    @Steven: 算是北京吧, 东八区

  13. 13 majia321 Commented @ 2010-03-08 10:45Reply to this comment

    ntpdate - no server suitable for synchronization found ! 用 AUR/rdate 设置时间和时间服务器同步:

    rdate -s time-b.nist.gov

    http://tf.nist.gov/tf-cgi/servers.cgi