VMware ESXi虚拟机迁移到OpenStack平台

2024-05-22 08:49:03 浏览数 (4)

因为某些原因公司需要吧VMware Esxi 虚拟机迁移到OpenStack平台,下面描述一下迁移步骤

条件需求

迁移 vmware esxi虚拟机:

IP:10.10.235.250

**机器在Esxi的名称:**yum-运维-[10.10.235.250]

所在宿主机ip: 10.10.233.11

迁移方式:冷迁移,需要提前关闭对应虚拟机。

需提前准备好该虚拟机所在物理机Esxi的账号密码。

OpenStack操作节点:

ip地址:10.10.214.11

主机名:szsjhl-control-test-10-10-214-11-vm.belle.lan

迁移步骤:

查看vmware esxi宿主机上所有的虚拟机列表

开启Esxi宿主机ssh,在10.10.214.11上面执行:virsh -c esx://root@宿主机IP?no_verify=1 list --all

代码语言:javascript复制
# virsh -c esx://root@10.10.233.11?no_verify=1 list --all
2023-05-30 04:02:02.573 0000: 12546: info : libvirt version: 4.5.0, package: 36.el7_9.5 (CentOS BuildSystem <http://bugs.centos.org>, 2021-04-28-13:32:22, x86-01.bsys.centos.org)
2023-05-30 04:02:02.573 0000: 12546: info : hostname: szsjhl-control-test-10-10-214-11-vm.belle.lan
2023-05-30 04:02:02.573 0000: 12546: warning : esxConnectOpen:857 : Ignoring unexpected path '' for non-vpx scheme 'esx'
Enter root's password for 10.10.233.11: 
 Id    Name                           State
----------------------------------------------------
 -     yum-[10.10.235.250]     shut off   <==需要迁移的虚拟机
 -     admin-server-[10.10.235.14]-2023.04.18 shut off
 -     eaas-basecore-[10.10.235.107]-2023.04.22 shut off
 -     eaas-eafweb-[10.10.235.105]-2023.04.22 shut off
 -     mycat-[10.10.234.23]-2023.04.26 shut off
 -     order-[10.10.235.164]-2023.04.26 shut off
 -     order-[10.10.235.27]-2023.04.18 shut off
 -     order-[10.10.235.32]-2023.04.18 shut off
 -     pay-[10.10.235.58]-2023.04.18 shut off
 -     retail-[7.116]-235.59-2023.04.26 shut off
 -     vue-com-[10.10.234.26]-2023.04.26 shut off
 -     web-admin-[10.10.235.83] shut off
 -     zuul-[10.234.7.127]-235.62-2023.04.26 shut off
创建用于存放文件的目录(可选)
代码语言:javascript复制
# mkdir -p /data/esxi-vm
# cd /data/esxi-vm/
拷贝虚拟机到本地

拷贝完成后会在当前目录生成一个xml文件和disk1磁盘文件

virt-v2v-copy-to-local -ic esx://root@宿主机IP?no_verify=1虚拟机名称

代码语言:javascript复制
# virt-v2v-copy-to-local -ic esx://root@10.10.233.11?no_verify=1 yum-[10.10.235.250]

[ 0.0] Fetching the remote libvirt XML metadata ...
2023-04-06 07:52:18.315 0000: 32189: info : libvirt version: 4.5.0, package: 36.el7_9.5 (CentOS BuildSystem <http://bugs.centos.org>, 2021-04-28-13:32:22, x86-01.bsys.centos.org)
2023-04-06 07:52:18.315 0000: 32189: info : hostname: szsjhl-control-test-10-10-214-11-vm.belle.lan
2023-04-06 07:52:18.315 0000: 32189: warning : esxConnectOpen:857 : Ignoring unexpected path '' for non-vpx scheme 'esx'
Enter root's password for 10.10.233.11:
[ 10.6] Parsing the remote libvirt XML metadata ...
Enter host password for user 'root':
Enter host password for user 'root':
[ 19.4] Copying remote disk 1/1 to yum-[10.10.235.250]-disk1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 100G 100 100G 0 0 93.7M 0 0:18:11 0:18:11 --:--:-- 99.3M
[1115.6] Writing libvirt XML metadata to yum-[10.10.235.250].xml ...
[1115.6] Finishing off
查看生成的xml文件和disk1磁盘文件
代码语言:javascript复制
# ll /data/esxi-vm/
total 104857604
-rw-r--r-- 1 root root 107374182400 Apr 6 16:10 yum-[10.10.235.250]-disk1
-rw-r--r-- 1 root root 1168 Apr 6 16:10 yum-[10.10.235.250].xml
转换数据格式

把磁盘文件的格式转换成OpenStack能够识别的格式

代码语言:javascript复制
# virt-v2v -i libvirtxml yum-[10.10.235.250].xml.xml -o local -os /data/esxi-vm/ -of raw

[ 0.0] Opening the source -i libvirtxml yum-[10.10.235.250].xml.xml
[ 0.0] Creating an overlay to protect the source from being modified
[ 0.5] Opening the overlay
[ 38.1] Inspecting the overlay
[ 62.8] Checking for sufficient free disk space in the guest
[ 62.8] Estimating space required on target for each disk
[ 62.8] Converting CentOS Linux release 7.6.1810 (Core) to run on KVM
virt-v2v: This guest has virtio drivers installed.
[ 157.5] Mapping filesystem data to avoid copying unused and blank areas
[ 159.0] Closing the overlay
[ 159.6] Assigning disks to buses
[ 159.6] Checking if the guest needs BIOS or UEFI to boot
[ 159.6] Initializing the target -o local -os /data/esxi-vm/
[ 159.6] Copying disk 1/1 to /data/esxi-vm/yum-[10.10.235.250].xml-sda (raw)
(100.00/100%)
[ 347.2] Creating output metadata
[ 347.2] Finishing off
代码语言:javascript复制
# ll -h
total 106G
-rw-r--r-- 1 qemu qemu 100G Apr 6 16:10 yum-[10.10.235.250]-disk1
-rw-r--r-- 1 root root 100G Apr 6 16:32 yum-[10.10.235.250]-sda
-rw-r--r-- 1 root root 1.5K Apr 6 16:32 yum-[10.10.235.250].xml
转换磁盘文件格式

raw 和 qcow2 两种格式都支持,qcow2格式:空间占用小、传输快等等。

代码语言:javascript复制
#qemu-img convert -f raw -O qcow2 yum-[10.10.235.250]-sda yum-[10.10.235.250]-sda.qcow2
代码语言:javascript复制
# ll -h
total 111G
-rw-r--r-- 1 qemu qemu 100G Apr 6 16:10 yum-[10.10.235.250]-disk1
-rw-r--r-- 1 root root 100G Apr 6 16:32 yum-[10.10.235.250]-sda
-rw-r--r-- 1 root root 5.1G Apr 6 17:13 yum-[10.10.235.250]-sda.qcow2
-rw-r--r-- 1 root root 1.5K Apr 6 16:32 yum-[10.10.235.250].xml
上传镜像到glance
代码语言:javascript复制
# openstack image create "yum-[10.10.235.250]" --file yum-[10.10.235.250]-sda.qcow2 --disk-format qcow2 --container-format bare --public

# openstack image list
 -------------------------------------- --------------------------------------------- -------- 
| ID | Name | Status |
 -------------------------------------- --------------------------------------------- -------- 

| 27d3347c-3a91-46d2-9d32-cdbc8479c8fa | yum-[10.10.235.250] | active |

从控制台上用新上传的镜像创建新虚拟机,可能会缺少部分实例类型,需要新创建对应实例类型

新创建完新虚拟机后,需要从页面控制台进入新虚拟机中更改一下IP地址,改为openstack中新获取的IP,不然机器无法连接登录。

1 人点赞