001.Chrony时间服务器

时间:2022-12-18 14:50:56

一 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 安装

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

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

2.2 服务节点chrony配置

 [root@ntpserver ~]# vi /etc/chrony.conf

 server ntp1.aliyun.com iburst

 server ntp2.aliyun.com iburst

 server ntp3.aliyun.com iburst #采用阿里云时钟源

 allow 172.24.8.0/24 #允许客户端所在网段

 bindcmdaddress 127.0.0.1

 bindcmdaddress ::1

 local stratum 10 #设置源时钟等级
 

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

2.3 服务节点启动验证

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

001.Chrony时间服务器

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

001.Chrony时间服务器

2.4 客户端节点chrony配置

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

附录1 配置文件详解

/etc/chrony.conf

 # 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 "格式使用。

 # Record the rate at which the system clock gains/losses time.

 driftfile /var/lib/chrony/drift

 # 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

 # 通常,chronyd将根据需求通过减慢或加速时钟,使得系统逐步纠正所有时间偏差。在某些特定情况下,系统时钟可能会漂移过快,导致该调整过程消耗很长的时间来纠正系统时钟。该指令强制chronyd在调整期大于某个阀值时步进调整系统时钟,但只有在因为chronyd启动时间超过指定限制(可使用负值来禁用限制),没有更多时钟更新时才生效。

 # Enable kernel synchronization of the real-time clock (RTC).

 rtcsync

 # rtcsync指令将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。

 # 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

 #deny 192.168/16

 # 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器。

 # Listen for commands only on localhost.

 bindcmdaddress 127.0.0.1

 bindcmdaddress ::1

 # 该指令允许你限制chronyd监听哪个网络接口的命令包(由chronyc执行)。该指令通过cmddeny机制提供了一个除上述限制以外可用的额外的访问控制等级。

 # Serve time even if not synchronized to a time source.

 #local stratum 10

 # 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
 

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

xhy 标记: chrony