Centos7 Kvm 虛擬機(jī)遷移
1、虛擬機(jī)靜態(tài)遷移
#虛擬機(jī)靜態(tài)遷移兩種方式
#1、遷移vm至其他機(jī)器上運(yùn)行植酥,且無(wú)共享存儲(chǔ)
#2、遷移vm至其他機(jī)器上運(yùn)行附迷,且有共享存儲(chǔ)
#遷移vm的思路是將disk img磁盤(pán)映像文件與xml配置文件拷貝至目的主機(jī)重新定義即可
#環(huán)境中部署有共享存儲(chǔ)方案惧互,只是需要重新在目標(biāo)主機(jī)定義即可完成vm的遷移
#實(shí)驗(yàn)為無(wú)共享存儲(chǔ)方式
2、準(zhǔn)備disk img和xml配置等文件
[root@node71 ~]# virsh list
Id 名稱(chēng) 狀態(tài)
----------------------------------------------------
3 oel1 running
[root@node71 ~]# virsh domblklist oel1
目標(biāo) 源
------------------------------------------------
vda /home/data/vm/oel1/oel1_qcow2.img
vdb /home/data/vm/oel1/oel1_qcow2_1.img
[root@node71 ~]# virsh shutdown oel1
域 oel1 被關(guān)閉
[root@node71 ~]# virsh dumpxml oel1 > ./oel1.xml
#scp遠(yuǎn)程拷貝文件至目標(biāo)主機(jī)
[root@node71 ~]# scp /home/data/vm/oel1/oel1_qcow2.img root@192.168.2.110:/data/vm/oel1/
The authenticity of host '192.168.2.110 (192.168.2.110)' can't be established.
ECDSA key fingerprint is ab:ef:f7:83:53:37:da:4d:35:c0:56:0f:9e:bd:01:10.
Are you sure you want to continue connecting (yes/no)? ys
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.2.110' (ECDSA) to the list of known hosts.
root@192.168.2.110's password:
oel1_qcow2.img 100% 2690MB 41.4MB/s 01:05
[root@node71 ~]# scp /home/data/vm/oel1/oel1_qcow2_1.img root@192.168.2.110:/data/vm/oel1/
root@192.168.2.110's password:
oel1_qcow2_1.img 100% 1091MB 40.4MB/s 00:27
[root@node71 ~]# scp ./oel1.xml root@192.168.2.110:/etc/libvirt/qemu/
root@192.168.2.110's password:
oel1.xml 100% 3089 3.0KB/s 00:00
[root@node71 ~]#
3喇伯、目標(biāo)主機(jī)將遷移過(guò)來(lái)的xml配置文件重新注冊(cè)到kvm
#注冊(cè)之前喊儡,需要確認(rèn)xml當(dāng)中配置的disk路徑與實(shí)際disk 的img文件路徑是否一直,
#vi /etc/libvirt/qemu/oel1.xml
<source file='/data/vm/oel1/oel1_qcow2.img'/>
<source file='/data/vm/oel1/oel1_qcow2_1.img'/>
#重新編輯修改正確的disk路徑
#目標(biāo)主機(jī)注冊(cè)遷移虛擬機(jī)
[root@node72 ~]# virsh define /etc/libvirt/qemu/oel1.xml
定義域 oel1(從 /etc/libvirt/qemu/oel1.xml)
#啟動(dòng)vm
[root@node72 ~]# virsh start oel1
域 oel1 已開(kāi)始
#console接入vm
[root@node72 ~]# virsh console oel1
連接到域 oel1
換碼符為 ^]
mount: mount point /proc/bus/usb does not exist
Welcome to Oracle Linux Server
Starting udev: [ OK ]
Setting hostname localhost.localdomain: [ OK ]
Setting up Logical Volume Management: 2 logical volume(s) in volume group "VolGroup" now active
[ OK ]
Checking filesystems
Checking all file systems.
[/sbin/fsck.ext4 (1) -- /] fsck.ext4 -a /dev/mapper/VolGroup-lv_root
/dev/mapper/VolGroup-lv_root: clean, 23019/1215840 files, 505899/4859904 blocks
[/sbin/fsck.ext4 (1) -- /boot] fsck.ext4 -a /dev/vda1
/dev/vda1: clean, 44/128016 files, 81219/512000 blocks
[ OK ]
Remounting root filesystem in read-write mode: [ OK ]
Mounting local filesystems: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
Entering non-interactive startup
Starting monitoring for VG VolGroup: 2 logical volume(s) in volume group "VolGroup" monitored
[ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]
Starting auditd: [ OK ]
Starting system logger: [ OK ]
Starting kdump:[FAILED]
Mounting filesystems: [ OK ]
Starting acpi daemon: [ OK ]
Retrigger failed udev events[ OK ]
Starting sshd: [ OK ]
Starting postfix: [ OK ]
Starting crond: [ OK ]
Oracle Linux Server release 6.6
Kernel 3.8.13-44.1.1.el6uek.x86_64 on an x86_64
localhost.localdomain login: root
Password:
Last login: Tue Oct 25 02:58:14 on ttyS0
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:37:5f:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.134/16 brd 192.168.255.255 scope global eth0
inet6 fe80::5054:ff:fe37:5ff6/64 scope link
valid_lft forever preferred_lft forever
#測(cè)試網(wǎng)絡(luò)連通性
[root@localhost ~]# ping -c 2 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=4.74 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=48.6 ms
--- 192.168.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1063ms
rtt min/avg/max/mdev = 4.744/26.673/48.603/21.930 ms
[root@localhost ~]#
[root@node72 ~]#
#檢查KVM機(jī)器的vnc端口稻据,是否開(kāi)啟艾猜,開(kāi)啟則說(shuō)明可以vnc接入
[root@node72 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 1 *:5910 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[root@node72 ~]#
4、動(dòng)態(tài)遷移
#采用共享存儲(chǔ)的方式存放disk img映像文件
#nfs共享存儲(chǔ)
[root@node1 ~]# iptables -F
[root@node1 ~]# cat /etc/exports
/data *(rw,sync,no_root_squash)
[root@node1 ~]#
#Kvm節(jié)點(diǎn)掛載nfs共享存儲(chǔ)捻悯,掛載路徑一致
[root@node71 ~]# mount -t nfs 192.168.0.211:/data /mnt
[root@node72 ~]# mount -t nfs 192.168.0.211:/data /mnt
#兩臺(tái)KVM檢查nfs掛載后vm磁盤(pán)文件權(quán)限匆赃,貌似nobady權(quán)限也是可以
[root@node72 ~]# ll -h /mnt/vm/oel2/
總用量 2.0G
-rw-r--r-- 1 nobody nobody 2.0G 10月 26 11:18 oel2_qcow2.img
[root@node72 ~]#
#有node71運(yùn)行vm之后,將vm遷移至node72,vm的disk img存放在/mnt/vm/oel1路徑下
#檢查node71
[root@node71 ~]# virsh domblklist oel2
目標(biāo) 源
------------------------------------------------
vda /mnt/vm/oel2/oel2_qcow2.img
hda -
[root@node71 ~]# virsh list --all
Id 名稱(chēng) 狀態(tài)
----------------------------------------------------
5 oel2 running
[root@node71 ~]#
[root@node71 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 1 *:5911 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 64 *:59589 *:*
LISTEN 0 64 :::60821 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[root@node71 ~]#
#node72檢查oel2的disk 文件
#遷移過(guò)程中報(bào)錯(cuò)今缚,在啟動(dòng)虛擬機(jī)時(shí)需要關(guān)閉cache
[root@node71 ~]# virsh migrate --live oel2 qemu+ssh://192.168.2.110/system
The authenticity of host '192.168.2.110 (192.168.2.110)' can't be established.
ECDSA key fingerprint is ab:ef:f7:83:53:37:da:4d:35:c0:56:0f:9e:bd:01:10.
Are you sure you want to continue connecting (yes/no)? yes
root@192.168.2.110's password:
錯(cuò)誤:不安全的遷移:如果磁盤(pán)使用 cache != none 則遷移會(huì)導(dǎo)致數(shù)據(jù)崩潰
錯(cuò)誤:無(wú)法解析地址 'node72' 服務(wù) '49152': 未知的名稱(chēng)或服務(wù)
[root@node71 ~]#
#這里實(shí)驗(yàn)算柳,嘗試忽略錯(cuò)誤,即使不安全也嘗試遷移姓言,并且增加在hosts文件增加名稱(chēng)解析
[root@node71 ~]# cat /etc/hosts
192.168.2.111 node71
192.168.2.110 node72
[root@node71 ~]#
[root@node71 ~]# virsh migrate --live --verbose --abort-on-error --unsafe oel2 qemu+ssh://192.168.2.110/system
root@192.168.2.110's password:
遷移: [100 %]
[root@node71 ~]# virsh list --all
Id 名稱(chēng) 狀態(tài)
----------------------------------------------------
- oel2 關(guān)閉
[root@node71 ~]#
#在node72檢查瞬项,此時(shí)node72上沒(méi)有oel2的xml配置文件需要重新導(dǎo)出一份(node71上還存在)
[root@node72 ~]# virsh list --all
Id 名稱(chēng) 狀態(tài)
----------------------------------------------------
3 oel2 running
[root@node72 ~]# virsh dumpxml oel2 > /etc/libvirt/qemu/oel2.xml
[root@node72 ~]# ls /etc/libvirt/qemu/oel2.xml
/etc/libvirt/qemu/oel2.xml
[root@node72 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 64 *:40147 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 1 *:5911 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 64 :::42983 :::*
[root@node72 ~]#
#測(cè)試vnc連接無(wú)任何問(wèn)題
#且測(cè)試vm網(wǎng)絡(luò)連通性,一個(gè)PING包都不掉
virsh migrate命令幫助
[root@node71 ~]# virsh migrate --help
NAME
migrate - 將域遷移到另一個(gè)主機(jī)中
SYNOPSIS
migrate <domain> <desturi> [--live] [--offline] [--p2p] [--direct] [--tunnelled] [--persistent] [--undefinesource] [--suspend] [--copy-storage-all] [--copy-storage-inc] [--change-protection] [--unsafe] [--verbose] [--compressed] [--auto-converge] [--rdma-pin-all] [--abort-on-error] [--migrateuri <string>] [--graphicsuri <string>] [--listen-address <string>] [--dname <string>] [--timeout <number>] [--xml <string>] [--migrate-disks <string>]
DESCRIPTION
將域遷移到另一個(gè)主機(jī)中何荚。熱遷移時(shí)添加 --live囱淋。
OPTIONS
[--domain] <string> 域名,id 或 uuid
[--desturi] <string> 客戶(hù)端(常規(guī)遷移)或者源(p2p 遷移)中看到到目的地主機(jī)連接 URI
--live 熱遷移
--offline 離線遷移
--p2p 點(diǎn)對(duì)點(diǎn)遷移
--direct 直接遷移
--tunnelled 管道遷移
--persistent 目的地中的持久 VM
--undefinesource 在源中取消定義 VM
--suspend 部啟用目的地主機(jī)中的域
--copy-storage-all 使用全磁盤(pán)復(fù)制的非共享存儲(chǔ)進(jìn)行遷移
--copy-storage-inc 使用增值復(fù)制(源和目的地共享同一基礎(chǔ)映像)的非共享存儲(chǔ)進(jìn)行遷移
--change-protection 遷移結(jié)束前不得對(duì)域進(jìn)行任何配置更改
--unsafe 即使不安全也要強(qiáng)制遷移
--verbose 顯示遷移進(jìn)程
--compressed 實(shí)時(shí)遷移過(guò)程中壓縮重復(fù)的頁(yè)
--auto-converge force convergence during live migration
--rdma-pin-all support memory pinning during RDMA live migration
--abort-on-error 在遷移過(guò)程中忽略軟錯(cuò)誤
--migrateuri <string> 遷移 URI餐塘, 通惩滓拢可省略
--graphicsuri <string> 無(wú)空隙圖形遷移中使用的圖形 URI
--listen-address <string> listen address that destination should bind to for incoming migration
--dname <string> 在遷移過(guò)長(zhǎng)中重新命名為一個(gè)新名稱(chēng)(如果支持)
--timeout <number> 如果 live 遷移超時(shí)(以秒計(jì))則強(qiáng)制虛擬機(jī)掛起
--xml <string> 包含為目標(biāo)更新的 XML 的文件名
--migrate-disks <string> comma separated list of disks to be migrated
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者