1. 程式人生 > >openstack遷移雲主機總匯其一(雲主機熱遷移)

openstack遷移雲主機總匯其一(雲主機熱遷移)

openstack 雲主機熱遷移

openstack遷移總匯

目錄

1 熱遷移之block-migration

1.1 查看物理主機CPU

1.2 修改hosts文件

1.3 開啟熱遷移

1.4 修改防火墻

1.5 virsh測試是否可以連通對端機器

1.5.1 方法1

1.5.2 方法2

1.6 遷移情況

1.7 下面的作為參考

1.7.1 主機

1.7.2 各節點之間nova賬號無密碼訪問

1.7.3 可選操作

1.8 註意事項

1.8.1 事項1

1.8.2

事項2

2 冷遷移

2.1 方法1

2.1.1 YUN-19上,修改數據庫

2.1.2 實例文件拷貝

2.1.3 查看文件

2.1.4 新建與遷移的實例關聯的網橋

2.2 方法2

2.2.1 轉換鏡像格式

2.2.2 查看鏡像信息

2.2.3 幾種鏡像格式的比較:

2.2.4 註意事項

2.2.5 把鏡像disk4拷貝到YUN-19

2.2.6 linux實例做遷移

2.2.7 補充一

2.2.8

補充二

3 參考文檔

1 熱遷移之block-migration

1.1 查看物理主機CPU

# cat /proc/cpuinfo |grep name |cut -f2 -d:|uniq -c

YUN-11YUN-12(主機名)

32 Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz

YUN-13YUN-14

64 Intel(R) Xeon(R) CPU E7- 4830 @ 2.13GHz

test-compute

8 Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz

還有後來添加的主機YUN-17

192 Intel(R) Xeon(R) CPU E7-8850 v2 @ 2.30GHz

1.2 修改hosts文件

(每個遷移涉及的節點上都做此操作)

# vi /etc/hosts

添加

192.168.0.11 YUN-11

192.168.0.12 YUN-12

192.168.0.13 YUN-13

192.168.0.14 YUN-14

192.168.0.126 test-compute

192.168.0.17 YUN-17

1.3 開啟熱遷移

(每個遷移涉及的節點上都做此操作)

# vi /etc/nova/nova.conf

# Migration flags to be set for live migration (string value)

#live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER

to

# Migration flags to be set for live migration (string value)

live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_UNSAFE

1.4 修改防火墻

# vi /etc/sysconfig/iptables

修改之前的防火墻配置

YUN-11防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.11" -j ACCEPT

YUN-12防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.13" -j ACCEPT

YUN-13防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.13" -j ACCEPT

YUN-14的防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.14" -j ACCEPT

測試機的防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.126" -j ACCEPT

YUN-17的防火墻

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 5900:5999,16509 -m comment --comment "001 nova compute incoming nova_compute" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.17" -j ACCEPT

修改之後的防火墻配置

YUN-11

添加

# by sxzhou-

A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.13" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.14" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.126" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.11_192.168.0.17" -j ACCEPT

YUN-12

添加

# by sxzhou

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.11" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.14" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.126" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.12_192.168.0.17" -j ACCEPT

YUN-13

添加

# by sxzhou

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.11" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.14" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.126" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.13_192.168.0.17" -j ACCEPT

YUN-14

添加

# by sxzhou -A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.11" -j ACCEPT

-A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.13" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.126" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.14_192.168.0.17" -j ACCEPT

測試機

添加

# by sxzhou

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.11" -j ACCEPT

-A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.13" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.14" -j ACCEPT

-A INPUT -s 192.168.0.17/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.126_192.168.0.17" -j ACCEPT

YUN-17

添加

# by sxzhou

-A INPUT -s 192.168.0.11/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.11" -j ACCEPT

-A INPUT -s 192.168.0.12/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.12" -j ACCEPT

-A INPUT -s 192.168.0.13/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.13" -j ACCEPT

-A INPUT -s 192.168.0.14/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.14" -j ACCEPT

-A INPUT -s 192.168.0.126/32 -p tcp -m multiport --dports 16509,49152:49215 -m comment --comment "001 nova qemu migration incoming nova_qemu_migration_192.168.0.17_192.168.0.126" -j ACCEPT

保存退出後記得重啟防火墻的服務

1.5 virsh測試是否可以連通對端機器

(要測試其余每臺機器)

兩種測試方式:

YUN-11為例,測試與YUN-12的連通性

1.5.1 方法1

YUN-11主機上

virsh # connect qemu+tcp://192.168.0.12/system

正常情況下將列出YUN-12上的實例

下面是異常情況

virsh # connect qemu+tcp://192.168.0.12/system

error: Failed to connect to the hypervisor

error: unable to connect to server at '192.168.0.13:16509': No route to host

異常情況的話就要查看上面所述的配置是否有誤

1.5.2 方法2

# virsh

