KVM虚拟化-搭建系统方法虚拟化技术kvm
程序员文章站
2022-06-21 18:46:09
...
centos7.8在宿主机上安装kvm虚拟化的环境
yum -y install qemu-kvm libvirt virt-manager virt-install virt-viewer
systemctl start --now libvirtd
Ubuntu 安装 KVM
yum -y istall qemu-kvm virt-manager libvirt-daemon-system
#如果没有开启CPU虚拟化功能会提示以下信息
[aaa@qq.com ~]#kvm-ok
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
#添加CPU的虚拟化支持再执行
[aaa@qq.com ~]#kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
ps:centos8提供了供基于Web的虚拟机管理方式
[aaa@qq.com ~]#yum -y install cockpit
[aaa@qq.com ~]#systemctl enable --now cockpit.socket
Created symlink /etc/systemd/system/sockets.target.wants/cockpit.socket →
/usr/lib/systemd/system/cockpit.socket.
[aaa@qq.com ~]#dnf -y install cockpit
#打开浏览器,访问以下地址:
https://centos8主机:9090
在windos端安装virt-manager图形化工具
使用命令启动virt-manager工具
export DIRPLAY=10.0.0.1:0.0
virt-manager
安装完虚拟工具后,会自动生成一个 virbr0 网卡,类似于Vmware workstation 生成的VMnet8 网卡,充当虚拟机的NAT网卡
ip
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
group default qlen 1000
link/ether 52:54:00:97:eb:e3 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
查看
grep -R 192.168.122.1 /etc/libvirt/*
/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'>
[aaa@qq.com ~]# cat /etc/libvirt/qemu/networks/default.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh net-edit default
or other application using the libvirt API.
-->
<network>
<name>default</name>
<uuid>ca6f19c7-07ab-415c-8800-a2d30a424c1f</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:60:a5:b6'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
nmcli connection show virbr0
把准备好的ios镜像上传到宿主机
mkdir -p /data/ios
ll /data/iso/
total 11215400
-rw-r--r-- 1 qemu qemu 1085276160 Aug 9 16:37 CentOS-7-x86_64-Minimal-2003.iso
-rw-r--r-- 1 root root 1718616064 Aug 9 16:31 CentOS-8.2.2004-x86_64-minimal.iso
AMD CPU 创建虚拟机故障修复方法
#修复以上故障
[aaa@qq.com ~]# tee /etc/modprobe.d/qemu-system-x86.conf << EOF
options kvm ignore_msrs=1
EOF
options kvm ignore_msrs=1
[aaa@qq.com ~]#reboot
创建虚拟机
export DISPLAY=10.0.0.1:0.0
virt-manager
qemu-img create -f qcow2 /var/lib/libvirt/images/centos7.qcow2 20G
#查看支持的OS
[aaa@qq.com ~]#osinfo-query os| grep centos
创建虚拟机光盘启动并手动安装
virt-install --virt-type kvm --name centos7 --ram 1024 --vcpus 2 --cdrom=/data/isos/CentOS-7-x86_64-Minimal-2003.iso --disk path=/var/lib/libvirt/images/centos7.qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-variant=centos7.0
[aaa@qq.com ~]#export DISPLAY=10.0.0.1:0.0
[aaa@qq.com ~]#virt-manager
方法二
利用ios镜像创建,下一步
选择ios镜像
选择镜像路径
找到路径点击下一步
然后无脑下一步就行
这里勾选这个,等下配置输入法
上一篇: KVM虚拟化技术 详解