安装ntp服务
yum -y install ntp
服务端配置
vim /etc/ntp.conf
restrict 172.16.1.61 nomodify notrap nopeer noquery //当前节点IP地址
restrict 172.16.1.1 mask 255.255.255.0 nomodify notrap //集群所在网段的网关,子网掩码
# 在server部分添加以下部分,并注释掉server
server 127.127.1.0
fudge 127.127.1.0 stratum 10
客户端配置
vim /etc/ntp.conf
restrict 172.16.1.7 nomodify notrap nopeer noquery //当前节点IP地址
restrict 172.16.1.1 mask 255.255.255.0 nomodify notrap //集群所在网段的网关,子网掩码
在server部分添加如下语句,将server指向主节点。
server 172.16.1.61
fudge 172.16.1.61 stratum 10
启用服务
service ntpd start
chkconfig ntpd on
客户端运行如下命令,与服务端实现同步
ntpdate -u 192.168.0.101
配置定时任务
crontab -e
* * * * * ntpdate -u 192.168.0.101 (星代表,分时日月周)