1.各个主机安装ntpdate
2.编写shell
#!/bin/sh array=("root@master" "root@slave002" "root@slave003" "root@slave004" "root@slave005" "root@slave006" "root@slave007" "root@slave008" "root@slave009" "root@slave010" "root@slave011" "root@slave012" "root@slave013" "root@slave014" "root@slave015" "root@slave016" "root@slave017" "root@client1" "root@client2" "root@client3" "root@client4") for i in "${array[@]}" do if [ ! -n $i ] then echo "HOSTNAME IS NULL" else ssh "$i" "ntpdate -u 6.6.1.52" #ssh登录 echo "$i" fi done
3.上传到master服务器上去,定时执行时间同步
vim /etc/crontab加入 */1 * * * * root /root/d.sh>>/root/log.txt 2>&1