基于Chrony时间同步

服务端

安装chrony

yum install -y chrony

启动服务并且加入开机自启

systemctl enable chronyd.service && systemctl restart chronyd.service && systemctl status chronyd.service

编辑配置文件

vim /etr/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.rocky.pool.ntp.org iburst
server 176.0.250.31 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 176.0.0.0/16
allow 192.168.10.0/24
allow 10.10.100.0/24
allow 63.0.0.0/16
#qhtest
allow 72.0.0.251

# Serve time even if not synchronized to a time source.
local stratum 10

# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

设置系统时区

timedatectl set-timezone Asia/Shanghai

重启服务

systemctl restart chronyd.service

强制同步时钟

chronyc -a makestep

客户端

安装chrony

yum install -y chrony

启动服务并且加入开机自启

systemctl enable chronyd.service && systemctl restart chronyd.service && systemctl status chronyd.service

编辑配置文件

vim /etr/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.rocky.pool.ntp.org iburst
server 176.0.250.1 iburst
server 176.0.250.2 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 30000

# 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

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

重启服务

systemctl restart chronyd.service

启用NTP时间同步

timedatectl set-ntp yes

常用命令

查看时间同步源

chronyc sources -v

查看时间同步源状态

chronyc sourcestats -v

校准时间服务器

chronyc tracking

查看硬件时间

hwclock

将硬件时间设置成和软件时间一样的

hwclock --systohc