Shell脚本完成Linux系统的初始化配置

Shell脚本完成Linux系统的初始化配置

#!/bin/bash

function net_conf(){
if [ $# -ne 2 ] ; then
        echo "Usage : $0 hostname ipaddress"
exit
fi

mv -f /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
# first avg ----> hostname
# 2th avg----> ip address

cat >> /etc/sysconfig/network-scripts/ifcfg-ens33<< EOF
TYPE=Ethernet
IPADDR=$2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
EOF
mv -f  /etc/hostname  /etc/hostname.bak
cat >> /etc/hostname <<EOF
$1
EOF
}

function yum_conf() {

if [ ! -d /etc/yum.repos.d/bak ]; then
	 mkdir /etc/yum.repos.d/bak
fi

ls -a | grep repo | xargs -I {} mv -f {} ./bak/
cd /etc/yum.repos.d
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum remove  -y  epel-release
yum install -y  https://repo.huaweicloud.com/epel/epel-release-latest-7.noarch.rpm
cd /etc/yum.repos.d/
rm -rf epel-testing.repo
sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/epel.repo
sed -i "s@http://download.fedoraproject.org/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo
yum clean all
yum makecache
yum repolist all    
}

function dns_conf() {
mv -f /etc/resolv.conf /etc/resolv.conf.bak
cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 8.8.8.8
EOF
systemctl restart network 
}

function firewall_conf() {
  systemctl status firewalld.service
  systemctl disable firewalld.service
}


function pkg_install() {
yum -y install net-tools
yum -y install telnet-server.x86_64
yum -y install telnet.x86_64
yum -y install xinetd.x86_64
chkconfig telnet on
}



#############main ######
net_conf $1 $2
yum_conf
dns_conf
firewall_conf
pkg_install

sync;sync;sync;reboot -f

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yolo2016

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值