• Centos 8 stream x64安装KVM


    Centos 8 stream 安装kvm

    提示:本次记录介绍根据在X86机器中,安装KVM服务的过程,仅供参考


    提示:安装前需确保服务器可以支持与互联网互通,在安装过程中会需要下载外网依赖


    前言

    整合服务器,使服务器利用率最大化:虚拟化技术可使企业级的服务器运行多个虚拟机,从而有效控制了服务器数量的膨胀,大大提高了服务器利用率。另外,通过对未充分利用的服务器的整合,企业不再需要为新项目另外购置硬件,因此,减少了资金投入,降低了供电、制冷和场地方面的运营成本。


    提示:以下是本篇文章正文内容,下面案例可供参考

    一、检查系统内核信息

    查询内核发行号

    uname -r
    4.18.0-358.el8.x86_64
    
    • 1
    • 2

    查询内核名称

    uname -s
    Linux
    
    • 1
    • 2

    主机的硬件架构名称

    uname -m
    x86_64
    
    • 1
    • 2

    二、检查本机是否支持虚拟化

    cpu是否支持虚拟化或是否物理开启虚拟化

    使用

    grep -E '(vmx|svm)' /proc/cpuinfocat /proc/cpuinfo | grep vmx命令

    grep -E '(vmx|svm)' /proc/cpuinfo
    # 展示如下信息标识cpu支持虚拟化
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    cat /proc/cpuinfo | grep vmx
    # 展示如下信息标识cpu支持虚拟化
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat umip md_clear arch_capabilities
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    安装

    安装kvm依赖

    采用yum方式安装

    • 安装前检查可以安装的版本
      显示安装的工具有:libvirt、virt-install、qemu-kvm、qeum-img、wget;下面我们一次对对各版本进行逐一验证
    yum info libvirt
    名称         : libvirt
    版本         : 8.0.0
    发布         : 10.module_el8.7.0+1218+f626c2ff
    架构         : x86_64
    大小         : 0.0  
    源           : libvirt-8.0.0-10.module_el8.7.0+1218+f626c2ff.src.rpm
    仓库         : @System
    来自仓库     : appstream
    概况         : Library providing a simple virtualization API
    URL          : https://libvirt.org/
    协议         : LGPLv2+
    描述         : 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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    yum info virt-install
    名称         : virt-install
    版本         : 3.2.0
    发布         : 4.el8
    架构         : noarch
    大小         : 33 k
    源           : virt-manager-3.2.0-4.el8.src.rpm
    仓库         : @System
    来自仓库     : appstream
    概况         : Utilities for installing virtual machines
    URL          : https://virt-manager.org/
    协议         : GPLv2+
    描述         : Package includes several command line utilities, including virt-install
                 : (build and install new VMs) and virt-clone (clone an existing virtual
                 : machine).
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    yum info qemu-kvm
    名称         : qemu-kvm
    时期         : 15
    版本         : 6.2.0
    发布         : 20.module_el8.7.0+1218+f626c2ff.1
    架构         : x86_64
    大小         : 0.0  
    源           : qemu-kvm-6.2.0-20.module_el8.7.0+1218+f626c2ff.1.src.rpm
    仓库         : @System
    来自仓库     : appstream
    概况         : QEMU is a machine emulator and virtualizer
    URL          : http://www.qemu.org/
    协议         : GPLv2 and GPLv2+ and CC-BY
    描述         : qemu-kvm is an open source virtualizer that provides hardware
                 : emulation for the KVM hypervisor. qemu-kvm acts as a virtual
                 : machine monitor together with the KVM kernel modules, and emulates the
                 : hardware for a full system such as a PC and its associated peripherals.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    yum info qeum-img
    名称         : qemu-img
    时期         : 15
    版本         : 6.2.0
    发布         : 20.module_el8.7.0+1218+f626c2ff.1
    架构         : x86_64
    大小         : 8.2 M
    源           : qemu-kvm-6.2.0-20.module_el8.7.0+1218+f626c2ff.1.src.rpm
    仓库         : @System
    来自仓库     : appstream
    概况         : QEMU command line tool for manipulating disk images
    URL          : http://www.qemu.org/
    协议         : GPLv2 and GPLv2+ and CC-BY
    描述         : This package provides a command line tool for manipulating disk images.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    yum info wget
    名称         : wget
    版本         : 1.19.5
    发布         : 10.el8
    架构         : x86_64
    大小         : 2.8 M
    源           : wget-1.19.5-10.el8.src.rpm
    仓库         : @System
    来自仓库     : appstream
    概况         : A utility for retrieving files using the HTTP or FTP protocols
    URL          : http://www.gnu.org/software/wget/
    协议         : GPLv3+
    描述         : GNU Wget is a file retrieval utility which can use either the HTTP or
                 : FTP protocols. Wget features include the ability to work in the
                 : background while you are logged out, recursive retrieval of
                 : directories, file name wildcard matching, remote file timestamp
                 : storage and comparison, use of Rest with FTP servers and Range with
                 : HTTP servers to retrieve files over slow or unstable connections,
                 : support for Proxy servers, and configurability.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 在线下载和安装

    等待安装完成

    yum install libvirt virt-install qemu-kvm wget -y
    
    • 1
    • 验证安装结果
     yum list installed qemu-img wget libvirt virt-install qemu-kvm
    已安装的软件包
    libvirt.x86_64                                               8.0.0-10.module_el8.7.0+1218+f626c2ff                                                @appstream
    qemu-img.x86_64                                              15:6.2.0-20.module_el8.7.0+1218+f626c2ff.1                                           @appstream
    qemu-kvm.x86_64                                              15:6.2.0-20.module_el8.7.0+1218+f626c2ff.1                                           @appstream
    virt-install.noarch                                          3.2.0-4.el8                                                                          @appstream
    wget.x86_64                                                  1.19.5-10.el8                                                                        @appstream
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    启动 libvirtd

    systemctl start libvirtd.service
    
    • 1

    查看运行状态

    systemctl status libvirtd.service
    libvirtd.service - Virtualization daemon
       Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2022-12-01 05:57:34 UTC; 2s ago
         Docs: man:libvirtd(8)
               https://libvirt.org
     Main PID: 320125 (libvirtd)
        Tasks: 21 (limit: 32768)
       Memory: 16.6M
       CGroup: /system.slice/libvirtd.service
               ├─ 78916 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
               ├─ 78917 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
               └─320125 /usr/sbin/libvirtd --timeout 120
    
    12月 01 05:57:34 wcuu-nat-7230394803.local systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
    12月 01 05:57:34 wcuu-nat-7230394803.local systemd[1]: libvirtd.service: Found left-over process 78917 (dnsmasq) in control group while starting unit. Igno>
    12月 01 05:57:34 wcuu-nat-7230394803.local systemd[1]: This usually indicates unclean termination of a previous run, or service implementation deficiencies.
    12月 01 05:57:34 wcuu-nat-7230394803.local systemd[1]: Starting Virtualization daemon...
    12月 01 05:57:34 wcuu-nat-7230394803.local systemd[1]: Started Virtualization daemon.
    12月 01 05:57:35 wcuu-nat-7230394803.local dnsmasq[78916]: read /etc/hosts - 6 addresses
    12月 01 05:57:35 wcuu-nat-7230394803.local dnsmasq[78916]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
    12月 01 05:57:35 wcuu-nat-7230394803.local dnsmasq-dhcp[78916]: read /var/lib/libvirt/dnsmasq/default.hostsfile
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    检查KVM

    lsmod | grep kvm
    kvm_intel             323584  0
    kvm                   905216  1 kvm_intel
    irqbypass              16384  1 kvm
    
    • 1
    • 2
    • 3
    • 4

    总结

    任何事情可繁可简,重在与你如何看待它。

  • 相关阅读:
    数据库连接池之c3p0-0.9.1.2,线上偶发APPARENT DEADLOCK,如何解?
    Mybatis sql 控制台格式化
    腾讯云4核8G服务器支持多少人在线访问?
    JAVA基础(十)
    【Linux】VirtualBox安装Centos7
    基于网络的虚拟仪器测试系统
    Spring-IOC-@Value和@PropertySource用法
    组件通信-父传子组件通信
    全排列+力扣
    高效解决触客难题的外呼系统,其实原理很简单!
  • 原文地址:https://blog.csdn.net/wcuuchina/article/details/128130593