1
、软件安装
#
设置当前时区
[root@localhost ~]
# timedatectl set-timezone Asia/Shanghai
[root@localhost ~]
# yum install -y chrony
[root@localhost ~]
# systemctl enable --now chronyd
[root@server1 ~]
# cat /etc/chrony.conf
#
设置时间服务器的服务端名字
server
0
.centos.pool.ntp.org iburst
server
1
.centos.pool.ntp.org iburst
server
2
.centos.pool.ntp.org iburst
# Allow NTP client access from local network.
#
设置允许哪个客户端可以访问该服务器
#allow 192.168.0.0/16
2、配置时间服务器客户端
[root@server1 ~]
# vim /etc/chrony.conf
#
此处服务器可以写国内的
server ntp.aliyun.com iburst
[root@localhost ~]
# systemctl restart chronyd
[root@server1 ~]
# chronyc sources
210
Number of sources
=
2
MS Name/IP address Stratum Poll Reach LastRx Last sample
============================================================================
===
^*
203
.107.6.88
2 6 7 1
-705us
[
-5240s
]
+
/-
28ms
^? ntp1.flashdance.cx
0 6 0
-
+
0ns[
+
0ns]
+
/-
0ns
*
表示
chronyd
当前同步到的源
+
表示可接受的信号源,与选定的信号源组合在一起
? 指示已失去连接性或其数据包未通过所有测试的源。它也显示在启动时,直到从中至少收集了
3
个样本为止
3
、配置时间服务器服务端
#
需要两个服务器,一个服务端(服务端
ip
:
192.168.231.129
),一个客户端测试(客户端主机
ip
网
段为
192.168.231.130/24
)
#
服务端的配置
[root@localhost ~]
# systemctl disable --now firewalld
[root@localhost ~]
# grep allow /etc/chrony.conf
allow
192
.168.231.130/24
#allow 0.0.0.0/0
[root@localhost ~]
# systemctl restart chronyd
#
客户端访问
,
先
ping
时间服务器
[root@localhost ~]
# ping 192.168.231.129
[root@localhost ~]
# grep iburst /etc/chrony.conf
server
192
.168.168.253 iburst
[root@localhost ~]
# systemctl restart chronyd
[root@localhost ~]
# chronyc sources
#
每周周一
8
:
00
向时间服务器同步当前主机的时间
[root@ntp-server ~]
# dnf install chrony -y
[root@ntp-server ~]
# grep ^pool /etc/chrony.conf
pool ntp.aliyun.com iburst
pool pool.ntp.org iburst
pool ntp.tencent.com iburst
[root@ntp-server ~]
# systemctl enable --now chronyd
[root@ntp-server ~]
# grep chronyc /etc/crontab
0 8
*/7 *
1
root chronyc sources &> /dev/null