用虚拟机编写脚本需求:1要白定义配置网络(记住需要备份网络配置文件) 2.自定义配置主机名 3.关闭防火墙与selinux安全策略 4.配冒示久挂载镜像 5.配置本地仓库与网络合库
时间: 2023-05-25 12:02:30 浏览: 99
以下是可能的脚本编写过程:
#!/bin/bash
# 备份并清空网络配置文件
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.backup
echo -e "DEVICE=eth0\nONBOOT=yes\nBOOTPROTO=dhcp\n" > /etc/sysconfig/network-scripts/ifcfg-eth0
# 自定义主机名
echo "hostname=mysystem" > /etc/sysconfig/network
# 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
sed -i.bak 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
# 挂载镜像
mount -t iso9660 -o loop /path/to/iso /mnt
# 配置本地和网络yum源
mkdir /yumrepos
cp /mnt/RHEL7/Server/repodata/*-comps.xml /yumrepos/
yum install createrepo -y
createrepo /yumrepos/
echo -e "[local]\nname=local repo\nbaseurl=file:///yumrepos\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/local.repo
echo -e "[network]\nname=network repo\nbaseurl=http://192.168.0.1/yumrepos\ngpgcheck=0\nenabled=1" > /etc/yum.repos.d/network.repo
# 完成
echo "All configurations completed."
阅读全文