Learning KVM - part 9 虛擬機(jī)熱遷移

在KVM中,您可以將運(yùn)行中的虛擬機(jī)從一個(gè)KVM主機(jī)遷移到另一個(gè)KVM主機(jī),而不需要任何停機(jī)時(shí)間。如果兩個(gè)KVM主機(jī)都能夠訪(fǎng)問(wèn)相同的存儲(chǔ)池,那么實(shí)時(shí)遷移工作就很好了。要使存儲(chǔ)池在KVM主機(jī)上都可訪(fǎng)問(wèn),您需要使用NFS或GFS2文件系統(tǒng)(集群文件系統(tǒng))。在本例中,我使用NFS文件系統(tǒng)來(lái)存儲(chǔ)VM映像。在遷移過(guò)程中,VM的“內(nèi)存”內(nèi)容將被復(fù)制到目標(biāo)KVM主機(jī),而在某個(gè)時(shí)間點(diǎn)上,將發(fā)生遷移VM。注意,當(dāng)您在KVM主機(jī)上共享文件系統(tǒng)時(shí),將不會(huì)在網(wǎng)絡(luò)上復(fù)制VM的磁盤(pán)映像,因?yàn)閮蓚€(gè)KVM主機(jī)都可以訪(fǎng)問(wèn)相同的存儲(chǔ)池。

migrate.png

虛擬機(jī)熱遷移演示

  1. 為kvm-node2安裝kvm軟件及手動(dòng)配置網(wǎng)橋br0
  2. 關(guān)閉kvm-node2的防火墻
[root@kvm-node2 ~]# iptables -F
[root@kvm-node2 ~]# systemctl stop firewalld.service 
  1. 登錄到kvm-node1上檢查vm運(yùn)行情況
 [root@kvm-node1 ~]# virsh list
 Id    Name                           State
----------------------------------------------------
 3     test                           running
  1. 打通kvm-node1到kvm-node2的ssh key通道
[root@kvm-node1 ~]# ssh-copy-id 192.168.57.202
The authenticity of host '192.168.57.202 (192.168.57.202)' can't be established.
ECDSA key fingerprint is cf:b5:cd:88:0c:05:fb:9b:b9:46:b0:c0:c4:38:cf:c1.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.57.202's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.57.202'"
and check to make sure that only the key(s) you wanted were added.

[root@kvm-node1 ~]# ssh 192.168.57.202
Last login: Wed Jun 14 16:28:06 2017 from 192.168.57.1
[root@kvm-node2 ~]# exit
logout
  1. 登錄到vm實(shí)例“test”上,長(zhǎng)ping“kvm-node1”,注意隨時(shí)觀察網(wǎng)絡(luò)是否有中斷。
[root@kvm-node1 ~]# virsh console test
Connected to domain test
Escape character is ^]

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

localhost login: root
Password: 
Last login: Wed Jun 14 17:06:02 on ttyS0
[root@localhost ~]# uptime
 17:07:12 up 2 min,  1 user,  load average: 0.15, 0.13, 0.05
[root@localhost ~]# ping 192.168.57.201
PING 192.168.57.201 (192.168.57.201) 56(84) bytes of data.
64 bytes from 192.168.57.201: icmp_seq=1 ttl=64 time=0.269 ms
64 bytes from 192.168.57.201: icmp_seq=2 ttl=64 time=0.308 ms
64 bytes from 192.168.57.201: icmp_seq=3 ttl=64 time=0.788 ms
  1. 開(kāi)始從KVM-node1上遷移vm機(jī)到KVM-node2上:
[root@kvm-node1 ~]# virsh migrate test qemu+ssh://root@192.168.57.202/system
error: Unsafe migration: Migration may lead to data corruption if disks use cache != none
  1. (⊙o⊙)哦,看起來(lái)我們沒(méi)發(fā)遷移vm,從報(bào)錯(cuò)中我們很輕易的得知,熱遷移必須配置虛擬機(jī)的磁盤(pán)使用緩存,現(xiàn)在我們來(lái)配置這個(gè)選項(xiàng):
[root@kvm-node1 ~]# virsh edit test
Domain test XML configuration edited.
############################################添加cache='none'
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
          <target dev='vda' bus='virtio'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
############################################
  1. 啟動(dòng)虛擬機(jī)后,重復(fù)步驟5,注意觀察vm是否有業(yè)務(wù)中斷
  2. 我們?cè)賮?lái)嘗試一下遷移操作,沒(méi)有輸出,O(∩_∩)O~ 通常沒(méi)有結(jié)果就是最好的結(jié)果。
[root@kvm-node1 ~]# virsh migrate test qemu+ssh://root@192.168.57.202/system

  1. 下面我們登錄到kvm-node2上檢查一下虛擬機(jī)遷移是否成功
