1、自动检测是否支持硬件虚拟化
2、自动创建br0、br1网桥,用于内网和外网
3、自动安装kvm所需组件
取消网卡自动改名
cat > /etc/sysconfig/grub <<EOF
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
EOF
grub2-mkconfig -o /boot/grub2/grub.cfg
复制以下脚本安装环境
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
egrep '(vmx|svm)' /proc/cpuinfo
[ $? -ne 0 ] && echo "Hardware virtualization is not supported" &&exit 1
yum install -y wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install -y net-tools vim lrzsz tree screen lsof tcpdump
systemctl disable firewalld
systemctl stop firewalld
systemctl disable NetworkManager
systemctl stop NetworkManager
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
echo ' * - nofile 100000 ' >>/etc/security/limits.conf
yum update -y && reboot
hostnamectl --static set-hostname kvm-node1
cat > /etc/sysconfig/network-scripts/ifcfg-br0 <<EOF
TYPE="Bridge"
BOOTPROTO="static"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
IPADDR="192.168.7.68"
NETMASK="255.255.248.0"
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-br1 <<EOF
TYPE="Bridge"
BOOTPROTO="static"
NAME="br1"
DEVICE="br1"
ONBOOT="yes"
IPADDR="172.16.7.68"
NETMASK="255.255.255.0"
EOF
mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.bak
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth0"
BRIDGE="br0"
DEVICE="eth0"
ONBOOT="yes"
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth1"
BRIDGE="br1"
DEVICE="eth1"
ONBOOT="yes"
EOF
yum -y install kvm
lsmod | grep kvm
yum -y install python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-install virt-v2v libguestfs-tools acpid
[ $? -eq 0 ] && echo "Success!"
转载于Ropon运维博客–https://www.idiyrom.com/14.html