Linux:对新机器进行初始化设置的脚本

初始化

#!/bin/bash
echo "本次配置适用于Redhat7 CentOS7的物理机。公有云不可使用!其他版本系统慎用!"
#将IP地址修改为静态
read -p "请输入你的IP(最后一位即可,默认192.168.186.xxx): " ip
read -p "请输入你的主机名:" host_name

sed -i 's/\<dhcp\>/none/' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i "$ a IPADDR=192.168.186.${ip}\nNETMASK=255.255.255.0\nDNS=223.6.6.6\nGATEWAY=192.168.186.2" /etc/sysconfig/network-scripts/ifcfg-ens33
ifdown ens33;ifup ens33
#添加DNS解析
sed -i '/^nameserver/d' /etc/resolv.conf
echo "nameserver 223.6.6.6" >> /etc/resolv.conf


#配置yum源

yum -y install wget > /dev/null
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 
yum clean all
yum makecache

#配置epel源
find /etc/yum.repos.d/ -name "epel*"|xargs -i mv {} {}.bak
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
yum clean all
yum makecache

#永久修改主机名
echo "${host_name}" >/etc/hostname

#永久关闭防火墙 SeLinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0 >> /dev/null
sed -i.bak 's/enforcing$/disabled/' /etc/selinux/config

#ntp对时
yum -y install ntp-4.2.6p5-29.el7.centos.2.x86_64
ntpdate ntp.aliyun.com

#是否重启
read -p "初始化完成,部分配置需重启生效。现在重启?[y]" reply
[ $reply == "y" ] && reboot || echo "请您稍后手动重启。【reboot】"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值