zoukankan      html  css  js  c++  java
  • chrony时间同步服务

    1. NTP时间同步协议

    1.1 NTP协议简介

    • NTP(Network Time Protocol,网络时间协议)
    • NTP是用来使网络中的各个计算机时间同步的一种协议
    • 可以使用nepdate命令来向服务同步时间
      ntpdate 10.0.0.201

    1.2 ntpd和chrony实现时间同步的方式

    • ntpd实现时间同步的思路:把时间的周期缩短,也就是让秒针转动的速度变快,以追上时间服务器的时间。
    • chrony实现时间同步的思路:也是让时间周期缩短,但是它相比于ntpd,它是直接转动时针,所以能更快的将时间同步。

    2. chrony服务

    2.1 chrony服务简介

    • chrony is a versatile implementation of the Network Time Protocol (NTP).
    • It can synchronize the system clock with NTP servers, reference clocks (e.g. GPS receiver), and manual input using wristwatch and keyboard.
    • It can also operate as an NTPv4 (RFC 5905) server and peer to provide a time service to other computers in the network.

    2.2 程序环境

    1)安装

    • 直接 yum  install  chrony 即可

    2)监听的端口

    • 123/udp:兼容ntp服务监听在udp的123端口上
    • 323/udp:chrony服务本身监听在udp的323端口上

    3)程序结构

    • 配置文件:/etc/chrony.conf 
    • 主程序文件:chronyd
    • unit file:chronyd.service

    4)工具程序

    • chronyc(交互式环境)
      • sources:查看连接的时间服务器
      • sourcestats:查看当前时间同步是否正常
      • tracking:校准时间服务器

    2.3 配置文件 /etc/chrony.conf

    1)配置项

    • server:指明时间服务器地址
    • allow NETADDRNETMASK
    • allow all:允许所有 客户端主机
    • deny NETADDR/NETMASK
    • deny all:拒绝所有客户端
    • bindcmdaddress:命令管理接口监听的地址
    • local stratum 10:即使自己未能通过网络时间服务器同步到时间,也允许将本地时间作为标准时间授时给其它客户端(建议关闭)
    • rtcsync:将启用一个内核模式,在该模式下,系统时间每11分钟会拷贝到实时时钟(RTC)

    2)配置示例

    ### 指明时间服务地址
    #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 10.0.0.201 iburst
    
    
    ### 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整
    # Record the rate at which the system clock gains/losses time.
    driftfile /var/lib/chrony/drift
    
    
    # chronyd根据需求减慢或加速时间调整, 
    # 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长
    # 该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟
    # 只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效
    # Allow the system clock to be stepped in the first three updates
    # if its offset is larger than 1 second.
    makestep 1.0 3
    
    
    ### 启用内核模式,系统时间每11分钟会拷贝到实时时钟(RTC)
    # Enable kernel synchronization of the real-time clock (RTC).
    rtcsync
    
    
    ### 通过使用hwtimestamp指令启用硬件时间戳
    # Enable hardware timestamping on all interfaces that support it.
    #hwtimestamp *
    
    
    # Increase the minimum number of selectable sources required to adjust
    # the system clock.
    #minsources 2
    
    
    ### 允许的所有客户端主机
    # Allow NTP client access from local network.
    #allow 192.168.0.0/16
    
    
    ### 设置当自己未能通过网路时间服务同步到时间,也允许将本地时间作为标准时间授时给其他客户端(建议关闭)
    # Serve time even if not synchronized to a time source.
    #local stratum 10
    
    
    # 指定包含NTP验证密钥的文件
    # Specify file containing keys for NTP authentication.
    #keyfile /etc/chrony.keys
    
    
    # 指定日志文件的目录
    # Specify directory for log files.
    logdir /var/log/chrony
    
    # Select which information is logged.
    #log measurements statistics tracking

    3. 思维导图

    • 参考链接:
      • https://www.cnblogs.com/lizhaoxian/p/11260041.html
      • https://www.centos.bz/2018/03/centos-7-chrony-设置服务器集群系统时间同步/

  • 相关阅读:
    Yuan先生的博客网址
    Django的认证系统 auth模块
    Django 中间件使用
    Django Form表单验证
    Django ORM介绍 和字段及字段参数
    ajax 使用
    Java报表之JFreeChart
    POI
    MyBatis
    问题解决方法
  • 原文地址:https://www.cnblogs.com/hgzero/p/13540847.html
Copyright © 2011-2022 走看看