伺服器端#
(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