一、VMware开启cpu虚拟化
在Linux中验证是否开启cpu虚拟化?
grep -E "vmx|svm" /proc/cpuinfo | wc -l
4
如果过滤出来,数值为0的话,表示未开启cpu虚拟化,不能使用KVM;数值为非0的话,则表示可以继续安装kvm
二、安装KVM工具包
#CentOS
yum install -y qemu-kvm qemu-kvm-tools libvirt libvirt-client virt-manager virt-install
#Ubuntu
apt install -y qemu-kvm virt-manager libvirt-daemon-system
kvm-ok #查看是否开启cpu虚拟化
三、启动KVM服务
[root@centos7 ~]# systemctl enable --now libvirtd
[root@centos7 ~]# ip a #查看是否⽣成 NAT ⽹卡 virbr0
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:d8:d2:16 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
3.1 修改virbr0的默认网段
过滤出"192.168.122.1"所在文件
[root@centos7 ~]# grep 192.168.122.1 /etc/ -R
/etc/libvirt/qemu/networks/autostart/default.xml: <ip address='192.168.122.1' netmask='255.255.255.0'>
/etc/libvirt/qemu/networks/default.xml: <ip address='192.168.122.1' netmask='255.255.255.0'>
[root@centos7 ~]# ll /etc/libvirt/qemu/networks/autostart/default.xml
lrwxrwxrwx 1 root root 14 Jul 1 20:15 /etc/libvirt/qemu/networks/autostart/default.xml -> ../default.xml
通过查看文件信息,我们发现/etc/libvirt/qemu/networks/autostart/default.xml是/etc/libvirt/qemu/networks/default.xml的软连接文件,所以我们只要在/etc/libvirt/qemu/networks/default.xml文件中更改即可。
[root@centos7 ~]# vim /etc/libvirt/qemu/networks/default.xml
<network>
<name>default</name>
<uuid>4cb7f3ab-8637-499e-8886-429844ff536e</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:d8:d2:16'/>
<ip address='10.10.10.1' netmask='255.255.255.0'>
<dhcp>
<range start='10.10.10.2' end='10.10.10.254'/>
</dhcp>
</ip>
</network>
[root@centos7 ~]# reboot #重启服务,否则不生效
[root@centos7 ~]# ip a
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:d8:d2:16 brd ff:ff:ff:ff:ff:ff
inet 10.10.10.1/24 brd 10.10.10.255 scope global virbr0
valid_lft forever preferred_lft forever
3.2 打开virt-manage可视化管理工具
#第一步:
xshell ---> 右键 ---> 属性 ---> 隧道 ---> 选中 Xmanage
#第二步:
[root@centos7 ~]# virt-manager