centos 搭建ntp
str=$(printf "%-25s" "*")
echo -e "${str// /*}"
echo -e "*\t\t\t*"
echo -e "*\tNTP 安装\t*"
echo -e "*\t\t\t*"
echo -e "${str// /*}"
#搭建ntp建议搭建在Puppet控制端
ntp=`rpm -qa | grep ntp- && echo $?`
if [[ "$ntp"x == ""x ]];then
yum install ntp-* -y > /dev/null >&
fi
#同步时间
/etc/init.d/ntpd stop > /dev/null >&
ntp=`ntpdate .uk.pool.ntp.org && ntpdate .uk.pool.ntp.org && echo $?`
if [[ "$ntp" == "" ]];then
echo 'NTP同步失败'
echo "执行ntpdate 0.uk.pool.ntp.org检查"
exit
fi
#写入配置文件
cat > /etc/ntp.conf << EFO
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 0.0.0.0 mask 0.0.0.0 nomodify
SYNC_HWCLOCK=yes
server time.nist.gov prefer
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server .centos.pool.ntp.org minpoll maxpoll iburst
server 210.72.145.44
server 218.21.130.42
server 127.127.1.0
fudge 127.127.1.0 stratum
restrict time.nist.gov nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict .centos.pool.ntp.org nomodify notrap noquery
restrict 210.72.145.44 nomodify notrap noquery
restrict 218.21.130.42 nomodify notrap noquery
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EFO
if [ $? != ];then
echo "写入失败"
exit
fi
#启动
/etc/init.d/ntpd start
ntp=`/etc/init.d/ntpd status | grep -Eo stopped`
if [ "$ntp" == "stopped" ];then
echo "启动失败"
echo "执行/etc/init.d/ntpd status检查并启动"
exit
fi
chkconfig ntpd on > /dev/null >&
ntp=`chkconfig --list ntpd | awk '{print $4,$5,$6}' | sed -e 's/://g' -e 's/[2-4\]//g' -e 's/ /\n/g'|uniq | grep -v 'on'`
if [[ "$ntp" != "" ]];then
echo "设置NTP开机启动失败"
echo "执行chkconfig --list ntpd检查"
exit
fi
ntp=`ntpq -p | sed '1,2d' | awk '{print $9}'`
for i in ntp
do
if [ x"$i" == x'' ];then
echo "时间同步有问题"
echo "执行ntpq -p检查"
exit
fi
done
#将ntp写入crontab
#ntp
ntp=`grep -q "NTP" /etc/crontab && echo $?`
if [[ "$ntp" != "" ]];then
echo "#NTP" >> /etc/crontab
echo "0 1 * * * root /usr/sbin/ntpdate time-b.nist.gov >/dev/null 2" >> /etc/crontab
service crond reload
fi
centos 搭建ntp的更多相关文章
- 使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 一.NTP服务器介绍 网络时间协议(Network Time Protocol,NTP)服务器,也就是日常所说的NTP服务器,用来提供同步时间服务 ...
- CentOS 6.5 下搭建NTP服务器
参考网站: http://www.iyunv.com/thread-64847-1-1.html http://acooly.iteye.com/blog/1993484 1 检查系统 ...
- Centos7安装搭建NTP服务器和NTP客户端同步时间
NTP简介: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在计算机的世界里,时间非常地重要 例如:对于火箭发射这种科研活动,对时间的 ...
- 搭建ntp服务器
1.同步网络时间 先关闭掉ntp服务,使用ntpd同步网络时间. /etc/init.d/ntpd stop ntpdate 2.hk.pool.ntp.org 网络时间可以从http://www.p ...
- CentOS之NTP服务器配置
本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...
- centos7搭建ntp时间同步服务器chrony服务
centos7搭建ntp时间同步服务器chrony服务 前言: 在centos6的时候我们基本使用的是ntp服务用来做时间同步,但是在centos7后推荐是chrony作为时间同步器的服务端使用, ...
- CentOS7搭建NTP服务器及客户端同步时间
一.服务器配置 1.查看服务器.客户端操作系统版本 [root@hadoop101 ~]# cat /etc/redhat-release CentOS Linux release (Core) 2. ...
- centos6 & centos7搭建ntp服务器
原理 NTP(Network TimeProtocol,网络时间协议)是用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1 ...
- linux搭建ntp时间同步服务
1.NTP简介 NTP(Network Time Protocol,网络时间协议)用来使计算机时间同步的一种协议.它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准 ...
随机推荐
- Linux下添加桌面快捷方式
这里用Ubuntu下BurpSuite举例 sudo vim /home/user/Desktop/burpsuite.desktop //burpsuite随意起名,系统会系动创建文件 文件写入 # ...
- 打开Vim/Vi代码高亮
由于新装Vim/Vi 默认是没有打开代码高亮配置的,就看到有朋友一次次到网上去找各种配置.其实Vim默认带来配置文件的样本的,只需拷贝过来就可使用. 在用户根目录(~)中新建vim的配置文件 .vim ...
- 《Cracking the Coding Interview》——第18章:难题——题目2
2014-04-29 00:59 题目:设计一个洗牌算法,效率尽量快点,必须等概率. 解法:每次随机抽一张牌出来,最后都抽完了,也就洗好了.时间复杂度O(n^2),请看代码. 代码: // 18.2 ...
- 《Cracking the Coding Interview》——第2章:链表——题目6
2014-03-18 02:41 题目:给定一个带有环的单链表,找出环的入口节点. 解法1:用hash来检测重复节点肯定是容易想而且效率也高的好办法. 代码: // 2.6 You have a ci ...
- phpStorm9.0 +xampp+chrome php调试环境配置!
不多说,直接上step by step: 1.xampp配置 看看我的XAMPP版本: 修改配置文件,该打开打开,该加上加上,结果如下(当前需要重新启动apache,配置才会生效): [XDebug] ...
- PL/SQL 循环语句
1.基本 LOOP 循环语句 语法: LOOP 语句序列; END LOOP; 其中,语句序列中需要一个EXIT语句或一个EXIT WHEN语句来中断循环. 实例: DECLARE x ) :; BE ...
- Jmeter编码问题
问题现象:1.利用csv data set config参数化数据后,在beanshell中引用,能正常引用到,但是传给服务器时,还是报手机号格式不对 将jmeter日志级别打成debug(jmete ...
- NGUI执行基本事件的原理
通常我们为对象附加一个脚本组件,脚本组件只要加此鼠标处理事件方法,这个对象就有了点击事件了: void OnClick() { Debug.Log("onclick"); } 可为 ...
- Python读取不同文件夹下的图片并且分类放到新创建的训练文件夹和标签文件夹
在深度学习的训练时,经常会碰到训练的样本数据集和标签数据集是在一个文件夹中,这个时候我们就不得不进行一些数据的预处理和文件的分类,例如将训练(training data)数据集和标签数据集(label ...
- css 外边距,内边距的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...