[root@kvm-node2 ~]# virsh list
 Id    Name                           State
----------------------------------------------------
 3     test                           running
  1. 在整個(gè)遷移過(guò)程中,我們可以觀察到對(duì)虛擬機(jī)(vm)上跑的業(yè)務(wù)基本沒(méi)喲影響,我們長(zhǎng)ping的進(jìn)程僅僅只有輕微額網(wǎng)絡(luò)抖動(dòng)。當(dāng)然KVM熱遷移只適合遷移業(yè)務(wù)不繁忙的虛擬機(jī),如果業(yè)務(wù)過(guò)于繁忙,熱遷移可能由于數(shù)據(jù)同步無(wú)法達(dá)到讀寫(xiě)一致而超時(shí)失敗。
[root@localhost ~]# ping 192.168.57.201
PING 192.168.57.201 (192.168.57.201) 56(84) bytes of data.
64 bytes from 192.168.57.201: icmp_seq=1 ttl=64 time=0.457 ms
64 bytes from 192.168.57.201: icmp_seq=2 ttl=64 time=0.928 ms
64 bytes from 192.168.57.201: icmp_seq=3 ttl=64 time=0.795 ms
64 bytes from 192.168.57.201: icmp_seq=4 ttl=64 time=0.683 ms
64 bytes from 192.168.57.201: icmp_seq=5 ttl=64 time=0.374 ms
64 bytes from 192.168.57.201: icmp_seq=6 ttl=64 time=0.584 ms
64 bytes from 192.168.57.201: icmp_seq=7 ttl=64 time=0.253 ms
64 bytes from 192.168.57.201: icmp_seq=8 ttl=64 time=0.667 ms
64 bytes from 192.168.57.201: icmp_seq=9 ttl=64 time=0.297 ms
64 bytes from 192.168.57.201: icmp_seq=10 ttl=64 time=0.268 ms
64 bytes from 192.168.57.201: icmp_seq=11 ttl=64 time=0.757 ms
64 bytes from 192.168.57.201: icmp_seq=12 ttl=64 time=0.193 ms
64 bytes from 192.168.57.201: icmp_seq=13 ttl=64 time=0.234 ms
64 bytes from 192.168.57.201: icmp_seq=14 ttl=64 time=0.298 ms
64 bytes from 192.168.57.201: icmp_seq=15 ttl=64 time=0.289 ms
64 bytes from 192.168.57.201: icmp_seq=16 ttl=64 time=0.171 ms
64 bytes from 192.168.57.201: icmp_seq=17 ttl=64 time=0.754 ms
64 bytes from 192.168.57.201: icmp_seq=18 ttl=64 time=0.731 ms
64 bytes from 192.168.57.201: icmp_seq=19 ttl=64 time=0.371 ms
64 bytes from 192.168.57.201: icmp_seq=20 ttl=64 time=2.05 ms    # 輕微的網(wǎng)絡(luò)抖動(dòng)
64 bytes from 192.168.57.201: icmp_seq=21 ttl=64 time=0.359 ms
64 bytes from 192.168.57.201: icmp_seq=22 ttl=64 time=0.662 ms
64 bytes from 192.168.57.201: icmp_seq=23 ttl=64 time=0.555 ms
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • root@softwareluke-Lenovo:/home/softwareluke# virt-manager...
    燕京博士閱讀 813評(píng)論 0 0
  • 目的 使用網(wǎng)橋模式,將多臺(tái)linux虛擬機(jī)/物理主機(jī)橋接。同時(shí)保證虛擬機(jī)和宿主機(jī)器及局域網(wǎng)內(nèi)其他主機(jī)進(jìn)行通信。最后...
    W_Bousquet閱讀 4,039評(píng)論 0 1
  • 本文整理了在實(shí)踐過(guò)程中使用的Linux網(wǎng)絡(luò)工具,這些工具提供的功能非常強(qiáng)大,我們平時(shí)使用的只是冰山一角,比如lso...
    老夫劉某閱讀 3,821評(píng)論 0 7
  • 0.遠(yuǎn)程桌面連接mstsc1.打開(kāi)服務(wù)列表 services.msc2.刪除服務(wù) sc...
    請(qǐng)叫我四爺閱讀 929評(píng)論 0 1
  • 當(dāng)一口氣看完這本書(shū),合起來(lái)的時(shí)候,我感嘆道,這本書(shū)確實(shí)很偉大,然而,我習(xí)慣性的看完?yáng)|西后會(huì)看看豆瓣上其他人的想法。...
    道哥的道閱讀 610評(píng)論 0 1

友情鏈接更多精彩內(nèi)容