服务器端#
(1)通过在线方式安装 chrony
yum install -y chrony
(2)启动 chrony 服务
systemctl start chronyd
(3)查看 chrony 服务状态
systemctl status chronyd
(4)配置 chrony 服务为开机自启动
systemctl enable chronyd
(5)修改 chronyd 服务配置文件,完成 NTP 服务器的搭建
vi /etc/chrony.conf
-------------------chrony.conf-------------------
pool 2.centos.pool.ntp.org iburst
sourcedir /run/chrony-dhcp
#配置的多个NTP服务器
server ftp.aliyun.com iburst
server time1.aliyun.com iburst
server time2.aliyun.com iburst
server time3.aliyun.com iburst
server time4.aliyun.com iburst
server time5.aliyun.com iburst
server 10.10.2.103 iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
#允许访问的网段
allow 10.10.0.0/16
keyfile /etc/chrony.keys
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
#日志存储路径
logdir /var/log/chrony
#日志测量统计指标
log measurements statistics tracking
-------------------chrony.conf-------------------
(6)配置防火墙,重启服务,使得配置生效
# 配置ntp服务访问策略,使其能够正常访问
firewall-cmd --permanent --add-service=ntp
# 重新加载防火墙策略
firewall-cmd --reload
# 重启chronyd服务
systemctl restart chronyd
(7)查看连接 NTP 服务的客户机
chronyc clients
客户机端#
(1)通过在线方式安装 chrony
yum install -y chrony
(2)配置访问 chrony 服务器
# 修改chrony的配置文件
vi /etc/chrony.conf
-------------------chrony.conf-------------------
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
pool 2.centos.pool.ntp.org iburst
# Use NTP servers from DHCP.
sourcedir /run/chrony-dhcp
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# 配置ntp服务器地址
server 10.10.2.103 iburst
#为排版方便此处省略部分提示信息
-----------------------------------------------
(3)启动 chronyd 服务,连接 NTP 服务器
# 启动chrony服务
systemctl start chronyd
# 查看chrony服务状态
systemctl status chronyd
# 配置chrony服务为开机自启动
systemctl enable chronyd
(4)配置防火墙,使得配置生效
# 配置ntp服务访问策略,使其能够正常访问
firewall-cmd --permanent --add-service=ntp
# 重新加载防火墙策略
firewall-cmd --reload
(5)验证 NTP 服务器的连接情况
# 查看源服务器状态
chronyc sourcestats
# 查看详细同步状态
chronyc sources -v
# 追踪同步情况
chronyc tracking
# 开启网络时间同步
timedatectl set-ntp true
# 查看时间同步状态
timedatectl status