chrony软件

时间:2019-11-13
本文章向大家介绍chrony软件,主要包括chrony软件使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

chrony简介

Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。

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

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

    chrony是CentOS7.x上自带的时间同步软件

chrony的操作

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

chrony配置文件

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

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

[root@localhost ~]# cat /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:该参数可以多次用于添加时钟服务器,必须以"server "格式使用。一般而言,你想添加多少服务器,就可以添加多少服务器
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

配置参数说明

参数          参数说明
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@localhost ~]# chronyc sourcestats
210 Number of sources = 4
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
162.159.200.1 0 0 0 +0.000 2000.000 +0ns 4000ms
ntp8.flashdance.cx 0 0 0 +0.000 2000.000 +0ns 4000ms
120.25.115.20 6 4 25m -23.121 50.893 -1565us 7650us
electabuzz.felixc.at 0 0 0 +0.000 2000.000 +0ns 4000ms

查看ntp详细的同步状态

[root@localhost ~]# chronyc sources -v
210 Number of sources = 4

.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? 162.159.200.1 0 10 0 - +0ns[ +0ns] +/- 0ns
^? ntp8.flashdance.cx 0 10 0 - +0ns[ +0ns] +/- 0ns
^* 120.25.115.20 2 8 377 118 +14ms[+5878us] +/- 32ms
^? electabuzz.felixc.at 0 10 0 - +0ns[ +0ns] +/- 0ns

chronyc命令参数说明:

参数 参数说明
accheck 检查NTP访问是否对特定主机可用
activity 该命令会显示有多少NTP源在线/离线
add server 手动添加一台新的NTP服务器。
clients  在客户端报告已访问到服务器
delete    手动移除NTP服务器或对等服务器
settime   手动设置守护进程时间
tracking  显示系统时间信息

查看日期时间、时区及NTP状态:# timedatectl1.1.6 其他时间设置相关指令

查看日期时间、时区及NTP状态:# timedatectl
查看时区列表:# timedatectl list-timezones
修改时区# timedatectl set-timezone Asia/Shanghai
修改日期时间:# timedatectl set-time "2015-01-21 11:50:00"(可以只修改其中一个)
开启NTP:# timedatectl set-ntp true/flase

1.1.7 chrony的优势

    更快的同步只需要数分钟而非数小时时间,从而最大程度减少了时间和频率误差,这对于并非全天 24 小时运行的台式计算机或系统而言非常有用。

    能够更好地响应时钟频率的快速变化,这对于具备不稳定时钟的虚拟机或导致时钟频率发生变化的节能技术而言非常有用。

    在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响。

    在应对临时非对称延迟时(例如,在大规模下载造成链接饱和时)提供了更好的稳定性。

    无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟。

chrony与ntp都是时间同步软件

  两个软件不能够同时开启,会出现时间冲突。

原文地址:https://www.cnblogs.com/liujunjun/p/11849765.html