Shell脚本完成Linux系统的初始化配置
Shell脚本完成Linux系统的初始化配置#!/bin/bashfunction net_conf(){if [ $# -ne 2 ] ; thenecho "Usage : $0 hostname ipaddress"exitfimv -f /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifc
·
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
更多推荐
已为社区贡献2条内容
所有评论(0)