当前位置: > shell编程 >

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

时间:2014-10-17 12:36来源:linux.it.net.cn 作者:it

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

脚本内容如下:
 

复制代码代码示例:

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

IP=`ifconfig eth0 |grep 'inet addr' |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进行时间同步


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容