Chrony时间同步服务使用说明

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

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

   chronyCentOS7.x上自带的时间同步软件

1.1.2 chrony的操作

# yum install -y chrony -->安装服务 # systemctl start chronyd.service -->启动服务 # systemctl enable chronyd.service -->设置开机自启动,默认是enable的

1.1.3 chrony配置文件

chrony服务使用的配置文件为/etc/chrony.conf

其配置内容格式和ntpd服务基本相似

[root@openvpn ~]# cat /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (). 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 # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # 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 # 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

 

1.1.4 配置参数说明

参数

 

参数说明

 

server

 

该参数可以多次用于添加时钟服务器,必须以"server "格式使用。一般而言,你想添加多少服务器,就可以添加多少服务器

 

stratumweight

 

stratumweight指令设置当chronyd从可用源中选择同步源时,每个层应该添加多少距离到同步距离。默认情况下,CentOS中设置为0,让chronyd在选择源时忽略源的层级

 

driftfile

 

chronyd程序的主要行为之一,就是根据实际时间计算出计算机增减时间的比率,将它记录到一个文件中是最合理的,它会在重启后为系统时钟作出补偿,甚至可能的话,会从时钟服务器获得较好的估值

 

rtcsync

 

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

 

allow/deny

 

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

 

cmdallow/cmddeny

 

跟上面相类似,只是你可以指定哪个IP地址或哪台主机可以通过chronyd使用控制命令

 

bindcmdaddress

 

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

 

makestep

 

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

 
检查ntp源服务器状态1.1.5 查看同步状态

 

[root@openvpn ~]# chronyc sourcestats 210 Number of sources = 4 Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev ============================================================================== 61-216-153-105.HINET-IP.> 0 0 0 +0.000 2000.000 +0ns 4000ms dns1.synet.edu.cn 18 9 62m +0.312 1.706 +7548ns 1920us ntp2.itcompliance.dk 0 0 0 +0.000 2000.000 +0ns 4000ms mx.comglobalit.com 22 11 270m +0.660 0.184 +37ms 987us

查看ntp详细的同步状态

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13211.html