02 KVM安装虚拟化

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

文章目录

02 KVM安装虚拟化

2.1 最低硬件要求

在openEuler系统中安装虚拟化组件最低硬件要求

  • AArch64处理器架构ARMv8以上并且支持虚拟化扩展
  • x86_64处理器架构支持VT-x
  • 2核CPU
  • 4GB的内存
  • 16GB可用磁盘空间

2.2 安装虚拟化核心组件

2.2.1 安装方法

2.2.1.1 前提条件
  • 已经配置yum源。
  • 安装操作需要root用户权限。
2.2.1.2 安装步骤
  1. 安装QEMU组件。
# dnf install -y qemu

示例命令如下

[root@superman-21 ~]# dnf install -y qemu
Last metadata expiration check: 0:01:08 ago on 2023年02月04日 星期六 20时27分24秒.
Dependencies resolved.
============================================================================================================================
 Package                         Architecture          Version                              Repository                 Size
============================================================================================================================
Installing:
 qemu                            x86_64                10:6.2.0-60.oe2203                   update                    5.8 M
Installing dependencies:
 CUnit                           x86_64                2.1.3-22.oe2203                      OS                         50 k
 dtc                             x86_64                1.6.1-1.oe2203                       everything                 95 k
 libiscsi                        x86_64                1.19.0-9.oe2203                      update                     89 k
 multipath-tools                 x86_64                0.8.7-2.oe2203                       OS                        309 k
 qemu-block-curl                 x86_64                10:6.2.0-60.oe2203                   update                     38 k
 qemu-block-iscsi                x86_64                10:6.2.0-60.oe2203                   update                     45 k
 qemu-hw-usb-host                x86_64                10:6.2.0-60.oe2203                   update                     47 k
 rdma-core                       x86_64                35.1-2.oe2203                        OS                        795 k
 virglrenderer                   x86_64                0.8.2-3.oe2203                       update                    185 k
Installing weak dependencies:
 libiscsi-utils                  x86_64                1.19.0-9.oe2203                      update                    171 k

Transaction Summary
============================================================================================================================
Install  11 Packages

Total download size: 7.6 M
Installed size: 27 M
Downloading Packages:
(1/11): CUnit-2.1.3-22.oe2203.x86_64.rpm                                                    211 kB/s |  50 kB     00:00    
(2/11): dtc-1.6.1-1.oe2203.x86_64.rpm                                                       831 kB/s |  95 kB     00:00    
(3/11): multipath-tools-0.8.7-2.oe2203.x86_64.rpm                                           863 kB/s | 309 kB     00:00    
(4/11): libiscsi-1.19.0-9.oe2203.x86_64.rpm                                                 1.3 MB/s |  89 kB     00:00    
(5/11): rdma-core-35.1-2.oe2203.x86_64.rpm                                                  1.8 MB/s | 795 kB     00:00    
(6/11): libiscsi-utils-1.19.0-9.oe2203.x86_64.rpm                                           1.3 MB/s | 171 kB     00:00    
(7/11): qemu-block-curl-6.2.0-60.oe2203.x86_64.rpm                                          691 kB/s |  38 kB     00:00    
(8/11): qemu-block-iscsi-6.2.0-60.oe2203.x86_64.rpm                                         729 kB/s |  45 kB     00:00    
(9/11): qemu-hw-usb-host-6.2.0-60.oe2203.x86_64.rpm                                         781 kB/s |  47 kB     00:00    
(10/11): virglrenderer-0.8.2-3.oe2203.x86_64.rpm                                            1.8 MB/s | 185 kB     00:00    
(11/11): qemu-6.2.0-60.oe2203.x86_64.rpm                                                    4.0 MB/s | 5.8 MB     00:01    
----------------------------------------------------------------------------------------------------------------------------
Total                                                                                       4.0 MB/s | 7.6 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                    1/1 
  Installing       : rdma-core-35.1-2.oe2203.x86_64                                                                    1/11 
  Running scriptlet: rdma-core-35.1-2.oe2203.x86_64                                                                    1/11 
  Installing       : virglrenderer-0.8.2-3.oe2203.x86_64                                                               2/11 
  Running scriptlet: virglrenderer-0.8.2-3.oe2203.x86_64                                                               2/11 
  Installing       : qemu-hw-usb-host-10:6.2.0-60.oe2203.x86_64                                                        3/11 
  Installing       : qemu-block-curl-10:6.2.0-60.oe2203.x86_64                                                         4/11 
  Running scriptlet: dtc-1.6.1-1.oe2203.x86_64                                                                         5/11 
  Installing       : dtc-1.6.1-1.oe2203.x86_64                                                                         5/11 
  Running scriptlet: dtc-1.6.1-1.oe2203.x86_64                                                                         5/11 
  Installing       : multipath-tools-0.8.7-2.oe2203.x86_64                                                             6/11 
  Running scriptlet: multipath-tools-0.8.7-2.oe2203.x86_64                                                             6/11 
  Running scriptlet: CUnit-2.1.3-22.oe2203.x86_64                                                                      7/11 
  Installing       : CUnit-2.1.3-22.oe2203.x86_64                                                                      7/11 
  Installing       : libiscsi-1.19.0-9.oe2203.x86_64                                                                   8/11 
  Running scriptlet: libiscsi-1.19.0-9.oe2203.x86_64                                                                   8/11 
  Installing       : libiscsi-utils-1.19.0-9.oe2203.x86_64                                                             9/11 
  Installing       : qemu-block-iscsi-10:6.2.0-60.oe2203.x86_64                                                       10/11 
  Running scriptlet: qemu-10:6.2.0-60.oe2203.x86_64                                                                   11/11 
  Installing       : qemu-10:6.2.0-60.oe2203.x86_64                                                                   11/11 
  Running scriptlet: qemu-10:6.2.0-60.oe2203.x86_64                                                                   11/11 
  Verifying        : CUnit-2.1.3-22.oe2203.x86_64                                                                      1/11 
  Verifying        : multipath-tools-0.8.7-2.oe2203.x86_64                                                             2/11 
  Verifying        : rdma-core-35.1-2.oe2203.x86_64                                                                    3/11 
  Verifying        : dtc-1.6.1-1.oe2203.x86_64                                                                         4/11 
  Verifying        : libiscsi-1.19.0-9.oe2203.x86_64                                                                   5/11 
  Verifying        : libiscsi-utils-1.19.0-9.oe2203.x86_64                                                             6/11 
  Verifying        : qemu-10:6.2.0-60.oe2203.x86_64                                                                    7/11 
  Verifying        : qemu-block-curl-10:6.2.0-60.oe2203.x86_64                                                         8/11 
  Verifying        : qemu-block-iscsi-10:6.2.0-60.oe2203.x86_64                                                        9/11 
  Verifying        : qemu-hw-usb-host-10:6.2.0-60.oe2203.x86_64                                                       10/11 
  Verifying        : virglrenderer-0.8.2-3.oe2203.x86_64                                                              11/11 

