自定义部署Chrony同步时间
通过自定义时间服务器向指定的客户端主机同步时间
要求:自定义时间服务器主机的时间通过ntp.aliyun.com主机同步时间
一 客户端的配置
1,客户端与服务端使用同一种网络模式(NAT)
2,vim /etc/chrony.conf(使用文本编辑器进入chrony的配置文件)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst
server 192.168.2.128 iburst(这一行修改为自己服务端的ip地址)
3, [root@localhost /]# date -s 12:20
Wed Oct 22 12:20:00 PM CST 2025 (将时间修改为错误的使效果明显)
[root@localhost /]# systemctl restart chronyd (修改配置文件后需要重启软件)
[root@localhost /]# timedatectl
Local time: Wed 2025-10-22 21:31:27 CST (由此可以看出时间已经同步)
Universal time: Wed 2025-10-22 13:31:27 UTC
RTC time: Wed 2025-10-22 13:31:27
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
[root@localhost /]# chronyc sources (这个命令可以查看同步的时间由谁提供)
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.2.128 (由此看出时间由我们自己部署的Chrony提供) 3 6 77 20 +41us[ +637us] +/- 23ms
二 服务端的配置
1,客户端与服务端使用同一种网络模式(NAT)
2, [root@localhost /]# systemctl disable firewalld.service
[root@localhost /]# setenforce 0
关闭防火墙以及降低SELINUX的强度(以防时间同步时出现错误)
3,vim /etc/chrony.conf(使用文本编辑器进入chrony的配置文件)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.rhel.pool.ntp.org iburst
pool ntp.aliyun.com iburst (使用阿里的时间同步)
#Allow NTP client access from local network.
allow 192.168.2.0/24 (允许的客户端的网段)
# Serve time even if not synchronized to a time source.
local stratum 10 (本地服务主机的等级 10)
4, [root@localhost /]# systemctl restart chronyd (修改配置文件后需要重启软件)