一键安装与配置NTP server的脚本

发布时间:2021-01-11编辑:脚本学堂
分享一个shell脚本,用于一键安装与配置ntp server时间服务器,有需要的朋友参考下。

本节分享一个一键安装脚本,用于安装与配置时间服务器 NTP server。

脚本内容如下:
 

复制代码 代码示例:

#!/bin/bash
#Filename:ntp.sh

IP=`ifconfig eth0 |grep 'inet addr' |linuxjishu/13830.html target=_blank class=infotextkey>awk -F '[ :]+'  '{print $4}'`
yum -y  install ntp*
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0 
sed -i 's/BOOTPROTO="dhcp"/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0 
sed -i 's/BOOTPROTO=none/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0 
echo "IPADDR=192.168.66.181" >>/etc/sysconfig/network-scripts/ifcfg-eth0 
echo "NETMASK=255.255.255.0" >>/etc/sysconfig/network-scripts/ifcfg-eth0 
service network restart 1>/dev/null  2>/dev/null
sed -i  "s/#restrict 192.168.1.0/restrict 192.168.66.0/g" /etc/ntp.conf
sed -i "s/#server*/server/g" /etc/ntp.conf
sed -i "s/#fudge*/fudge/g" /etc/ntp.conf
sed -i "s/restrict default kod nomodify notrap nopeer noquery/#restrict default kod nomodify notrap nopeer noquery/g" /etc/ntp.conf
echo server ntp.nasa.gov >>/etc/ntp.conf
echo logfile /var/log/ntp >>/etc/ntp.conf
echo  $IP  >>  /etc/ntp/step-tickers
echo  "127.127.1.0 " >>   /etc/ntp/step-tickers
echo  "SYNC_HWCLOCK=yes" >>/etc/sysconfig/ntpd
service ntpd restart     #重启服务完毕 十分钟后再用client进行时间同步