1.準備環境,首先是共享存儲,這里以nfs為例:
1.1 在nfs server上配置/etc/exports權限,如下:
# cat /etc/exports /var/lib/libvirt/nfs 14.5.72.26(rw,sync,no_root_squash) /var/lib/libvirt/nfs 14.5.72.28(rw,sync,no_root_squash)
啟動nfs服務
1.2 在兩個機器上分別掛載nfs
“# mount 14.5.72.56: /var/lib/libvirt/nfs /var/lib/libvirt/nfs/”
1.3 加hosts
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 14.5.72.28 test-env-nm05-compute-14e5e72e28 14.5.72.26 test-env-nm05-compute-14e5e72e26
1.4 添加ssh免密登錄
分別在兩個節點加入public key免密登錄,因為內蒙環境不支持ssh通過輸入密碼方式登錄,所以需要配置公鑰免密訪問,配置好了以后驗證ssh是否成功。
2. 準備虛擬機
copy vm disk 到目錄nfs目錄,/var/lib/libvirt/nfs/,當前環境中網絡使用nat配置,虛擬機配置yum源與host一致 , define /start vm
[root@test-env-nm05-compute-14e5e72e26 secure]# virsh list Id Name State -------------------------------- 1 centos7_yuping running
3. 開始遷移,在節點1運行如下命令:
# virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.26:10000/system
4. 在節點2上檢查虛擬機狀態
[root@test-env-nm05-compute-14e5e72e28 ~]# virsh list --all
Id Name State
-------------------------------------
1 centos7_yuping running
如遇虛擬機高負載情況下,讓虛擬機一直有大量的臟內存存在,用上面的命令會一直卡住不能完成遷移,可以加參數--auto-converge force convergence during live migration 這個參數會降低vcpu的工作頻率,讓虛機內部產生的臟數據慢慢變少。以下是在壓力測試下遷移的命令以及所用時間。
time virsh migrate centos7_yuping --live --p2p --unsafe --persistent --undefinesource qemu+ssh://14.5.72.28:10000/system --auto-converge real 19m53.173s user 0m0.036s sys 0m0.017s
常見問題及解決辦法:
如果使用qemu+ssh遷移成功,使用qemu+tcp方式遷移報錯:
[root@test-env-nm05-compute-14e5e72e38 secure]# virsh migrate test2 --live --undefinesource --persistent --unsafe --auto-converge --p2p --tls --tls-destination 14.5.72.37 qemu+tcp://14.5.72.37/system error: operation failed: Failed to connect to remote libvirt URI qemu+tcp://14.5.72.37/system: authentication failed: authentication failed
可以用以下方式解決:
(1)修改/etc/libvirt/libvirtd.conf,添加配置 auth_tcp = "none" --否則可能出現沒有權限連接遠端的情況
(2)新版本6.9,需啟動libvirtd-tcp.socket服務(服務狀態為active且16509端被監聽)
現網一般走tcp:
libvirt打開tcp監控:
vim /etc/libvirt/libvirtd.conf
listen_tcp = 1 --老版本該參數有效,新版本中無效了,被注釋掉了。取而代之的是啟動libvirtd-tcp.socket服務即可,啟動后就會監聽16509端口。
--migrateuri tcp://{MIGRATE_NET_IP} 遷移網絡,如內存和磁盤數據流量
qemu+tcp://{DST_IP}/system 遷移控制信息走的網絡,若不指定--migrateuri,這樣數據和控制信息都走一個網絡!
libvirtd-tcp服務無法啟動的解決辦法:可參考《libvirt服務啟動配置與說明》
systemctl stop libvirtd.service 先停掉libvirtd服務
systemctl start libvirtd-tcp.socket 再啟動libvirtd-tcp服務
systemctl start libvirtd.service 再啟動libvirtd服務
systemctl status libvirtd-tcp.socket 檢查ibvirtd-tcp.socket服務狀態是否為active
netstat -anp | grep 16509 檢查是否在監聽16509端口