基于NTP的多服务器时间同步脚本


server服务器每1个小时更新一次时间,server服务器旗下同步服务器每5秒钟同步一次时间,同步服务器与外网不做交互,由server服务器进行同步时间。所以保证每一台同步服务器时间一致。

#vi ud_ntp.sh

#!/bin/bash
time=5
ip(){
echo "192.168.48.114"
echo "192.168.28.233"
}
stp(){
/etc/init.d/ntpd stop
}
upd(){
ntpdate us.pool.ntp.org
}
stt(){
/etc/init.d/ntpd start
}

num=`ps -ef | grep ntpd.pid | grep -v grep`
not(){
if [ ! -n "$num" ]; then
#      echo "IS NULL"
        upd
        stt
else
#      echo "NOT NULL"
        stp
        upd
        stt
fi
}

ntp(){
while true
do
sleep $time
for i in `ip`
do
        ssh $i ntpdate 192.168.48.117
        if [[ 00 == `date | awk -F ":" '{print $2}'` ]]
        then
                not
                sleep 240
                break
        fi
done
done
}
ntp&

还有什么考虑不周全的地方,大家指正!

CentOS NTP服务器安装与配置

Linux实战部署系列之NTP服务器

多种操作系统NTP客户端配置

搭建企业级NTP时间服务器

Linux下快速搭建ntp时间同步服务器

CentOS 6.3 下实现NTP时间服务器

本文永久更新链接地址

相关内容