这里以centos7 为例,其它系统差不多
主节点
vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict ::1
restrict default nomodify
restrict default nomodify notrap
#有网络连接时同步阿里云时间
server ntp4.aliyun.com
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
#添加此处。允许内网其他机器同步。
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
从节点
vim /etc/ntp.conf
ftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict ::1
restrict default nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
#这里是主节点的主机名或者ip
server master
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
重启服务
systemctl restart ntpd
验证
ntpstat
synchronised to NTP server (119.28.206.193) at stratum 3
time correct to within 25 ms
polling server every 1024 s
网友评论