Skip to content

天楚锐齿

人工智能 云计算 大数据 物联网 IT 通信 嵌入式

天楚锐齿

  • 下载
  • 物联网
  • 云计算
  • 大数据
  • 人工智能
  • Linux&Android
  • 网络
  • 通信
  • 嵌入式
  • 杂七杂八

Openstack nova的存储、ephemeral以及虚拟机实例的备份与恢复

2018-03-13
一个例子:
# ll -h
-rw-r–r–. 1 root root 204M Feb 29 19:21 f16-x86_64-openstack-sda.qcow2

# qemu-img info f16-x86_64-openstack-sda.qcow2
image: f16-x86_64-openstack-sda.qcow2
file format: qcow2
virtual size: 9.8G (10486808576 bytes)
disk size: 204M
cluster_size: 65536
可以看到204M就是文件大小。

# nova flavor-list
+—-+———–+———–+——+———–+——+——-+————-+
| ID |    Name   | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor |
+—-+———–+———–+——+———–+——+——-+————-+
| 2  | m1.small  | 2048      | 10   | 20        |      | 1     | 1.0         |
+—-+———–+———–+——+———–+——+——-+————-+
small类型持久硬盘为10GB,临时硬盘为20GB。
把上面的虚拟机以small方式启动起来。
# file /var/lib/nova/instances/instance-0000001e/disk
/var/lib/nova/instances/instance-0000001e/disk: QEMU QCOW Image (v2), has backing file (path /var/lib/nova/instances/_base/4fc90f26a53998d2a785ca85d95fab5d9), 10737418240 bytes
这个disk对应10GB的backing file,在../../_base目录下。

# file /var/lib/nova/instances/instance-0000001e/disk.local
/var/lib/nova/instances/instance-0000001e/disk.local: QEMU QCOW Image (v2), has backing file (path /var/lib/nova/instances/_base/ephemeral_0_20_None), 21474836480 bytes

这个disk.local对应20GB的backing file,在../../_base目录下。

# ll -h /var/lib/nova/instances/_base/
total 9.1G
-rw-r–r–. 1 nova nova 9.8G Jul 20 17:23 4fc90f26a53998d2a785ca85d95fab5d9063bf78
-rw-r–r–. 1 nova qemu  10G Jul 20 17:23 4fc90f26a53998d2a785ca85d95fab5d9063bf78_10
-rw-r–r–. 1 nova nova 204M Jul 18 11:43 4fc90f26a53998d2a785ca85d95fab5d9063bf78.part
-rw-r–r–. 1 qemu qemu  20G Jul 18 11:43 ephemeral_0_20_None
这里10G对应small里面的10G,20G对应small里面的20G,204M对应文件大小,9.8GB对应虚拟磁盘大小。

进入虚拟机里面,查看硬盘配置:
# fdisk -l
WARNING: GPT (GUID Partition Table) detected on ‘/dev/vda’! The util fdisk doesn’t support GPT. Use GNU Parted.
Disk /dev/vda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot      Start         End      Blocks   Id  System
/dev/vda1               1    20482047    10241023+  ee  GPT

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/vdb doesn’t contain a valid partition table
这里的10GB对应small的10GB,20GB对应small的20GB。

虚拟机里面查看文家系统:
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          9.2G  713M  8.4G   8% /
devtmpfs        995M     0  995M   0% /dev
tmpfs          1003M     0 1003M   0% /dev/shm
tmpfs          1003M   40M  963M   4% /run
/dev/vda2       9.2G  713M  8.4G   8% /
tmpfs          1003M   40M  963M   4% /run
tmpfs          1003M     0 1003M   0% /sys/fs/cgroup
tmpfs          1003M     0 1003M   0% /media

    在 nova 裡面, 它將 volume 分成了兩個類型, 一種是關機後就會消失的 ephemeral volume, 另一種則是會繼續存在的 persistent volume, 即使 Virtual Machine 關機後, 你仍可以產生新的 Virtual Machine, 然後將這個 persistent volume 掛上去

