CentOS 7 shell脚本_自动部署初始化(记录)

操作环境: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."

记一次:第一个脚本(自动部署系统初始化)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值