shell搭建CentOS_7基础环境

旧巷老猫 提交于 2020-02-08 00:39:50

#!/bin/bash
#Auth:Darius
#CentOS_7配置实验环境
eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`
file=/etc/sysconfig/network-scripts/ifcfg-$eno
dir=/etc/yum.repos.d
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#查看防火墙是否开启
firewall-cmd --state
#清空防火墙规则
iptables -F
#临时关闭selinux
setenforce 0

#永久关闭selinux
sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
#修改主机名
echo "当前主机名:$(hostname)"
read -p "请输入新主机名:" hostname_input
hostname $hostname_input &> /dev/null
hostnamectl set-hostname $hostname_input &> /dev/null

#ip地址设置
rm -rf /etc/udev/*
echo -e "DEVICE=$eno\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static" >$file
read -p "请输入ip地址": ip
read -p "请输入子网掩码": nt
read -p "请输入网关": gw
echo "IPADDR=$ip" >> $file
echo "NETMASK=$nt" >>$file
echo "GATEWAY=$gw" >>$file
[ $? -eq 0 ] && echo "IP地址配置成功"
#构建yum本地仓库
mkdir /media/cdrom
mount /dev/sr0 /media/cdrom/
#设置光盘自动挂载
echo "/dev/sr0 /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
mkdir $dir/bak
mv $dir/C* $dir/bak/
echo -e "[yum]\nname=yum\nbaseurl=file:///media/cdrom\ngpgcheck=0\nenabled=1" >$dir/yum.repo
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "yum仓库构建完成"
yum install -y vim gcc gcc-c++ make &>/dev/null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!