而 ephemeral volume 目前會用在兩個地方, 第一個是開機用的主硬碟 (Root Disk), 如果你跑的程式有需要使用額外的空間, 那可以要求多一顆暫用硬碟(Ephemeral Disk), 但仍要注意這個 disk 在關機後就會消失.

我們可以在 Flavor 內看到 Openstack 預設的幾種組合(tiny 的那個雖然寫著沒有 root disk, 但其實仍然有, 只是比較小, 只有 2G)

Openstack nova的存储、ephemeral以及虚拟机实例的备份与恢复 - 见龙在天 - 见龙在天

m1.tiny (1VCPU / 0GB disk / 512MB RAM) 的狀況

ubuntu@vm1:~$ sudo fdisk -l Disk /dev/vda: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000     Device Boot      Start         End      Blocks   Id  System /dev/vda1   *       16065     4192964     2088450   83  Linux   ubuntu@vm1:~$ sudo less /proc/meminfo | grep -i total MemTotal:         503520 kB SwapTotal:             0 kB VmallocTotal:   34359738367 kB HugePages_Total:       0  ubuntu@vm1:~$ sudo less /proc/cpuinfo | grep CPU model name      : QEMU Virtual CPU version 1.0  ubuntu@vm1:~$ sudo df -h Filesystem      Size  Used Avail Use% Mounted on /dev/vda1       2.0G  667M  1.3G  35% / udev            242M   12K  242M   1% /dev tmpfs            99M  204K   99M   1% /run none            5.0M     0  5.0M   0% /run/lock none            246M     0  246M   0% /run/shm

m1.small (1VCPU / 10GB disk / 2048MB RAM) 的狀況, 可以看到比 m1.tiny 多了一個 /dev/vdb , 大小是 20G

ubuntu@vm2:~$ sudo fdisk -l  Disk /dev/vda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000     Device Boot      Start         End      Blocks   Id  System /dev/vda1   *       16065    20964824    10474380   83  Linux  Disk /dev/vdb: 21.5 GB, 21474836480 bytes 16 heads, 63 sectors/track, 41610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000  Disk /dev/vdb doesn't contain a valid partition table  ubuntu@vm2:~$ sudo less /proc/meminfo | grep -i total MemTotal:        2051772 kB SwapTotal:             0 kB VmallocTotal:   34359738367 kB HugePages_Total:       0  ubuntu@vm2:~$ sudo less /proc/cpuinfo | grep CPU model name      : QEMU Virtual CPU version 1.0  ubuntu@vm2:~$ sudo df -h Filesystem      Size  Used Avail Use% Mounted on /dev/vda1       9.9G  670M  8.7G   7% / udev            998M  8.0K  998M   1% /dev tmpfs           401M  208K  401M   1% /run none            5.0M     0  5.0M   0% /run/lock none           1002M     0 1002M   0% /run/shm /dev/vdb         20G  173M   19G   1% /mnt

回到 compute node 上面去看