virsh # connect qemu+tcp://192.168.0.12/system

查看主機名確認

virsh # hostname

YUN-12

1.6 遷移情況

dash中選擇【管理員】-【實例】,在要遷移的主機後面點擊下拉菜單,再點擊“實例熱遷移”,再選擇“塊遷移”

YUN-11可以遷移到YUN-12YUN-17

YUN-12可以遷移到YUN-17

YUN-13可以遷移到YUN-12test-compute

YUN-13可以遷移到YUN-12test-compute

test-compute可以遷移到YUN-12

YUN-17不可以遷移

註:

其他機器無法遷移到YUN-11YUN-13的原因是這兩臺機器的磁盤空間被超量使用

從上面的測試可以分析出各主機遷移CPU的優先級

YUN-17 < YUN-13YUN-14 < YUN-126 < YUN-11YUN-12

當遷移失敗,並且在日誌文件中查看到下面所示的出錯信息時,就說明兩臺節點的物理資源不匹配

InvalidCPUInfo: Unacceptable CPU info: CPU doesn't have compatibility.

查看的日誌主要有控制節點的/var/log/nova/api.log和計算節點的/var/log/nova/compute.log

1.7 下面的作為參考

在剛開始的遷移測試中,是這樣的

操作對象:

1.7.1 主機

主機IP 主機名 角色

192.168.0.11 YUN-11 控制節點

192.168.0.12 YUN-12 擴展節點

192.168.0.126 test-compute 測試機

註意:本測驗是雖然以控制節點為例,但是每臺涉及遷移的主機都要做操作

1.7.2 各節點之間nova賬號無密碼訪問

1.7.2.1 在各個需要相互無密碼訪問節點上做以下操作

# usermod -s /bin/bash nova

# su nova

$ cd

$ ssh-keygen

$ touch .ssh/authorized_keys

1.7.2.2 把其他節點的公鑰拷貝過來,追加到本地的認證文件中

以控制節點為例

$ scp root@192.168.0.12:/var/lib/nova/.ssh/id_rsa.pub .

$ cat id_rsa.pub >> .ssh/authorized_keys

$ scp root@192.168.0.126:/var/lib/nova/.ssh/id_rsa.pub .

$ cat id_rsa.pub >> .ssh/authorized_keys

之後兩個擴展節點就能夠利用nova用戶無密碼訪問控制節點了

依照這種方法在其他節點做類似操作,最終就會實現各節點之間nova用戶的無密碼訪問

1.7.3 可選操作

【可選,確認即可】網上文檔上做了修改,但是本集群按默認配置

1.7.3.1 編輯/etc/nova/nova.conf

如果希望可以在Dashboard裏設置root的密碼

inject_password=true

修改虛擬機配置,不需要遷移

allow_resize_to_same_host=true

(可選)

遷移和修改配置,不需要手工確認,1表示1秒的時間讓你確認,如果沒確認就繼續

resize_confirm_window=1

重啟服務

service openstack-nova-compute restart

1.7.3.2 熱遷移(block-migration

所有的節點上修改nova.conf

live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE,VIR_MIGRATE_UNSAFE

開啟熱遷移功能

【確認即可,此處也按系統默認配置】

然後需要配置versh免密碼連接,修改/etc/libvirt/libvirtd.conf

去掉註釋

listen_tls = 0

listen_tcp = 1

去掉註釋並修改值

auth_tcp = none# 註意這裏必須設為none,否則需要認證。

測試下:

virsh --connect qemu+tcp://192.168.0.12/system list

virsh --connect qemu+tcp://192.168.0.126/system list

如果不需要輸入用戶名和密碼就能夠列出所有的虛擬機,則表示配置成功。

重啟所有計算節點nova-compute libvirt-bin服務

此時就可以使用novaclient命令進行遷移,比如要把vm1從測試機遷移到YUN-12,

nova live-migration --block-migrate vm1 YUN-12

註意選項--block-migrate是必要的,否則默認以共享存儲的方式遷移,另外需要在控制節點做/etc/hosts文件主機名和IP的解析

測試遷移【事實證明防火墻不可以關閉】

測試遷移並沒有成功,在關閉YUN-12test-compute防火墻後再次測試,遷移成功。需要註意的是控制節點關閉防火墻失敗

1.8 註意事項

1.8.1 事項1

需要註意的是做熱遷移的過程中發現,關閉各節點防火墻就可以做遷移(不做修改防火墻的步驟),但是整個集群出現異常,各節點不能夠創建實例,所以對於各節點的防火墻不能關閉,只能做策略。

1.8.2 事項2

nova用戶無密碼訪問是否需要做還不太明確,在剛開始的測試中都是做的,就是上面提到的三臺機器,不過在後來的試驗中,不斷有新加進來測試的機器都沒有做,所以應該是不需要。


openstack遷移雲主機總匯其一(雲主機熱遷移)