一.KVM虚拟机迁移概述

1.什么是迁移

所谓的迁移就是将一个宿主机的虚拟机迁移到另外一台宿主机运行的过程。


为什么需要迁移:
    - 比如宿主机的资源不足,迁移到其他节点以实现给虚拟机更多资源的情况;
    - 再比如,宿主机的资源利用率过低,将一些利用率低的宿主机的虚拟机进行合并的场景;

2.迁移的类型

冷迁移:
    将虚拟机关机,然后将配置文件和磁盘文件拷贝到另一台KVM宿主机上重启启动的过程。

热迁移:
    在不关闭KVM虚拟机的情况下,迁移KVM宿主机内的相应的虚拟机到其他KVM宿主机的过程。

二.冷迁移案例之无依赖环境迁移

1.案例说明

指的是虚拟机的配置文件和磁盘文件都是独立的个体,虚拟机之间没有任何冲突。

2.环境准备说明

    1.KVM宿主机源节点环境
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     yinzhengjie-kvm01              running

[root@yinzhengjie-kvm189 ~]# 


    2.KVM宿主机目标节点环境
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------

[root@yinzhengjie-kvm190 ~]#

3.开始迁移

    1.关闭KVM虚拟机
[root@yinzhengjie-kvm189 ~]# virsh destroy yinzhengjie-kvm01 
Domain yinzhengjie-kvm01 destroyed

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     yinzhengjie-kvm01              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh domblklist yinzhengjie-kvm01  # 查看虚拟机所对应的磁盘文件路径 
Target     Source
------------------------------------------------
vda        /opt/yinzhengjie-kvm01.qcow2
hda        -

[root@yinzhengjie-kvm189 ~]# 



    2.拷贝KVM虚拟机的配置文件和磁盘文件到目标节点
[root@yinzhengjie-kvm189 ~]# scp /opt/yinzhengjie-kvm01.qcow2 yinzhengjie-kvm190:/opt/
[root@yinzhengjie-kvm189 ~]# scp /etc/libvirt/qemu/yinzhengjie-kvm01.xml yinzhengjie-kvm190:/opt/


    3.目标节点导入虚拟机
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# ll /opt/
total 15089480
-rw-r--r--. 1 qemu qemu  4712300544 Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
drwxr-xr-x. 2 root root           6 Oct 31  2018 rh
-rw-------. 1 root root 10739318784 Apr 14 04:16 yinzhengjie-kvm01.qcow2
-rw-------. 1 root root        4270 Apr 14 04:17 yinzhengjie-kvm01.xml
[root@yinzhengjie-kvm190 ~]#        
[root@yinzhengjie-kvm190 ~]# virsh define /opt/yinzhengjie-kvm01.xml 
Domain yinzhengjie-kvm01 defined from /opt/yinzhengjie-kvm01.xml

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     yinzhengjie-kvm01              shut off

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# 


    4.模板节点启动虚拟机并测试
[root@yinzhengjie-kvm190 ~]# virsh start yinzhengjie-kvm01 
Domain yinzhengjie-kvm01 started

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     yinzhengjie-kvm01              running

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]#  
[root@yinzhengjie-kvm190 ~]# virsh console yinzhengjie-kvm01 
Connected to domain yinzhengjie-kvm01
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-1160.el7.x86_64 on an x86_64

yinzhengjie-kvm01 login: root
Password: 
Last login: Wed Apr 10 21:44:24 on ttyS0
[root@yinzhengjie-kvm01 ~]# 
[root@yinzhengjie-kvm01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@yinzhengjie-kvm01 ~]#

三.冷迁移案例之有链接克隆虚拟机迁移

1.案例说明

迁移的虚拟机是一个克隆的机器,如果仅迁移克隆的虚拟机不迁移基于克隆的主机则迁移后无法启动的情况。

举个例子:
    创建一个模板机"yinzhengjie-kvm02",基于"yinzhengjie-kvm02"克隆一个"yinzhengjie-kvm03"的虚拟机,然后将"yinzhengjie-kvm03"虚拟机迁移。

2.环境准备说明

    1.KVM宿主机源节点完整克隆一台虚拟机
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     yinzhengjie-kvm01              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ll -h /opt/
total 6.0G
-rw-r--r--. 1 qemu qemu 4.4G Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
drwxr-xr-x. 2 root root    6 Oct 31  2018 rh
-rw-------. 1 root root  11G Apr 14 04:08 yinzhengjie-kvm01.qcow2
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virt-clone -o yinzhengjie-kvm01 -n yinzhengjie-kvm02 --auto-clone
Allocating 'yinzhengjie-kvm02.qcow2'                                                                |  10 GB  00:00:02     