# 可以看到有兩個 virtual machine 正在跑 wistor@ubuntu83:~$ sudo virsh list [sudo] password for wistor:  Id Name                 State ----------------------------------   3 instance-00000007    running   4 instance-00000009    running  # 這個只有 vda, 合理的判斷應該是 m1.tiny wistor@ubuntu83:~$ sudo virsh domblklist 3 Target     Source ------------------------------------------------ vda        /var/lib/nova/instances/instance-00000007/disk  # 這個有 vda 和 vdb, 應該就是 m1.small wistor@ubuntu83:~$ sudo virsh domblklist 4 Target     Source ------------------------------------------------ vda        /var/lib/nova/instances/instance-00000009/disk vdb        /var/lib/nova/instances/instance-00000009/disk.local  # 先到 tiny 的資料夾去看, 可以發現有 disk 這個檔案, 還有一個 libvirt.xml # 但為什麼 disk 大小只有 118M ? 而不是 2G? wistor@ubuntu83:/var/lib/nova/instances/instance-00000007$ ll -h total 115M drwxrwxr-x 2 nova         nova 4.0K May 29 13:54 ./ drwxr-xr-x 6 nova         nova 4.0K May 29 13:57 ../ -rw-rw---- 1 libvirt-qemu kvm   21K May 29 13:55 console.log -rw-r--r-- 1 libvirt-qemu kvm  118M May 29 14:07 disk -rw-rw-r-- 1 nova         nova 1.5K May 29 13:54 libvirt.xml  # 看一下 disk 是什麼東西, 結果發現他是 QCOW 格式, backing file 在 _base 裡面 wistor@ubuntu83:/var/lib/nova/instances/instance-00000007$ file disk disk: QEMU QCOW Image (v2), has backing file (path /var/lib/nova/instances/_base/20938b475c7d805e707888fb2a3196550), 2147483648 bytes  # 看一下 _base 底下有什麼東西 wistor@ubuntu83:/var/lib/nova/instances/_base$ ll -h total 3.1G drwxrwxr-x 2 nova         nova 4.0K May 27 23:35 ./ drwxr-xr-x 6 nova         nova 4.0K May 29 13:57 ../ -rw-r--r-- 1 libvirt-qemu kvm  2.0G May 27 23:57 20938b475c7d805e707888fb2a31965508d0bb4b -rw-r--r-- 1 libvirt-qemu kvm   10G May 27 23:57 20938b475c7d805e707888fb2a31965508d0bb4b_10 -rw-r--r-- 1 libvirt-qemu kvm   20G May 27 23:28 ephemeral_0_20_None  # 而這個 backend 的大小剛好就是 2G, 而且是個 boot sector, 所以他就是 tiny 的 boot disk wistor@ubuntu83:/var/lib/nova/instances/_base$ file 20938b475c7d805e707888fb2a31965508d0bb4b 20938b475c7d805e707888fb2a31965508d0bb4b: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 16065, 4176900 sectors, code offset 0x63  # 接下來看看 small 的資料夾, 可以發現多一個 disk.local wistor@ubuntu83:/var/lib/nova/instances/instance-00000009$ ll -h total 395M drwxrwxr-x 2 nova         nova 4.0K May 29 13:57 ./ drwxr-xr-x 6 nova         nova 4.0K May 29 13:57 ../ -rw-rw---- 1 libvirt-qemu kvm   21K May 29 13:58 console.log -rw-r--r-- 1 libvirt-qemu kvm  390M May 29 14:13 disk -rw-r--r-- 1 libvirt-qemu kvm   12M May 29 13:58 disk.local -rw-rw-r-- 1 nova         nova 1.7K May 29 13:57 libvirt.xml  # 發現他也是 qcow 格式, backing file 也在 _base 下 wistor@ubuntu83:/var/lib/nova/instances/instance-00000009$ file disk.local disk.local: QEMU QCOW Image (v2), has backing file (path /var/lib/nova/instances/_base/ephemeral_0_20_None), 21474836480 bytes  # 這個就是 ephemeral disk, 大小為 20G wistor@ubuntu83:/var/lib/nova/instances/_base$ file ephemeral_0_20_None ephemeral_0_20_None: Linux rev 1.0 ext3 filesystem data, UUID=e886c848-3a77-4e2c-b6d6-4d77eb51f8da, volume name "ephemeral0" (large files)

另下來就是測試一下 persistent volume. 透過 UI 或是 command line, 我們生成一個大小為 10G 的 volume, 並且把它 attach 到 vm2 (m1.small)

