zoukankan      html  css  js  c++  java
  • centos linux ntp.conf 配置中 fudge 参数找不到

    最近服务器被迫关机了一次,突然想把时间同步服务搞一搞 (内网 环境,无法连接互联网)

    为什么我要记录这个文章?
    因为这玩意很简单,花了我几乎一天的时间.
    总是报错,尝试修改配置,继续报错,再我几乎绝望,想吐槽 linux ntpd 垃圾的时候,它突然生效了,
    只是因为加了一个配置interface listen 10.100.2.242,也或许是因为刚好需要等待的时间到了.
    我就不明白了,为什么网上都说要等几分钟才能生效呢? 我用ntpdate -d -v $IP 来同步,为什么给我
    报错,我还不知道该怎么修改.
    活该 linux 这么难用.

    ntpd 服务器配置(10.100.2.242)

    vim ntp.conf

    # For more information about this file, see the man pages
    # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
    
    driftfile /var/lib/ntp/drift
    
    # 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  nopeer 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
    restrict ::1
    
    # Hosts on local network are less restricted.
    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    restrict 10.100.2.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.centos.pool.ntp.org iburst
    #server 1.centos.pool.ntp.org iburst
    #server 2.centos.pool.ntp.org iburst
    #server 3.centos.pool.ntp.org iburst
    server 127.127.1.1 burst true prefer
    #fudge 127.127.1.1 stratum 8
    interface listen 10.100.2.242
    #... 省略后面的了
    

    关键的地方在于:

    针对指定局域网网段是生效
    restrict 10.100.2.0 mask 255.255.255.0 nomodify notrap
    设置服务器自己作为单独的一个ntpd 服务器来提供服务
    server 127.127.1.1 burst true prefer
    再上述配置增加后,还不生效,神奇的,我找到了下面的几乎无人提及配置,貌似生效了
    interface listen 10.100.2.242
    这个在man手册都没看到,怎么了?
    fudge 127.127.1.1 stratum 0

    fudge参数貌似不生效

    ntpd --version
    ntpd 4.2.6p5
    

    根据 ntp.org 的记录,最新版本是4.2.8pX 系列, 这应该是版本问题了;

    ntp 客户端配置 (10.100.2.243-249) 全部使用10.100.2.242的时间配置

    客户端就简单了,当测试ok,我就批量操作了:

    yum install ntpd -y
    sed -i 's/^server/#server/g' /etc/ntp.conf 
    line=`grep "#server" /etc/ntp.conf -n|tail -n 1|cut -d ':' -f 1`
    if test -z "$line";then echo "not found server ";return;fi
    sed -i -e "$line a server 10.100.2.242 prefer iburst" /etc/ntp.conf 
    systemctl enable ntpd||chkconfig --level 345 ntpd on
    systemctl restart ntpd||service ntpd restart
    ntpstat ; ntpq -p; ntpdate -d
    date
    ntpdate -v -d 10.100.2.242
    date
    

    终于生效了,开启各种ntpd服务,最好不要用crontab来写ntpdate的定时命令,ntpdate只适合手动运行.

    后来又查了一下,原来windows的w32time服务也是支持ntpd的, 既可以配置为ntpd server,也可以作为ntp client
    链接ntpd server(不管是win还是linux的,通通支持),最关键的,配置很简单,使用很简单.

    所以 linux 真好用.

    REF: http://doc.ntp.org/
    ntp.conf:很少有人提及的事
    ntp的interface listen配置,绑定监听

  • 相关阅读:
    通过HttpListener实现简单的Http服务
    WCF心跳判断服务端及客户端是否掉线并实现重连接
    NHibernate初学六之关联多对多关系
    NHibernate初学五之关联一对多关系
    EXTJS 4.2 资料 跨域的问题
    EXTJS 4.2 资料 控件之Grid 那些事
    EXTJS 3.0 资料 控件之 GridPanel属性与方法大全
    EXTJS 3.0 资料 控件之 Toolbar 两行的用法
    EXTJS 3.0 资料 控件之 combo 用法
    EXTJS 4.2 资料 控件之 Store 用法
  • 原文地址:https://www.cnblogs.com/ayanmw/p/12872495.html
Copyright © 2011-2022 走看看