Clone 'yinzhengjie-kvm02' created successfully.
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ll -h /opt/
total 8.0G
-rw-r--r--. 1 qemu qemu 4.4G Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
drwxr-xr-x. 2 root root    6 Oct 31  2018 rh
-rw-------. 1 root root  11G Apr 14 04:08 yinzhengjie-kvm01.qcow2
-rw-------. 1 root root 1.6G Apr 14 05:16 yinzhengjie-kvm02.qcow2
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 




    2.基于"yinzhengjie-kvm02"创建链接克隆的虚拟机"k8s-master231"
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ./yinzhengjie-clone_qcow2_VM.sh c yinzhengjie-kvm02 k8s-master231
Formatting '/opt/k8s-master231.qcow2', fmt=qcow2 size=10737418240 backing_file='/opt/yinzhengjie-kvm02.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
Domain k8s-master231 defined from /tmp/k8s-master231.xml

Domain k8s-master231 started

尹正杰编写脚本: yinzhengjie-kvm02 虚拟机克隆成功[successfully]
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 8     k8s-master231                  running
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ll -h /opt/
total 7.5G
-rw-r--r--. 1 qemu qemu 4.4G Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
-rw-r--r--. 1 qemu qemu 7.8M Apr 14 05:22 k8s-master231.qcow2
drwxr-xr-x. 2 root root    6 Oct 31  2018 rh
-rw-------. 1 root root  11G Apr 14 04:08 yinzhengjie-kvm01.qcow2
-rw-------. 1 qemu qemu 1.6G Apr 14 05:16 yinzhengjie-kvm02.qcow2
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh console k8s-master231 
Connected to domain k8s-master231
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-1160.el7.x86_64 on an x86_64

yinzhengjie-kvm01 login: root
Password: 
Last login: Wed Apr 10 21:44:24 on ttyS0
[root@yinzhengjie-kvm01 ~]# 
[root@yinzhengjie-kvm01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@yinzhengjie-kvm01 ~]# 



    3.KVM宿主机目标节点环境
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     yinzhengjie-kvm01              running

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh destroy yinzhengjie-kvm01 
Domain yinzhengjie-kvm01 destroyed

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh undefine yinzhengjie-kvm01 
Domain yinzhengjie-kvm01 has been undefined

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# ll /opt/
total 15089480
-rw-r--r--. 1 qemu qemu  4712300544 Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
drwxr-xr-x. 2 root root           6 Oct 31  2018 rh
-rw-------. 1 root root 10739318784 Apr 14 04:26 yinzhengjie-kvm01.qcow2
-rw-------. 1 root root        4270 Apr 14 04:17 yinzhengjie-kvm01.xml
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# rm -f /opt/yinzhengjie-kvm01.*
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# ll /opt/
total 4601856
-rw-r--r--. 1 qemu qemu 4712300544 Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
drwxr-xr-x. 2 root root          6 Oct 31  2018 rh
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------

[root@yinzhengjie-kvm190 ~]#

3.开始迁移

    1.拷贝虚拟机的配置文件和磁盘文件到另一个节点(拷贝时需要将yinzhengjie-kvm02虚拟机的磁盘文件一起拷贝过去哟~)
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 8     k8s-master231                  running
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh destroy k8s-master231 
Domain k8s-master231 destroyed

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# scp /etc/libvirt/qemu/k8s-master231.xml /opt/{k8s-master231,yinzhengjie-kvm02}.qcow2 yinzhengjie-kvm190:/opt/
root@yinzhengjie-kvm190's password: 
k8s-master231.xml                                                                        100% 4258     1.9MB/s   00:00    
k8s-master231.qcow2                                                                      100% 9536KB  87.7MB/s   00:00    
yinzhengjie-kvm02.qcow2                                                                  100% 1547MB 143.7MB/s   00:10    
[root@yinzhengjie-kvm189 ~]# 



    2.另一个节点启动虚拟机
