一次Linux时间同步工具Chrony配置

来源:这里教程网 时间:2026-03-03 21:36:43 作者:

1、 chrony 介绍

https://chrony-project.org/ 常用的时间同步工具: ntpdate ntpd ntpdate ntpd 的缺点: ntpdate 通常会配合 crontab 来定时同步时间,时间会发生跳变,时间倒退,引发业务异常, RAC 集群节点重启等故障。 ntpd 时间同步慢   Chrony 优点: 1) 时间同步快, 1 小时时差最快可能在 10 分钟内同步完成 2) 时间同步平顺,不会发生跳变

2、 安装

redhat 6.8之后 光盘源中已包含 安装

yum install chrony -y

 

启动服务

systemctl start chronyd

systemctl enable chronyd

 

 

3、 配置

 

vi /etc/chrony.conf

 

# 使用 pool.ntp.org 项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以。

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

server  192.168.1.10  iburst

可以写多个 ntp 服务器

 

 

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。

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

driftfile /var/lib/chrony/drift

 

# 如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。(注释关闭此功能)

# Allow the system clock to be stepped in the first three updates if its offset is larger than 1 second.

# makestep 1.0 3    生产环境已存在时差的情况下,必须注释

 

# 启用实时时钟(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

 

# 指定 NTP 客户端地址,以允许或拒绝连接到扮演时钟服务器的机器(打开这个就成了NTP服务器)

# 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

 

4、 服务检查

查看时间源

[root@ test  ~]# chronyc sources

210 Number of sources = 1

MS Name/IP address Stratum Poll Reach LastRx Last sample

===============================================================================

^* 192.168.100.29 1 10 377 595 -1348ns[-2000ns] +/- 11ms

 

查看时间源状态

chronyc sourcestats

[root@ test  ~]# chronyc sourcestats

210 Number of sources = 1

Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev

==============================================================================

192.168.100.29 13 9 112m -0.000 0.011 -11ns 17us

 

查看时间源状态

watch -n 1 'chronyc tracking'

chronyc tracking

Reference ID    : 78197314 (120.25.115.20)

Stratum         : 3

Ref time (UTC)  : Thu Oct 20 03:13:58 2024

System time     : 44.323120117 seconds fast of NTP time

Last offset     : -0.000066264 seconds

RMS offset      : 0.000912449 seconds

Frequency       : 11.736 ppm slow

Residual freq   : -0.026 ppm

Skew            : 3.923 ppm

Root delay      : 0.035763457 seconds

Root dispersion : 0.002698489 seconds

Update interval : 70.6 seconds

Leap status     : Normal

   

相关推荐