KVM虚拟化搭建

KVM虚拟化搭建

1.关闭防火墙

# 停止firewall
systemctl stop firewalld

# 禁止firewall开机启动
systemctl disable firewalld

2.关闭enforce

setenforce 0
# 将/etc/selinux/config中SELINUX=enforcing改为SELINUX=disabled
vi /etc/selinux/config 

3.查cpu是否支持VT

egrep '(vmx|svm)' --color=always /proc/cpuinfo

4.检查内核模块是否加载

lsmod | grep kvm

5.安装kvm及依赖

yum install -y  virt-*  libvirt  bridge-utils qemu-img qemu-kvm virt-install

设置开机启动

systemctl enable libvirtd
systemctl start libvirtd

查看状态是否正常

systemctl status libvirtd

配置软连接

ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm 

6.为虚拟机创建网桥

首先备份一下网卡设置

cp /etc/sysconfig/network-scripts/ifcfg-ens160  /etc/sysconfig/network-scripts/ifcfg-ens160.bak

配置虚拟网桥

# 清空ifcfg-ens160内容
cat >/etc/sysconfig/network-scripts/ifcfg-ens160 <<EOF
DEVICE=ens160
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0
EOF

新建br0

cat >/etc/sysconfig/network-scripts/ifcfg-br0 <<EOF
TYPE="Bridge"
BOOTPROTO=static
DEVICE="br0"
ONBOOT="yes"
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
DELAY="0"
EOF

7.重启网络

systemctl restart network

8.查看网桥

brctl show
brctl stp br0 on

9.创建虚拟机

方式1

# 1.创建虚拟机文件系统
qemu-img create -f qcow2 centos6.qcow2 500G

# 2.用virt-manager图形化安装:略

方式2

# virt-install安装
virt-install --name=master1 --memory 8192 --vcpus=2 --disk path=/data/qemu/centos1/centos1.qcow2,size=500,format=qcow2,bus=virtio --accelerate --cdrom=/data/CentOS-7-x86_64-DVD-1810.iso --vnc --vncport=6004 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole

来源简书 https://blog.csdn.net/wq962464/article/details/105238378

留下评论