KVM虛擬機器的冷遷移

尹正杰發表於2024-04-13

目錄
  • 一.KVM虛擬機器遷移概述
    • 1.什麼是遷移
    • 2.遷移的型別
  • 二.冷遷移案例之無依賴環境遷移
    • 1.案例說明
    • 2.環境準備說明
    • 3.開始遷移
  • 三.冷遷移案例之有連結克隆虛擬機器遷移
    • 1.案例說明
    • 2.環境準備說明
    • 3.開始遷移
  • 四.冷遷移案例之虛擬機器多塊磁碟遷移
    • 1.案例說明
    • 2.環境準備說明
    • 3.開始遷移
  • 五.可能會遇到的錯誤
    • 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虛擬機器遷移概述

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相關的配置檔案即可。


相關文章