之前写的:Chrony时间同步服务器的搭建——筑梦之路_筑梦之路的博客-CSDN博客_搭建chrony服务器
linux 下部署NTP服务器 时间同步_筑梦之路的博客-CSDN博客
操作系统:centos7
NTP 方式
# 安装ntp服务
yum -y install ntpdate
# 开始时间同步
ntpdate ntp3.aliyun.com
定时任务:
echo "*/5 * * * * /usr/sbin/ntpdate -u ntp3.aliyun.com"
Chrony方式
centos7 默认已安装
#服务端配置文件
cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
...
server ntp.ntsc.ac.cn iburst # 在这里添加几个时间同步服务器
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server s1a.time.edu.cn iburst
# 允许哪些NTP客户端通过本地网络同步主机的时间
allow 172.16.1.0/24
# 本机没有同步任何主机时间的情况下,依然把本机作为时间源
local stratum 10
...
systemctl restart chronyd && systemctl enable chronyd
#客户端配置文件
cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst # 0-3为系统默认时间服务器,注释掉
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 172.16.1.11 iburst # 添加指定的时间服务器
...
systemctl restart chronyd
上面的配置是把172.16.1.11作为时间服务器,本机同步172.16.1.11节点的时间
验证:chronyc sources -v
输出的最后一行,有上面配置的IP,说明配置chronyd成功;输出IP前面有*号,则表示时间已经同步。