欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos8 下安装kvm虚拟机

程序员文章站 2024-03-08 18:05:10
...

kvm虚拟机安装步骤

步骤一: 检查系统配置

测试系统是否支持虚拟机话,不行的话要再bios中设置 虚拟化

[[email protected] ~]# lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           AuthenticAMD
CPU family:          16
Model:               4
Model name:          AMD Phenom(tm) II X2 B57 Processor
Stepping:            3
CPU MHz:             3200.000
CPU max MHz:         3200.0000
CPU min MHz:         800.0000
BogoMIPS:            6429.41
Virtualization:      AMD-V
L1d cache:           64K
L1i cache:           64K
L2 cache:            512K
L3 cache:            6144K
NUMA node0 CPU(s):   0,1
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save

可以看到 本机器支持虚拟化  Virtualization:      AMD-V

如果没有相应的输出,就需要到bios设定或者是系统不支持。

确认有无kvm模块

[[email protected] ~]#  modprobe kvm
[[email protected] ~]# lsmod |grep kvm
kvm_amd               110592  0
ccp                    98304  1 kvm_amd
kvm                   786432  1 kvm_amd
irqbypass              16384  1 kvm

步骤二: 安装支撑包

确认系统已经安装好yum,网络通畅。

然后安装kvm虚拟机的安装包

# yum install qemu-kvm libvert virt-install -y

步骤三:安装centos虚拟机,我们采用centos7.8 minimal镜像,命令行启动

virt-install --name=centos7 --memory=512,maxmemory=1980  --vcpus=2,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-DVD-1708.iso --disk path=/vms/centos7.qcow2,size=80 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args=“console=tty0 console=ttyS0”

错误信息如下:

[[email protected] ~]# virt-install --name=centos7 --memory=1980,maxmemory=1980  --vcpus=2,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-Minimal-2003.iso --disk path=/vms/centos7.qcow2,size=80 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
WARNING  The requested volume capacity will exceed the available pool space when the volume is fully allocated. (81920 M requested capacity > 47670 M available)
WARNING  OS name 'rhel7' is deprecated, using 'rhel7.0' instead. This alias will be removed in the future.
WARNING  /root/CentOS-7-x86_64-Minimal-2003.iso may not be accessible by the hypervisor. You will need to grant the 'qemu' user search permissions for the following directories: ['/root']
ERROR    The requested volume capacity will exceed the available pool space when the volume is fully allocated. (81920 M requested capacity > 47670 M available) (Use --check disk_size=off or --check all=off to override)

 这里出现了2个错误,一个是space空间问题,一个是qemu user的问题

解决:

增加 --connect参数

[[email protected] ~]# virt-install --name=centos7 --memory=1980,maxmemory=1980  --vcpus=2,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-Minimal-2003.iso --disk path=/vms/centos7.qcow2,size=80 --connect qemu:///system  --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
WARNING  The requested volume capacity will exceed the available pool space when the volume is fully allocated. (81920 M requested capacity > 47670 M available)
WARNING  OS name 'rhel7' is deprecated, using 'rhel7.0' instead. This alias will be removed in the future.
WARNING  /root/CentOS-7-x86_64-Minimal-2003.iso may not be accessible by the hypervisor. You will need to grant the 'qemu' user search permissions for the following directories: ['/root']
ERROR    The requested volume capacity will exceed the available pool space when the volume is fully allocated. (81920 M requested capacity > 47670 M available) (Use --check disk_size=off or --check all=off to override)

 将虚拟机的硬盘大小调整到40G

[[email protected] ~]# virt-install --name=centos7 --memory=1980,maxmemory=1980  --vcpus=2,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-Minimal-2003.iso --disk path=/vms/centos7.qcow2,size=40 --connect qemu:///system  --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
WARNING  OS name 'rhel7' is deprecated, using 'rhel7.0' instead. This alias will be removed in the future.
WARNING  /root/CentOS-7-x86_64-Minimal-2003.iso may not be accessible by the hypervisor. You will need to grant the 'qemu' user search permissions for the following directories: ['/root']
WARNING  /root/CentOS-7-x86_64-Minimal-2003.iso may not be accessible by the hypervisor. You will need to grant the 'qemu' user search permissions for the following directories: ['/root']

Starting install...
Retrieving file vmlinuz...                                                                                                                      | 6.4 MB  00:00:00     
Retrieving file initrd.img...                                                                                                                   |  53 MB  00:00:00     
Allocating 'centos7.qcow2'                                                                                                                      |  40 GB  00:00:05     
ERROR    Cannot get interface MTU on 'br0': No such device
Removing disk 'centos7.qcow2'                                                                                                                   |    0 B  00:00:00     
Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
  virsh --connect qemu:///system start centos7
otherwise, please restart your installation.

没有发现网桥 br0,使用ifconfig查看

[[email protected] ~]# ifconfig  |grep br0
virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

 名字应该是virbr0

继续修改

[[email protected] ~]# mkdir -p /home/kvm
[[email protected] ~]# mv Cent* /home/kvm
[[email protected] ~]#chown -R qemu:qemu /home/kvm
[[email protected] ~]#virt-install --name=centos7 --memory=1980,maxmemory=1980  --vcpus=2,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/home/kvm/CentOS-7-x86_64-Minimal-2003.iso --disk path=/vms/centos7.qcow2,size=40 --connect qemu:///system  --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"

安装开始

Starting installer, one moment...
anaconda 21.48.22.158-1 for CentOS 7 started.
 * installation log files are stored in /tmp during the installation
 * shell is available on TTY2
 * when reporting a bug add logs from /tmp as separate text/plain attachments
11:50:35 Not asking for VNC because we don't have a network
================================================================================
================================================================================
Installation

 1) [x] Language settings                 2) [!] Time settings
        (English (United States))                (Timezone is not set.)
 3) [!] Installation source               4) [!] Software selection
        (Processing...)                          (Processing...)
 5) [!] Installation Destination          6) [x] Kdump
        (No disks selected)                      (Kdump is enabled)
 7) [ ] Network configuration             8) [!] Root password
        (Not connected)                          (Password is not set.)
 9) [!] User creation
        (No user will be created)
  Please make your choice from above ['q' to quit | 'b' to begin installation |
  'r' to refresh]: 

[anaconda] 1:main* 2:shell  3:log  4:storage-lo> Switch tab: Alt+Tab | Help: F1 






 

结束安装