centos初始化 ntp 杂七杂八脚本

虽说很简单几步,但是每次做添加都添加ntp就很烦,写一个脚本记录下

#!/bin/bash
read -p read -p"请输入主机名:    " HOSTNAME
#更换主机名
hostnamectl set-hostname $HOSTNAME
#添加DNS
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
#换源
version=$(cat /etc/redhat-release | awk '{print $4 }' | awk -F '.' '{print $1}')
echo $releasetmp
sleep 5
yum install wget -y
# 备份源文件
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-$version.repo
if [[ $? -eq 0 ]];then
    echo -e "\033[32m# yum 源已成功更新为 aliyun_repo #\033[0m"; 
    sleep 3; 
else
    echo -e "\033[31m# yum 源未成功更新为 aliyun_repo #\n3s 后退出...\033[0m";
    exit;
fi
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-$version.repo 
yum clean all && yum makecache && yum update -y
yum update -y
# 关闭防火墙&selinux
systemctl stop firewalld.service && systemctl disable firewalld.service 
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config && setenforce 0
# 安装常用软件
yum -y install ntp lrzsz  vim  net-tools  rsync bash-completion  tree screen lsof zip unzip telnet ntp locate
#添加ntp服务
read -p"请输入server NTP ip:    " SERVERIP
CLIENTIP=$(ifconfig $( ip route show | awk '/default/ { print $5 }' ) |sed -n 2p |awk -F ' ' '{print$2}')
CLENTPGET=$(ip route show | awk -F '/' ' NF>1{ print $1 }')
CLENTMASK=$(ifconfig $( ip route show | awk '/default/ { print $5 }' ) |sed -n 2p |awk -F ' ' '{print$4}')
#替换配置文件
sed -i 's/restrict default nomodify notrap nopeer noquery/#restrict default nomodify notrap nopeer noquery/g' /etc/ntp.conf
sed -i 's/restrict 127.0.0.1/restrict '"$CLIENTIP"' nomodify notrap nopeer noquery/g' /etc/ntp.conf
sed -i 's/restrict ::1/restrict '"$CLENTPGET"' mask '"$CLENTMASK"' nomodify notrap/g' /etc/ntp.conf
sed -i 's/server 0.centos.pool.ntp.org iburst/#server 0.centos.pool.ntp.org iburst/g' /etc/ntp.conf
sed -i 's/server 1.centos.pool.ntp.org iburst/#server 1.centos.pool.ntp.org iburst/g' /etc/ntp.conf
sed -i 's/server 2.centos.pool.ntp.org iburst/server '"$SERVERIP"'/g' /etc/ntp.conf
sed -i 's/server 3.centos.pool.ntp.org iburst/Fudge '"$SERVERIP"' stratum 10/g' /etc/ntp.conf
systemctl restart  ntpd  && systemctl enable  ntpd
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

king config

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值