if $(egrep -o 'vmx|svm' /proc/cpuinfo >>/dev/null);then
echo "[当前设备未开启虚拟化,请参考https://www.asfor.cn/archives/611.html教程开启虚拟化后再次使用此脚本]";
mv /etc/yum.repos.d/* ~/;
echo "[其他镜像源可参考https:/www.asfor.cn/server/mirror]";
echo "[您的repo文件已被移动至当前用户的家目录]"
# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo;
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo;
# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo;
# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo;
echo "[yum源文件配置成功,正在执行检测软件包数量]";
yum -y install epel-release vim wget net-tools unzip zip gcc gcc-c++;
yum -y install qemu-kvm qemu-kvm-tools qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils libguestfs-tools;
systemctl stop firewalld;
systemctl disable firewalld;
sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config;
echo "[SELINUX已被临时关闭,重启后将永久生效]";
read -p "网卡名称(example:ens33): " NETNAME
read -p "IP(example:192.168.81.134): " NETIP
read -p "网关(example:192.168.81.1): " NETGATEWAY
read -p "子网掩码(example:255.255.255.0):" NETMASK
cp /etc/sysconfig/network-scripts/ifcfg-$NETNAME /etc/sysconfig/network-scripts/ifcfg-br0
cat >> /etc/sysconfig/network-scripts/ifcfg-$NETNAME <<EOF
cat > /etc/sysconfig/network-scripts/ifcfg-br0 <<EOF
systemctl restart network
echo "[网络重启完成,您的网卡列表如下,请检查!]"
read -p "CPU核数(example:1)" CPU
read -p "输入虚拟机内存大小(M): " MEM
read -p "输入虚拟及硬盘大小(G): " SIZE
read -p "ISO镜像位置(example:/root/rhel-server-7.3-x84_64-dvd.iso):" ISOPATH
read -p "硬盘镜像位置(example:/root):" DISKPATH
virt-install --virt-type=kvm --name=$NAME --vcpus=$CPU --memory=$MEM --location=$ISOPATH --disk path=$DISKPATH/$NAME.qcow2,size=$SIZE,format=qcow2 --network bridge=virbr0 --graphics none --extra-args='console=ttyS0' --force