NTP客户端通过脚本一键配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cx55887/article/details/83902961

在上一篇博文NTP时间服务器安装配置详解中我已经讲解了如何配置NTP的服务端和客户端,但当进行集群的大规模配置时,一台一台的去手动配置NTP客户端会浪费我们很大的时间,所以这里我做了一个简单的脚本来实现NTP服务端自动配置。

脚本内容如下

#!/bin/bash
#变量定义NTP服务端ip
ntps=10.220.5.111
#安装ntp ntpdate
yum install ntp ntpdate -y &>/dev/null
#修改配置文件
echo "server $ntps
fudge $ntps startnum 10
restrict 127.0.0.1
includefile /etc/ntp/crypto/pw
logfile /var/log/ntp/ntp.log
" >/etc/ntp.conf
#创建日志文件
mkdir /var/log/ntp   &>/dev/null
touch /var/log/ntp/ntp.log
#关闭防火墙和selinux
service iptables stop  &>/dev/null
setenforce 0   &>/dev/null
#执行一次ntpdate时间同步
ntpdate $ntps &>/dev/null
#启动ntp
systemctl start ntpd
#检查状态
ntpq -p

------做运维之前很矫情的小年轻-----

猜你喜欢

转载自blog.csdn.net/cx55887/article/details/83902961