Installed:
  CUnit-2.1.3-22.oe2203.x86_64                                 dtc-1.6.1-1.oe2203.x86_64                                   
  libiscsi-1.19.0-9.oe2203.x86_64                              libiscsi-utils-1.19.0-9.oe2203.x86_64                       
  multipath-tools-0.8.7-2.oe2203.x86_64                        qemu-10:6.2.0-60.oe2203.x86_64                              
  qemu-block-curl-10:6.2.0-60.oe2203.x86_64                    qemu-block-iscsi-10:6.2.0-60.oe2203.x86_64                  
  qemu-hw-usb-host-10:6.2.0-60.oe2203.x86_64                   rdma-core-35.1-2.oe2203.x86_64                              
  virglrenderer-0.8.2-3.oe2203.x86_64                         

Complete!
[root@superman-21 ~]# 
  1. 安装libvirt组件。
# dnf install -y libvirt

示例命令如下

[root@superman-21 ~]# dnf install -y libvirt
Last metadata expiration check: 0:02:00 ago on 2023年02月04日 星期六 20时27分24秒.
Dependencies resolved.
============================================================================================================================
 Package                                              Architecture     Version                       Repository        Size
============================================================================================================================
Installing:
 libvirt                                              x86_64           6.2.0-50.oe2203               update            70 k