Openstack nova的存储、ephemeral以及虚拟机实例的备份与恢复 - 见龙在天 - 见龙在天
# 從 nova 的 command line 可以看到新增的 volume wistor@ubuntu83:~$ sudo -i nova volume-list +----+-----------+--------------+------+-------------+-------------+ | ID |   Status  | Display Name | Size | Volume Type | Attached to | +----+-----------+--------------+------+-------------+-------------+ | 3  | available | volume1      | 10   | None        |             | +----+-----------+--------------+------+-------------+-------------+  # 在 lvm 內也可以看到這個新的 volume wistor@ubuntu83:~$ sudo lvscan   ACTIVE            '/dev/nova-volumes/volume-00000003' [10.00 GiB] inherit  # 可以看到 tgt 把這個 volume export 出去變成一個 iscsi target wistor@ubuntu83:~$ sudo tgt-admin -s Target 1: iqn.2010-10.org.openstack:volume-00000003     System information:         Driver: iscsi         State: ready     I_T nexus information:     LUN information:         LUN: 0             Type: controller             SCSI ID: IET     00010000             SCSI SN: beaf10             Size: 0 MB, Block size: 1             Online: Yes             Removable media: No             Readonly: No             Backing store type: null             Backing store path: None             Backing store flags:         LUN: 1             Type: disk             SCSI ID: IET     00010001             SCSI SN: beaf11             Size: 10737 MB, Block size: 512             Online: Yes             Removable media: No             Readonly: No             Backing store type: rdwr             Backing store path: /dev/nova-volumes/volume-00000003             Backing store flags:     Account information:     ACL information:         ALL  # 然後使用 open iscsi initiator 連線到這個 iscsi target  wistor@ubuntu83:~$ sudo iscsiadm -m session tcp: [5] 172.17.123.83:3260,1 iqn.2010-10.org.openstack:volume-00000003  # 然後就多一個 device wistor@ubuntu83:/dev/disk/by-path$ ll lrwxrwxrwx 1 root root   9 May 29 14:23 ip-172.17.123.83:3260-iscsi-iqn.2010-10.org.openstack:volume-00000003-lun-1 -> ../../sdf  wistor@ubuntu83:~$ sudo fdisk -l /dev/sdf  Disk /dev/sdf: 10.7 GB, 10737418240 bytes 64 heads, 32 sectors/track, 10240 cylinders, total 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000  Disk /dev/sdf doesn't contain a valid partition table  # 然後也可以看到 vm2 上面又多了一個 device wistor@ubuntu83:~$ sudo virsh domblklist 4 Target     Source ------------------------------------------------ vda        /var/lib/nova/instances/instance-00000009/disk vdb        /var/lib/nova/instances/instance-00000009/disk.local vdc        /dev/disk/by-path/ip-172.17.123.83:3260-iscsi-iqn.2010-10.org.openstack:volume-00000003-lun-1

PS1. 目前發現在 vm 有掛載額外的 volume 時, 重開機會有問題

openstack中 虚拟机实例的备份与恢复

openstack中,虚拟机实例一般是放在nova/instances目录底下.

该目录的典型结构如下所示:

root@node77:~# ls /opt/stack/nova/instances/
_base instance-0000001a

其中

_base目录中存放的是虚拟机实例的base image

而instance-0000001a存放的是虚拟机实例镜像的增量部分。

instance-0000001a目录有如下的一些文件:

root@node77:~# ls /opt/stack/nova/instances/instance-0000001a/
console.log disk disk.local libvirt.xml

其中

console.log 保存虚拟机启动的日志信息

disk 和 disk.local为虚拟机实例的镜像文件

libvirt.xml为配置文件。

这其中需要注意的是,disk和disk.local并没有包含该虚拟机的所有数据,它们只是基于base image的增量部分

我们通过kvm-image 工具可以查看该信息,如下:

root@node77:/opt/stack/nova/instances/instance-0000001a# kvm-img info disk
image: disk
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 1.6G
cluster_size: 2097152
backing file: /opt/stack/nova/instances/_base/5dcb736a3fbb7f5b92657095aa77a877f4039ec0_10 (actual path: /opt/stack/nova/instances/_base/5dcb736a3fbb7f5b92657095aa77a877f4039ec0_10)

 

root@node77:/opt/stack/nova/instances/instance-0000001a# kvm-img info disk.local 
image: disk.local
file format: qcow2
virtual size: 40G (42949672960 bytes)
disk size: 4.0M
cluster_size: 2097152
backing file: /opt/stack/nova/instances/_base/ephemeral_0_40_None (actual path: /opt/stack/nova/instances/_base/ephemeral_0_40_None)

其中backing file 即是base image

因此我们在备份虚拟机实例的时候,不仅要备份instance-0000001a目录下的数据,而且要备份该虚拟机相关的base image数据,即backing file给出的文件。

 

对于该例子:

