chrony 是网络时间协议(NTP)的通用实现。
chrony 包含两个程序:chronyd 是一个可以在启动时启动的守护程序。
chronyc 是一个命令行界面程序,用于监视 chronyd 的性能并在运行时更改各种操作参数。
yum -y install chrony
systemctl enable chronyd
systemctl start chronyd
配置:
/etc/chrony.conf
# 使用 pool.ntp.org 项目中的公共服务器。
# 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
# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
# 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 客户端地址,以允许或拒绝连接到扮演时钟服务器的机器
# 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
chronyc 用法
# 查看 ntp_servers
chronyc sources -v
# 查看 ntp_servers 状态
chronyc sourcestats -v
# 查看 ntp_servers 是否在线
chronyc activity -v
# 查看 ntp 详细信息
chronyc tracking -v