[root@yinzhengjie-kvm190 ~]# ll -h /opt/
total 6.0G
-rw-r--r--. 1 qemu qemu 4.4G Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
-rw-r--r--. 1 root root 9.4M Apr 14 05:25 k8s-master231.qcow2
-rw-------. 1 root root 4.2K Apr 14 05:25 k8s-master231.xml
drwxr-xr-x. 2 root root    6 Oct 31  2018 rh
-rw-------. 1 root root 1.6G Apr 14 05:26 yinzhengjie-kvm02.qcow2
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh define /opt/k8s-master231.xml 
Domain k8s-master231 defined from /opt/k8s-master231.xml

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh start k8s-master231 
Domain k8s-master231 started

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 8     k8s-master231                  running

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh console k8s-master231 
Connected to domain k8s-master231
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-1160.el7.x86_64 on an x86_64

yinzhengjie-kvm01 login: root
Password: 
Last login: Sun Apr 14 05:23:08 on ttyS0
[root@yinzhengjie-kvm01 ~]# 
[root@yinzhengjie-kvm01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@yinzhengjie-kvm01 ~]#

四.冷迁移案例之虚拟机多块磁盘迁移

1.案例说明

一块虚拟机可能有多块虚拟磁盘,我们在迁移虚拟机时,要将该虚拟机的所有磁盘都得拷贝走。

2.环境准备说明

    1.连接克隆虚拟机
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ./yinzhengjie-clone_qcow2_VM.sh c yinzhengjie-kvm02 k8s-worker232
Formatting '/opt/k8s-worker232.qcow2', fmt=qcow2 size=10737418240 backing_file='/opt/yinzhengjie-kvm02.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 
Domain k8s-worker232 defined from /tmp/k8s-worker232.xml

Domain k8s-worker232 started

尹正杰编写脚本: yinzhengjie-kvm02 虚拟机克隆成功[successfully]
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 9     k8s-worker232                  running
 -     k8s-master231                  shut off
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 



    2.给链接克隆的虚拟机添加一块磁盘
[root@yinzhengjie-kvm189 ~]# virsh domblklist k8s-worker232 
Target     Source
------------------------------------------------
vda        /opt/k8s-worker232.qcow2
hda        -

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# qemu-img create -f qcow2 /opt/k8s-worker232_add_disk01.qcow2 20G
Formatting '/opt/k8s-worker232_add_disk01.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off 
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# ll -h /opt/k8s-worker232_add_disk01.qcow2 
-rw-r--r--. 1 root root 193K Apr 14 05:55 /opt/k8s-worker232_add_disk01.qcow2
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh attach-disk k8s-worker232 /opt/k8s-worker232_add_disk01.qcow2 vdb --subdriver qcow2 --config
Disk attached successfully

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh domblklist k8s-worker232 
Target     Source
------------------------------------------------
vda        /opt/k8s-worker232.qcow2
vdb        /opt/k8s-worker232_add_disk01.qcow2
hda        -

[root@yinzhengjie-kvm189 ~]#

3.开始迁移

    1.拷贝磁盘文件和配置文件到其他KVM宿主机节点
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 9     k8s-worker232                  running
 -     k8s-master231                  shut off
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh destroy k8s-worker232 
Domain k8s-worker232 destroyed

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off
 -     k8s-worker232                  shut off
 -     yinzhengjie-kvm01              shut off
 -     yinzhengjie-kvm02              shut off

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# virsh domblklist k8s-worker232 
Target     Source
------------------------------------------------
vda        /opt/k8s-worker232.qcow2
vdb        /opt/k8s-worker232_add_disk01.qcow2
hda        -

