准备虚拟机

    安装虚拟机,会依赖相关工具,安装依赖并使能 libvirtd 服务的参考命令如下(如果需要代理,请先配置代理):

    1. $ virsh pool-define-as vmPool --type dir --target /mnt/vm/images/
    2. $ virsh pool-build vmPool
    3. $ virsh pool-start vmPool
    4. $ virsh pool-autostart vmPool
    5. $ virsh vol-create-as --pool vmPool --name master0.img --capacity 200G --allocation 1G --format qcow2
    6. $ virsh vol-create-as --pool vmPool --name master1.img --capacity 200G --allocation 1G --format qcow2
    7. $ virsh vol-create-as --pool vmPool --name master2.img --capacity 200G --allocation 1G --format qcow2
    8. $ virsh vol-create-as --pool vmPool --name node1.img --capacity 300G --allocation 1G --format qcow2
    9. $ virsh vol-create-as --pool vmPool --name node2.img --capacity 300G --allocation 1G --format qcow2
    10. $ virsh vol-create-as --pool vmPool --name node3.img --capacity 300G --allocation 1G --format qcow2

    方法一

    1. 查询端口

      1. $ netstat -lntup | grep qemu-kvm

    方法二

    直接关闭防火墙

    1. $ systemctl stop firewalld

    创建虚拟机需要虚拟机配置文件。假设配置文件为 master.xml ,以虚拟机 hostname 为 k8smaster0 的节点为例,参考配置如下:

    1. cat master.xml
    2. <domain type='kvm'>
    3. <name>k8smaster0</name>
    4. <memory unit='GiB'>8</memory>
    5. <vcpu>8</vcpu>
    6. <os>
    7. <loader readonly='yes' type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw</loader>
    8. <nvram>/var/lib/libvirt/qemu/nvram/k8smaster0.fd</nvram>
    9. </os>
    10. <acpi/>
    11. <gic version='3'/>
    12. </features>
    13. <cpu mode='host-passthrough'>
    14. <topology sockets='2' cores='4' threads='1'/>
    15. </cpu>
    16. <iothreads>1</iothreads>
    17. <clock offset='utc'/>
    18. <on_poweroff>destroy</on_poweroff>
    19. <on_reboot>restart</on_reboot>
    20. <on_crash>restart</on_crash>
    21. <devices>
    22. <emulator>/usr/libexec/qemu-kvm</emulator>
    23. <disk type='file' device='disk'>
    24. <driver name='qemu' type='qcow2' iothread="1"/>
    25. <source file='/mnt/vm/images/master0.img'/>
    26. <target dev='vda' bus='virtio'/>
    27. <boot order='1'/>
    28. </disk>
    29. <disk type='file' device='cdrom'>
    30. <driver name='qemu' type='raw'/>
    31. <source file='/mnt/openEuler-21.09-everything-aarch64-dvd.iso'/>
    32. <readonly/>
    33. <boot order='2'/>
    34. </disk>
    35. <interface type='network'>
    36. <mac address='52:54:00:00:00:80'/>
    37. <source network='default'/>
    38. <model type='virtio'/>
    39. </interface>
    40. <console type='pty'/>
    41. <video>
    42. <model type='virtio'/>
    43. </video>
    44. <controller type='scsi' index='0' model='virtio-scsi'/>
    45. <controller type='usb' model='ehci'/>
    46. <input type='tablet' bus='usb'/>
    47. <input type='keyboard' bus='usb'/>
    48. <graphics type='vnc' listen='0.0.0.0'/>
    49. </devices>
    50. <seclabel type='dynamic' model='dac' relabel='yes'/>
    51. </domain>
    • name:虚拟机 hostname,建议尽量小写。例中为 k8smaster0
    • nvram:nvram的句柄文件路径,需要全局唯一。例中为 /var/lib/libvirt/qemu/nvram/k8smaster0.fd
    • disk 的 source file:虚拟机磁盘文件路径。例中为 /mnt/vm/images/master0.img
    • interface 的 mac address:interface 的 mac 地址。例中为 52:54:00:00:00:80
    1. 创建并启动虚拟机

    2. 获取虚拟机的 VNC 端口号

    3. 使用虚拟机链接工具,例如 VNC Viewer 远程链接虚拟机,并根据提示依次选择配置,完成系统安装