操作环境:CentOS 7
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
自动部署系统初始化:
#!/bin/bash
#change by liujun at 2020-03-04
#make ONBOOT=yes
NIC_name=$(ip addr | grep "^2" | awk -F ": " '{print $2}')
sed -ri 's/^(ONBOOT=.*)/ONBOOT="yes"/' /etc/sysconfig/network-scripts/ifcfg-$NIC_name
systemctl restart network
#Configure the network
sed -ri 's/^(BOOTPROTO=.*)/BOOTPROTO="static"/' /etc/sysconfig/network-scripts/ifcfg-$NIC_name
ip_address=$(ip addr show $NIC_name | awk '$1 == "inet" {print $2,$4}' | awk -F " " '{print $1}' | awk -F "/" '{print $1}')
netmask=$(ip addr show $NIC_name | awk '$1 == "inet" {print $2}' | awk -F "/" '{print $2}')
gateway=$(ip route show | grep "^default" | awk -F " " '{print $3}')
dns1=$(ip route show | grep "^default" | awk -F " " '{print $3}')
cat >> /etc/sysconfig/network-scripts/ifcfg-$NIC_name << EOF
IPADDR="$ip_address"
PREFIX="$netmask"
GATEWAY="$gateway"
DNS1="$dns1"
DNS2="8.8.8.8"
EOF
systemctl restart network
#configure the yum
yum install -y wget
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
#configure firewalld and selinux
systemctl stop firewalld
systemctl disable firewalld
sed -ri 's/^(SELINUX=.*)/SELINUX=disabled/' /etc/selinux/config
#install usully software
yum install -y vim lrzsz sysstat elinks net-tools bash-completion
echo "initlization done."
记一次:第一个脚本(自动部署系统初始化)