在CentOS7上运行KVM虚拟机
准备工作
检查CPU特性
CPU应该支持vmx
特性以更好地运行KVM虚拟机:lscpu | grep vmx
安装一些基础软件包(非必须)
sudo yum install -y epel-release net-tools vim unzip zip wget ftp bridge-utils
安装KVM及相关工具
sudo yum install -y qemu-kvm libvirt
sudo yum install -y libguestfs-tools libguestfs-tools libguestfs-tools-c
验证安装结果
$ lsmod | grep ^kvm
kvm_intel 174250 0
kvm 570658 1 kvm_intel
启动服务并设置为开机自动运行
systemctl start libvirtd
systemctl enable libvirtd
检查服务状态:
systemctl status libvirtd
systemctl is-enabled libvirtd
创建网络环境
注意: 如果这时系统里已经有了virbr0
这个网桥,则可以跳过本章节,后面直接使用virbr0
网桥即可。
创建default
网络和virbr0
网桥:
sudo virsh net-define /usr/share/libvirt/networks/default.xml
sudo virsh net-start default
sudo virsh net-autostart default
sudo virsh net-list
检查网络设置:
[root@cheshi-desktop1 ~]# sudo virsh net-list
Name State Autostart Persistent
--------------------------------------------
default active yes yes
[root@cheshi-desktop1 ~]# ifconfig virbr0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.66.15.173 netmask 255.255.254.0 broadcast 10.66.15.255
inet6 fe80::4ecc:6aff:fec5:ad0d prefixlen 64 scopeid 0x20<link>
ether 4c:cc:6a:c5:ad:0d txqueuelen 1000 (Ethernet)
RX packets 1613 bytes 118768 (115.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 74 bytes 10467 (10.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@cheshi-desktop1 ~]# ifconfig eno1
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::4ecc:6aff:fec5:ad0d prefixlen 64 scopeid 0x20<link>
ether 4c:cc:6a:c5:ad:0d txqueuelen 1000 (Ethernet)
RX packets 50352153 bytes 7052127783 (6.5 GiB)
RX errors 0 dropped 111 overruns 0 frame 0
TX packets 2944305 by