Installing dependencies:
 augeas                                               x86_64           1.13.0-3.oe2203               update           376 k
 autogen                                              x86_64           5.18.16-2.oe2203              OS               464 k
 dnsmasq                                              x86_64           2.86-2.oe2203                 update           241 k
 fmt                                                  x86_64           8.0.1-1.oe2203                OS               101 k
 glusterfs                                            x86_64           10.0-4.oe2203                 OS               555 k
 glusterfs-cli                                        x86_64           10.0-4.oe2203                 OS               177 k
 glusterfs-client-xlators                             x86_64           10.0-4.oe2203                 OS               807 k
 glusterfs-fuse                                       x86_64           10.0-4.oe2203                 OS               129 k
 gnutls-utils                                         x86_64           3.7.2-2.oe2203                OS               243 k
 gperftools-libs                                      x86_64           2.9.1-4.oe2203                OS               266 k
 libgfapi0                                            x86_64           10.0-4.oe2203                 OS                83 k
 libgfrpc0                                            x86_64           10.0-4.oe2203                 OS                51 k
 libgfxdr0                                            x86_64           10.0-4.oe2203                 OS                26 k
 libglusterd0                                         x86_64           10.0-4.oe2203                 OS                12 k
 libglusterfs0                                        x86_64           10.0-4.oe2203                 OS               277 k
 librados2                                            x86_64           2:16.2.7-14.oe2203            update           3.6 M
 librbd1                                              x86_64           2:16.2.7-14.oe2203            update           3.8 M
 libvirt-bash-completion                              x86_64           6.2.0-50.oe2203               update            71 k
 libvirt-client                                       x86_64           6.2.0-50.oe2203               update           367 k
 libvirt-daemon                                       x86_64           6.2.0-50.oe2203               update           338 k
 libvirt-daemon-config-network                        x86_64           6.2.0-50.oe2203               update            72 k
 libvirt-daemon-config-nwfilter                       x86_64           6.2.0-50.oe2203               update            76 k
 libvirt-daemon-driver-interface                      x86_64           6.2.0-50.oe2203               update           206 k
 libvirt-daemon-driver-network                        x86_64           6.2.0-50.oe2203               update           231 k
 libvirt-daemon-driver-nodedev                        x86_64           6.2.0-50.oe2203               update           206 k
 libvirt-daemon-driver-nwfilter                       x86_64           6.2.0-50.oe2203               update           229 k
 libvirt-daemon-driver-qemu                           x86_64           6.2.0-50.oe2203               update           852 k
 libvirt-daemon-driver-secret                         x86_64           6.2.0-50.oe2203               update           196 k
 libvirt-daemon-driver-storage                        x86_64           6.2.0-50.oe2203               update            70 k
 libvirt-daemon-driver-storage-core                   x86_64           6.2.0-50.oe2203               update           247 k
 libvirt-daemon-driver-storage-disk                   x86_64           6.2.0-50.oe2203               update            80 k
 libvirt-daemon-driver-storage-gluster                x86_64           6.2.0-50.oe2203               update            82 k
 libvirt-daemon-driver-storage-iscsi                  x86_64           6.2.0-50.oe2203               update            77 k
.
.
.
  libvirt-daemon-driver-qemu-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-secret-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-core-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-disk-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-gluster-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-iscsi-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-iscsi-direct-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-logical-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-mpath-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-rbd-6.2.0-50.oe2203.x86_64
  libvirt-daemon-driver-storage-scsi-6.2.0-50.oe2203.x86_64
  libvirt-libs-6.2.0-50.oe2203.x86_64
  libxslt-1.1.34-8.oe2203.x86_64
  lttng-ust-2.10.1-11.oe2203.x86_64
  lzop-1.04-1.oe2203.x86_64
  netcf-0.2.8-20.oe2203.x86_64 
  numad-0.5-31.oe2203.x86_64
  open-iscsi-2.1.5-7.oe2203.x86_64
  open-isns-0.101-1.oe2203.x86_64
  open-isns-help-0.101-1.oe2203.noarch
  qemu-img-10:6.2.0-60.oe2203.x86_64
  radvd-2.19-2.oe2203.x86_64
  systemd-container-249-16.oe2203.x86_64
  yajl-2.1.0-18.oe2203.x86_64

Complete!
[root@superman-21 ~]# 
  1. 启动libvirtd服务。
# systemctl start libvirtd

示例命令如下

[root@superman-21 ~]# systemctl start libvirtd
[root@superman-21 ~]# 

说明 说明
KVM模块已经集成在openEuler内核中因此不需要单独安装。

2.2.2 验证安装是否成功

  1. 查看内核是否支持KVM虚拟化即查看/dev/kvm和/sys/module/kvm文件是否存在命令和回显如下
# ls /dev/kvm

​ 示例命令如下

[root@superman-21 ~]# ls /dev/kvm
/dev/kvm
[root@superman-21 ~]# 
# ls /sys/module/kvm

​ 示例命令如下

[root@superman-21 ~]# ls /sys/module/kvm
coresize  holders  initsize  initstate  notes  parameters  refcnt  sections  srcversion  taint  uevent
[root@superman-21 ~]# 

若上述文件存在说明内核支持KVM虚拟化。若上述文件不存在则说明系统内核编译时未开启KVM虚拟化需要更换支持KVM虚拟化的Linux内核。

  1. 确认QEMU是否安装成功。

    若安装成功则可以看到QEMU软件包信息

# rpm -qi qemu    

​ 示例命令如下