我们需要备份如下的文件:

(1)console.log

(2)disk

(3)disk.local

(4)libvirt.xml

(5)/opt/stack/nova/instances/_base/ephemeral_0_40_None

(6)/opt/stack/nova/instances/_base/5dcb736a3fbb7f5b92657095aa77a877f4039ec0_10

 

如何根据备份的文件,在另外一台机器上恢复该虚拟机:

方法1:

我们将disk 和 disk.local磁盘文件分别和它们的base image合并,生成两个新的磁盘文件,那么这两个磁盘文件将包含虚拟机所有的数据。

qemu-img convert [-c] [-f format] [-o options] [-O output_format] filename output_filename
qemu-img convert disk –O qcow2 newdisk
 qemu-img convert disk.local –O qcow2 newdisk.local

 

方法2:

我们修改disk和disk.local文件中backing file的位置,为当前base image的位置

qemu-img rebase [-f format] [-u] -b backing_file [-F backing_format] filename
正确处理完磁盘文件后,剩下的工作就是按照libvirt.xml文件的设置,启动虚拟机了。
1,489次阅读

Post navigation

前一篇:

亚马逊EC2的AZ有效区域和Openstack nova的aggregate主机聚合

后一篇:

qemu-kvm使用例子

发表回复 取消回复

要发表评论,您必须先登录。

个人介绍

需要么,有事情这里找联系方式:关于天楚锐齿

=== 美女同欣赏,好酒共品尝 ===

微信扫描二维码赞赏该文章:

扫描二维码分享该文章:

分类

  • Linux&Android (81)
  • Uncategorized (1)
  • 下载 (28)
  • 云计算 (38)
  • 人工智能 (9)
  • 大数据 (35)
  • 嵌入式 (34)
  • 杂七杂八 (35)
  • 物联网 (65)
  • 网络 (25)
  • 通信 (22)

归档

近期文章

  • 飞书机器人发送卡片interactive消息
  • Springboot JPA实现对数据库表统一的增删改查
  • WEB的内容安全策略CSP(Content-Security-Policy)
  • CSS利用@media和viewport实现响应式布局自动适配手机电脑等
  • VUE前端增加国际化支持

近期评论

  • linux爱好者 发表在《Linux策略路由及iptables mangle、ip rule、ip route关系及一种Network is unreachable错误》
  • maxshu 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • Ambition 发表在《使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序》
  • maxshu 发表在《Android9下用ethernet 的Tether模式来做路由器功能》

阅读量

  • 使用Android的HIDL+AIDL方式编写从HAL层到APP层的程序 - 23,810次阅读
  • 卸载深信服Ingress、SecurityDesktop客户端 - 18,519次阅读
  • 车机技术之车规级Linux-Automotive Grade Linux(AGL) - 10,569次阅读
  • linux下的unbound DNS服务器设置详解 - 9,323次阅读
  • 在Android9下用ndk编译vSomeIP和CommonAPI以及使用例子 - 9,136次阅读
  • linux的tee命令导致ssh客户端下的shell卡住不动 - 8,639次阅读
  • Linux策略路由及iptables mangle、ip rule、ip route关系及一种Network is unreachable错误 - 8,126次阅读
  • 车机技术之360°全景影像(环视)系统 - 8,088次阅读
  • 车机技术之Android Automotive - 7,940次阅读
  • Windows下安装QEMU并在qemu上安装ubuntu和debian - 7,840次阅读

其他操作

  • 注册
  • 登录
  • 条目 feed
  • 评论 feed
  • WordPress.org

联系方式

地址
深圳市科技园

时间
周一至周五:  9:00~12:00,14:00~18:00
周六和周日:10:00~12:00

标签

android AT命令 CAN centos docker Hadoop hdfs ip java kickstart linux mapreduce mini6410 modem nova OAuth openstack os python socket ssh uboot 内核 协议 安装 嵌入式 性能 报表 授权 操作系统 数据 数据库 月报 模型 汽车 深信服 源代码 统计 编译 脚本 虚拟机 调制解调器 车机 金融 鉴权
© 2025 天楚锐齿