服务器端

(1)通过在线方式安装chrony

1
yum install -y chrony

(2)启动chrony服务

1
systemctl start chronyd

(3)查看chrony服务状态

1
systemctl status chronyd

(4)配置chrony服务为开机自启动

1
systemctl enable chronyd

(5)修改chronyd服务配置文件,完成NTP服务器的搭建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)配置防火墙,重启服务,使得配置生效

1
2
3
4
5
6
# 配置ntp服务访问策略,使其能够正常访问
firewall-cmd --permanent --add-service=ntp
# 重新加载防火墙策略
firewall-cmd --reload
# 重启chronyd服务
systemctl restart chronyd

(7)查看连接NTP服务的客户机

1
chronyc clients

客户机端

(1)通过在线方式安装chrony

1
yum install -y chrony

(2)配置访问chrony服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 修改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服务器

1
2
3
4
5
6
# 启动chrony服务
systemctl start chronyd
# 查看chrony服务状态
systemctl status chronyd
# 配置chrony服务为开机自启动
systemctl enable chronyd

(4)配置防火墙,使得配置生效

1
2
3
4
# 配置ntp服务访问策略,使其能够正常访问
firewall-cmd --permanent --add-service=ntp
# 重新加载防火墙策略
firewall-cmd --reload

(5)验证NTP服务器的连接情况

1
2
3
4
5
6
7
8
9
10
# 查看源服务器状态
chronyc sourcestats
# 查看详细同步状态
chronyc sources -v
# 追踪同步情况
chronyc tracking
# 开启网络时间同步
timedatectl set-ntp true
# 查看时间同步状态
timedatectl status