zoukankan      html  css  js  c++  java
  • linux-ntp-10

    Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com
    windows类: time.pool.aliyun.com

    s1a.time.edu.cn 北京邮电大学
    s1b.time.edu.cn 清华大学
    s1c.time.edu.cn 北京大学
    国家授时中心服务器210.72.145.44

    服务端 ntp
    ignore: #关闭所有的NTP联机服务(基本不用);
    nomodify: #客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时;
    notrap: #拒绝特殊的ntpdq捕获消息
    notrust: #客户端除非通过认证,否则该客户端来源将被视为不信任子网
    noquery: #不提供客户端的时间查询

    本例中允许接收同步请求的地址范围是192.168.30.0/24

    例如 :
    restrict192.168.30.0 mask 255.255.255.0 nomodify notrap
    restrict 192.168.100.0 mask 255.255.255.0 nomodify #该网段可以进行校时
    restrict 59.124.196.84 #允许该NTP服务器进入

    注意:如果参数没有设定,那就表示该IP(或子网)没有任何限制

    或者restrict default kod nomodify

    配置上游NTP服务器之前,先检查上游服务器是否能正常连通。若可以使用,修改NTP配置文件如下:
    server 210.72.145.44 #China Time Center
    server cn.pool.ntp.org #Pulbic Time Server
    server 202.112.10.36
    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10
    server time-nw.nist.gov prefer //prefer 该服务器优先

    如果第二步配置的server 210.72.145.44、cn.pool.ntp.org都无效时,

    则NTP服务器会根据这里的配置,把自己的时间做为NTP服务器的时间,即和自己同步。

    如果要使用本地时间,将server 网络服务注释,添加两行

    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10

    备注:fudge这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0

    systemctl start ntpd

    ntpstat

    ntpq -p

    st:即stratum阶层,值越小表示ntp serve的精准度越高;
    when:几秒前曾做过时间同步更新的操作;
    Poll表示,每隔多少毫秒与ntp server同步一次;
    reach:已经向上层NTP服务器要求更新的次数;
    delay:网络传输过程钟延迟的时间;
    offset:时间补偿的结果;
    jitter:Linux系统时间与BIOS硬件时间的差异时间

    ntpdate ntp.aliyun.com
    [ ! $(rpm -q ntp) ] && yum -y install ntp
    sed -ri.bk 's/(restrict default nomodify.)/restrict default kod nomodify/;s/^(server.)/#&/' /etc/ntp.conf

    echo -e "server ntp.aliyun.com server ntp1.aliyun.com" >> /etc/ntp.conf

    systemctl start ntpd.service
    systemctl enable ntpd.service

    客户端配置 ntpdate

    30 * * * * root /usr/sbin/ntpdate 192.168.100.100; /sbin/hwclock -w

    同步硬件时钟 
      NTP一般只会同步system clock. 如果我们也要同步RTC(hwclock)
    vi /etc/sysconfig/ntpd SYNC_HWCLOCK=yes

    hostname -I

    服务器端
    yum -y install chrony

    主配置文件:/etc/chrony.conf
    客户端程序:/usr/bin/chronyc
    服务端程序:/usr/sbin/chronyd

    vim /etc/chrony.conf
    server cn.pool.ntp.org iburst
    server tw.pool.ntp.org iburst

    允许指定网络的主机同步时间,不指定就是允许所有,默认不开启。

    allow 192.168.43.0/24
    # 还有一个默认不开启的选项,意思是,即使服务端没有同步到精确的网络时间,也允许向客户端同步不精确的时间。可以视情况而定。
    # Serve time even if not synchronized to any NTP server.
    #local stratum 10
    

    systemctl start chronyd.service

    客户端

    vim chrony.conf
    server 内网时间服务器主机IP iburst
    systemctl start chronyd
    enable

    使用chronyc
    查看现有的时间服务器
    chronyc> sources
    查看时间服务器状态
    chronyc> sourcestats

    chrony兼容ntpdate,客户端可以使用ntpdate手动同步时间
    ntpdate  内网时间服务器IP
    

    配置 /etc/ntp.conf 选项

    系统时间与BIOS事件的偏差记录

    driftfile /etc/ntp/drift

    restrict 控制相关权限。
    语法为: restrict IP地址 mask 子网掩码 参数
    其中IP地址也可以是default ,default 就是指所有的IP
    参数有以下几个:
    ignore  :关闭所有的 NTP 联机服务
    nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
    notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
    noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
    notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
    nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
    kod : 访问违规时发送 KoD 包。
    restrict -6 表示IPV6地址的权限设置。

    restrict default nomodifynotrapnoquery # 关闭所有的 NTP 要求封包

    上层主机设定
    server [IP|HOST Name] [prefer]
    prefer表示优先主机
    与 Time Server 沟通时所花费的时间,记录在driftfile  后面接的文件内
    restrict用来设置访问权限,server用来设置上层时间服务器,driftfile用来设置保存漂移时间的文件

    启动服务 systemctl start ntpd
    查看是否同步 ntpstat 会有时间延迟,可稍等会再试
    ntpq -p ntp 与上层服务器的关系

    ntpq -p
    remote refid st t when poll reach delay offset jitter

    *139.199.215.251 100.122.36.4 2 u 56 64 7 39.877 14.137 4.521
    +ntp04.rserver.e 85.199.214.102 2 u 57 64 5 250.114 43.419 3.252
    biisoni.miuku.n .INIT. 16 u - 64 0 0.000 0.000 0.000
    +ntp-fi01.rserve 129.242.4.241 2 u 53 64 7 336.771 27.274 7.773

    含义:
    remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
    refid:参考的上一层NTP主机的地址
    st:即stratum阶层 越小越精确
    when:几秒前曾做过时间同步更新的操作
    poll:下次更新在几秒之后
    reach:已经向上层NTP服务器要求更新的次数
    delay:网络传输过程钟延迟的时间
    offset:时间补偿的结果
    jitter:Linux系统时间与BIOS硬件时间的差异时间

    如需同时同步硬件时间,需设置/etc/sysconfig/ntpd文件,添加 SYNC_HWCLOCK=yes

    配置:
    设置默认策略允许任何主机同步
    restrict default ignore
    保留设置(对本机的)
    restrict 127.0.0.1
    restrict -6 ::1
    修改/etc/ntp/stpe-tickers文件,当ntpd服务启动时,会自动与该文件中记录的上层NTP服务进行时间校对

    iptables iptables -I INPUT -p udp --dport 123 -j ACCEPT

    ntpdate调整时间的方式”跃变“:在获得一个时间之后,ntpdate使用settimeofday(2)设置系统时间,尽量使用ntpd,如果时间偏移太大,ntpd同步不会成功,可手动同步

    则NTP服务器会根据这里的配置,把自己的时间做为NTP服务器的时间,即和自己同步。

    如果要使用本地时间,将server 网络服务注释,添加两行

    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10

    备注:fudge这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0

  • 相关阅读:
    一道面试题:按照其描述要求用java语言实现快速排序
    Tomcat容器运行struts2+spring+mybatis架构的java web应用程序简单分析
    关于oracle存储过程的一些知识点
    多动手试试,其实List类型的变量在页面上取到的值可以直接赋值给一个js的Array数组变量
    Chapter 5: Container
    统计文件夹下java代码行数的小程序--主要是学习任务队列的思想
    利用strut2标签自动生成form前端验证代码
    简单实现web单点登录
    Chapter 4: Tomcat Default Connector
    [python] 格式化方法 format
  • 原文地址:https://www.cnblogs.com/g2thend/p/11621149.html
Copyright © 2011-2022 走看看