[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# scp /etc/libvirt/qemu/k8s-worker232.xml /opt/k8s-worker232{,_add_disk01}.qcow2 yinzhengjie-kvm190:/opt/
root@yinzhengjie-kvm190's password: 
k8s-worker232.xml                                                                        100% 4258     1.9MB/s   00:00    
k8s-worker232.qcow2                                                                      100% 9536KB  73.0MB/s   00:00    
k8s-worker232_add_disk01.qcow2                                                           100%  193KB  45.2MB/s   00:00    
[root@yinzhengjie-kvm189 ~]# 
[root@yinzhengjie-kvm189 ~]# 


    2.KVM宿主机验证迁移后的节点并验证
[root@yinzhengjie-kvm190 ~]# ll -h /opt/
total 6.0G
-rw-r--r--. 1 qemu qemu 4.4G Apr  9 01:25 CentOS-7-x86_64-DVD-2009.iso
-rw-r--r--. 1 root root 9.5M Apr 14 05:28 k8s-master231.qcow2
-rw-------. 1 root root 4.2K Apr 14 05:25 k8s-master231.xml
-rw-r--r--. 1 root root 193K Apr 14 06:00 k8s-worker232_add_disk01.qcow2
-rw-r--r--. 1 root root 9.4M Apr 14 06:00 k8s-worker232.qcow2
-rw-------. 1 root root 4.5K Apr 14 06:00 k8s-worker232.xml
drwxr-xr-x. 2 root root    6 Oct 31  2018 rh
-rw-------. 1 qemu qemu 1.6G Apr 14 05:26 yinzhengjie-kvm02.qcow2
[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh define /opt/k8s-worker232.xml
Domain k8s-worker232 defined from /opt/k8s-worker232.xml

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     k8s-master231                  shut off
 -     k8s-worker232                  shut off

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh start k8s-worker232 
Domain k8s-worker232 started

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 13    k8s-worker232                  running
 -     k8s-master231                  shut off

[root@yinzhengjie-kvm190 ~]# 
[root@yinzhengjie-kvm190 ~]# virsh console k8s-worker232 
Connected to domain k8s-worker232
Escape character is ^]

CentOS Linux 7 (Core)
Kernel 3.10.0-1160.el7.x86_64 on an x86_64

yinzhengjie-kvm01 login: root
Password: 
Last login: Wed Apr 10 21:44:24 on ttyS0
[root@yinzhengjie-kvm01 ~]# 
[root@yinzhengjie-kvm01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@yinzhengjie-kvm01 ~]#

五.可能会遇到的错误

1.error: Cannot access backing file '/opt/yinzhengjie-kvm02.qcow2' of storage file '/opt/k8s-master231.qcow2' (as uid:107, gid:107): No such file or directory

错误原因:
    缺少源虚拟机的磁盘文件导致链接克隆的虚拟机无法正常启动。

解决方案:
    需要将缺失的磁盘文件拷贝到相应的路径即可。

2.error: Cannot access storage file '/opt/k8s-worker232_add_disk01.qcow2' (as uid:107, gid:107): No such file or directory

错误原因:
    缺少磁盘文件导致的报错。

解决方案:
    需要将缺失的磁盘文件拷贝到相应的路径即可。

3."KVM cpu feature tsc_adjust not found ..."

错误原因:
    表示KVM虚拟机在启动时检测到宿主机的CPU不支持TSC校准特性(Time Stamp Counter Adjust),而这个特性对于KVM来说是必须的。
    TSC_ADJUST是Intel处理器的一个特性,用于在宿主机上调整时间戳计数器(Time Stamp Counter, TSC)的速度,以保持与其他时钟源同步。

解决方法:
    - 升级宿主机的CPU固件到最新版本,以支持TSC校准特性。
    - 如果是在虚拟环境中,确保宿主机的虚拟化软件(如KVM、Hyper-V等)支持不带TSC校准特性的虚拟机。
    - 如果不需要在虚拟机中使用高精度计时功能,可以在虚拟机的配置中去掉对TSC精度的要求。
    - 如果是在虚拟机管理程序中,确保宿主机的CPU支持VT-x,并且在BIOS/UEFI中启用了Intel虚拟化技术(Intel VT-x, EPT等)。
    - 请注意,如果宿主机的CPU不支持TSC_ADJUST特性,而虚拟机依赖此特性,虚拟机可能无法正常启动。因此,解决方案可能需要更新宿主机的硬件或者配置。


温馨提示:
    这种情况一般都是服务器硬件异构情况才会出现的,比如intet系列的CPU迁移到ADM系列的CPU可能就会遇到类似的问题。不同CPU型号执行"lscpu"支持的指令集不尽相同。
    如果工作中真的遇到这样的坑,解决思路如下。
        现象假设:
            你要迁移的新虚拟机"k8s-worker232"到新节点但无法运行,因为CPU特性不支持,目前新节点正常运行的虚拟机为"k8s-master231"。
        解决思路:
            - 在新节点执行"virsh dumpxml k8s-master231"获取一个虚拟机的XML文件找到CPU相关的配置;
            - 使用上一步骤k8s-master231节点的CPU相关的配置覆盖掉原来的"k8s-worker232"虚拟机的XML虚拟机配置文件;
            - 然后基于修改后的XML文件启动即可;
            - 对了,顺便说一句,如果新节点没有运行的虚拟机,那就手动创建一个测试的虚拟机,拿到测试虚拟机的CPU相关的配置文件即可。

转自:https://www.cnblogs.com/yinzhengjie/p/18133506

Copyright © https://yan-jian.com 2023 all right reserved更新时间: 2024-05-15 14:09:40

results matching ""

    No results matching ""