zoukankan      html  css  js  c++  java
  • 001.Chrony时间服务器

    一 Chrony概览

    1.1 Chrony简介

    Chrony是一个开源的自由软件,是网络世界协议(NTP)的另一种实现,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。

    它由两个程序组成:chronyd和chronyc。

    chronyd:一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。

    chronyc提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作。

    1.2 Chrony优点

    • 更快的同步只需要数分钟而非数小时世界,从而最大程度减少了时间和频率误差;
    • 能够更好的响应时钟频率的快速变化,对于具备不稳定时钟的虚拟机或导致时钟频繁发生变化的节能结束非常有用;
    • 在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响;
    • 在应对临时非对称延时时提供了更好的稳定性;
    • 无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟。

    二 Chrony安装与配置

    2.1 架构及准备

    节点主机
    IP
    主机名
    NTP-Server
    172.24.8.30/24
    ntpserver
    NTP-Client
    172.24.8.31/24
    ntpclient

    主机名修改:略。

    2.1 安装

      1 [root@ntpserver ~]# yum install -y chrony

    注意:client节点同样需要安装。

    2.2 服务节点chrony配置

      1 [root@ntpserver ~]# vi /etc/chrony.conf
      2 
      3 server ntp1.aliyun.com iburst
      4 
      5 server ntp2.aliyun.com iburst
      6 
      7 server ntp3.aliyun.com iburst #采用阿里云时钟源
      8 
      9 allow 172.24.8.0/24 #允许客户端所在网段
     10 
     11 bindcmdaddress 127.0.0.1
     12 
     13 bindcmdaddress ::1
     14 
     15 local stratum 10 #设置源时钟等级
     16 

    注意:以上给出关键部分配置,其他部分采用默认即可,具体配置参数见附录1。

    2.3 服务节点启动验证

      1 [root@ntpserver ~]# systemctl start chronyd.service
      2 [root@ntpserver ~]# systemctl enable chronyd.service
      3 [root@ntpserver ~]# systemctl status chronyd.service

    01

      1 [root@ntpserver ~]# chronyc sources -v		#查看同步情况

    02

    2.4 客户端节点chrony配置

      1 [root@ntpclient ~]# vi /etc/chrony.conf
      2 server ntpserver iburst			#指定同步源为ntpserver

    附录1 配置文件详解

    /etc/chrony.conf

      1 # Use public servers from the pool.ntp.org project.
      2 
      3 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
      4 
      5 server 0.centos.pool.ntp.org iburst
      6 
      7 server 1.centos.pool.ntp.org iburst
      8 
      9 server 2.centos.pool.ntp.org iburst
     10 
     11 server 3.centos.pool.ntp.org iburst
     12 
     13 # 该参数可多次用于添加时钟服务器,必须以"server "格式使用。
     14 
     15 # Record the rate at which the system clock gains/losses time.
     16 
     17 driftfile /var/lib/chrony/drift
     18 
     19 # chronyd程序的主要行为之一,就是根据实际时间计算出计算机增减时间的比率,将它记录到一个文件中是最合理的,它会在重启后为系统时钟作出补偿,甚至可能的话,会从时钟服务器获得较好的估值。
     20 
     21 # Allow the system clock to be stepped in the first three updates
     22 
     23 # if its offset is larger than 1 second.
     24 
     25 makestep 1.0 3
     26 
     27 # 通常,chronyd将根据需求通过减慢或加速时钟,使得系统逐步纠正所有时间偏差。在某些特定情况下,系统时钟可能会漂移过快,导致该调整过程消耗很长的时间来纠正系统时钟。该指令强制chronyd在调整期大于某个阀值时步进调整系统时钟,但只有在因为chronyd启动时间超过指定限制(可使用负值来禁用限制),没有更多时钟更新时才生效。
     28 
     29 # Enable kernel synchronization of the real-time clock (RTC).
     30 
     31 rtcsync
     32 
     33 # rtcsync指令将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。
     34 
     35 # Enable hardware timestamping on all interfaces that support it.
     36 
     37 #hwtimestamp *
     38 
     39 # Increase the minimum number of selectable sources required to adjust
     40 
     41 # the system clock.
     42 
     43 #minsources 2
     44 
     45 # Allow NTP client access from local network.
     46 
     47 #allow 192.168.0.0/16
     48 
     49 #deny 192.168/16
     50 
     51 # 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器。
     52 
     53 # Listen for commands only on localhost.
     54 
     55 bindcmdaddress 127.0.0.1
     56 
     57 bindcmdaddress ::1
     58 
     59 # 该指令允许你限制chronyd监听哪个网络接口的命令包(由chronyc执行)。该指令通过cmddeny机制提供了一个除上述限制以外可用的额外的访问控制等级。
     60 
     61 # Serve time even if not synchronized to a time source.
     62 
     63 #local stratum 10
     64 
     65 # Specify file containing keys for NTP authentication.
     66 
     67 #keyfile /etc/chrony.keys
     68 
     69 # Specify directory for log files.
     70 
     71 logdir /var/log/chrony
     72 
     73 # Select which information is logged.
     74 
     75 #log measurements statistics tracking
     76 

    参考:https://www.cnblogs.com/Csir/p/6912527.html

    xhy 标记:
  • 相关阅读:
    在vue中使用 layui框架中的form.render()无效解决办法
    Week03面向对象入门
    Week04面向对象设计与继承
    JAVA暑假作业
    Week02Java基本语法与类库
    201621123082《Java程序设计》第1周学习总结
    利用Asp.net中的AJAX制作网页上自动选取开始日期及结束日期的用户自定义控件
    错误 1 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的
    Log4net日志记录、详细配置(自己使用)
    利用队列记录错误日志
  • 原文地址:https://www.cnblogs.com/itzgr/p/9888469.html
Copyright © 2011-2022 走看看