第一步:所有节点安装ntp服务
sudo yum install -y ntp
第二步:修改配置文件(第一个节点,其它节点的server则修改为 server 192.168.163.0 )
sudo vi /etc/ntp.conf
statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server ntp.aliyun.com
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com
server ntp5.aliyun.com
server ntp6.aliyun.com
server ntp7.aliyun.com
# 不允许来自公网上ipv4和ipv6客户端的访问
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
# 允许这个网段的对时请求
restrict 192.168.128.0 mask 255.255.255.0 nomodify
第三步:同步时间
sudo ntpdate ntp.aliyun.com
第四步:启动NTP服务并查看状态
sudo systemctl start ntpd
sudo systemctl status ntpd
第五步:设置开机自启
sudo systemctl enable ntpd
第六步:查看时间是否同步(需等待一会)
ntpstat