[root@superman-21 ~]# rpm -qi qemu
Name        : qemu
Epoch       : 10
Version     : 6.2.0
Release     : 60.oe2203
Architecture: x86_64
Install Date: 2023年02月04日 星期六 20时28分38秒
Group       : Unspecified
Size        : 21795130
License     : GPLv2 and BSD and MIT and CC-BY-SA-4.0
Signature   : RSA/SHA1, 2022年12月20日 星期二 15时48分21秒, Key ID d557065eb25e7f66
Source RPM  : qemu-6.2.0-60.oe2203.src.rpm
Build Date  : 2022年12月20日 星期二 08时00分00秒
Build Host  : obs-worker1639015616-x86-0004
Packager    : http://openeuler.org
Vendor      : http://openeuler.org
URL         : http://www.qemu.org
Summary     : QEMU is a generic and open source machine emulator and virtualizer
Description :
QEMU is a FAST! processor emulator using dynamic translation to achieve good emulation speed.

QEMU has two operating modes:

   Full system emulation. In this mode, QEMU emulates a full system (for example a PC),
   including one or several processors and various peripherals. It can be used to launch
   different Operating Systems without rebooting the PC or to debug system code.

   User mode emulation. In this mode, QEMU can launch processes compiled for one CPU on another CPU.
   It can be used to launch the Wine Windows API emulator (https://www.winehq.org) or to ease
   cross-compilation and cross-debugging.
You can refer to https://www.qemu.org for more infortmation.
[root@superman-21 ~]# 
  1. 确认libvirt是否安装成功。

    若安装成功则可以看到libvirt软件包信息

# rpm -qi libvirt

​ 示例命令如下

[root@superman-21 ~]# rpm -qi libvirt
Name        : libvirt
Version     : 6.2.0
Release     : 50.oe2203
Architecture: x86_64
Install Date: 2023年02月04日 星期六 20时29分36秒
Group       : Unspecified
Size        : 0
License     : LGPLv2+
Signature   : RSA/SHA1, 2023年01月05日 星期四 06时49分21秒, Key ID d557065eb25e7f66
Source RPM  : libvirt-6.2.0-50.oe2203.src.rpm
Build Date  : 2023年01月04日 星期三 08时00分00秒
Build Host  : obs-worker-backend-test-x86-0006
Packager    : http://openeuler.org
Vendor      : http://openeuler.org
URL         : https://libvirt.org/
Summary     : Library providing a simple virtualization API
Description :
Libvirt is a C toolkit to interact with the virtualization capabilities
of recent versions of Linux (and other OSes). The main package includes
the libvirtd server exporting the virtualization support.
[root@superman-21 ~]# 
  1. 查看libvirt服务是否启动成功。

    若服务处于“Active”状态说明服务启动成功可以正常使用libvirt提供的virsh命令行工具

# systemctl status libvirtd

​ 示例命令如下

[root@superman-21 ~]# systemctl status libvirtd
○ libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sat 2023-02-04 20:37:24 CST; 6min ago
TriggeredBy: ● libvirtd.socket
             ● libvirtd-ro.socket
             ● libvirtd-admin.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
    Process: 2104 ExecStart=/usr/sbin/libvirtd $LIBVIRTD_ARGS (code=exited, status=0/SUCCESS)
   Main PID: 2104 (code=exited, status=0/SUCCESS)
      Tasks: 2 (limit: 32768)
     Memory: 4.6M
     CGroup: /system.slice/libvirtd.service
             ├─2208 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/l>
             └─2209 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/l>

2月 04 20:35:25 superman-21 dnsmasq-dhcp[2208]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
2月 04 20:35:25 superman-21 dnsmasq-dhcp[2208]: DHCP, sockets bound exclusively to interface virbr0
2月 04 20:35:25 superman-21 dnsmasq[2208]: reading /etc/resolv.conf
2月 04 20:35:25 superman-21 dnsmasq[2208]: using nameserver 202.102.224.68#53
2月 04 20:35:25 superman-21 dnsmasq[2208]: read /etc/hosts - 2 addresses
2月 04 20:35:25 superman-21 dnsmasq[2208]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
2月 04 20:35:25 superman-21 dnsmasq-dhcp[2208]: read /var/lib/libvirt/dnsmasq/default.hostsfile
2月 04 20:37:24 superman-21 systemd[1]: libvirtd.service: Deactivated successfully.
2月 04 20:37:24 superman-21 systemd[1]: libvirtd.service: Unit process 2208 (dnsmasq) remains running after unit stopped.
2月 04 20:37:24 superman-21 systemd[1]: libvirtd.service: Unit process 2209 (dnsmasq) remains running after unit stopped.
[root@superman-21 ~]#

点赞你的认可是我创作的动力

⭐️ 收藏你的青睐是我努力的方向

✏️ 评论你的意见是我进步的财富

在这里插入图片描述

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6