#!/bin/bash#Auth:Darius#CentOS_7配置實驗環境eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`file=/etc/sysconfig/network-scripts/ifcfg-$enodir ...
#!/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