zoukankan      html  css  js  c++  java
  • ntp客户端

    ntp在linux中的用法

    我们主要介绍ntp client端

    1、在client端,首先配置ntpd.conf文件,添加server ip(时间服务提供商的ip或者主机名),可以指定多个

    启动ntpd服务:/etc/init.d/ntpd start

    此时ntp服务启动,通过udp的123端口与server端通信,开始时间同步

    2、client和server的时间同步有两种情况:时间跳变(time step)和渐变(time slew)

    跳变是指在client和server间时间差过大时(默认128ms),瞬间调整client端的系统时间。

    渐变是指时间差较小时,通过改变client端的时钟频率,进而改变client端中“1秒”的“真实时间”,保持client端时间连续性。

    举个例子,如果client端比server端慢10s,通过ntpd,client端的中每1秒现实时间是1.0005秒!虽然client端的时间仍然是1秒1秒增加的,通过调整每秒的实际时间,直到与serrver的时间相同。在这个例子中,10s/0.0005s=20000s,20000s/60/60=5.55555小时,即需要5个多小时才能消除10s的误差。

    在linux中,很多应用软件依赖系统的时间连续性来正确工作,系统时间的跳变将导致软件出现意想不到的问题,所以时间渐变才是ntpd的主要应用场景。

    3、那么怎么禁止ntpd的时间跳变,只采用时间渐变呢?

    刚开始通过man ntpd,尝试在ntpd启动配置(/etc/sysconfig/ntpd)中加-x选项:

    -x

    Normally, the time is slewed if the offset is less than the step threshold, which is 128 ms by default, and stepped if above the threshold. This option forces the time to be slewed in all cases. If the step threshold is set to zero, all offsets are stepped, regardless of value and regardless of the -x option. In general, this is not a good idea, as it bypasses the clock state machine which is designed to cope with large time and frequency errors Note: Since the slew rate is limited to 0.5 ms/s, each second of adjustment requires an amortization interval of 2000 s. Thus, an adjustment of many seconds can take hours or days to amortize. This option can be used with the -q option.

    结果发现-x只是提高了时间跳变的阈值,在client与server时间差小于600秒时,时间的调整使用渐变,大于600秒,时间调整使用跳变形式。

    查了很多资料,最后确定在ntp配置文件/etc/ntp.conf中添加字段:

    tinker panic 600


    这句话的意思是在时间差大于600秒的情况下,ntpd进程自动关闭,ntpd退出时会向/var/log/messages中写入log

    在时间差过大时,应该由用户手动设置系统时间或者调用ntpdate命令,这样能避免因为时间跳变出现的问题。

    总结:

    渐变的话,在偏差600s以内系统会很慢(slew)的方式追赶,超过600s后系统系统会跳跃式调整(step),这样不安全,所以要在/etc/ntp.conf中添加tinker panic 600(默认tpanic threshold值是是1000s,让偏差在超过600s后ntpd进程自动关闭)

     

    Offset(与服务器的时间差)

    0-128ms

    128ms-600s

    600s-1000s

    1000s以上

    使用-X参数(slew mode)

    微调

    微调(速度大约是0.5ms/s,调整600秒要14天左右)

    跳跃

    退出(加-g参数可忽略)

    不使用-X参数(step mode)

    微调

    跳跃

    跳跃

    退出(加-g参数可忽略)

    参考http://blog.csdn.net/judwenwen2009/article/details/51661239

     

     

  • 相关阅读:
    在.wxml文件中使用方法
    Element日期区间选择器限制选择范围
    规定段落中的文本不进行换行
    文件大小换算
    elementUI的message消息提示改成只能同时存在一个
    SQL 执行顺序
    SQL Left join
    wpf datagrid 行双击事件
    关于Infragistics.WebUI.UltraWebGrid的使用
    ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
  • 原文地址:https://www.cnblogs.com/dotagg/p/6363134.html
Copyright © 2011-2022 走看看