找回密码
 注册
查看: 4486|回复: 3

openstack nova 创建镜像Create a snapshot of the instance

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2017-11-10 17:00:22 | 显示全部楼层 |阅读模式
购买主题 本主题需向作者支付 3 金钱 才能浏览

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-10 18:00:18 | 显示全部楼层
Import the snapshot to new environment
( n( a3 {* S* @% r: H; u
# d0 s9 q" Z7 Z4 g' [3 u$ BIn the new project or cloud environment, import the snapshot:# ^2 k  h: g8 Y9 j) K- D
* Y0 u# r# F: D
$ glance image-create --copy-from IMAGE_URL --name myInstanceSnapshot

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-10 18:05:33 | 显示全部楼层
# Save the state and stop a running guest
  a) w6 J+ |: b' B* X4 s* `$ A$ virsh managedsave fed18 : l' W: x9 `- j8 j: ~; @
2 Y* T( q& }( y, c# o6 X- [+ e1 x( T5 S
# Create a qemu internal snapshot
+ I% m5 t3 V! x+ R: {) |$ qemu-img snapshot -c snap1 fed18.qcow2
4 O1 B* R3 _! ]: B' k! _% T4 I& T" f5 I$ X+ c
# Get information about the disk# Y/ B/ Q4 D. W, M9 o3 E. a1 ]
$ qemu-img info fed18.qcow2
2 S% V8 q4 M; d
. u$ O4 G9 `: D. O  G2 k8 }# Extract the internal snapshot, 3 Y2 s9 B! H* E+ Q( [
# convert it to raw and export it a file. F1 D4 T: h3 W) ~, J
$ qemu-img convert -f qcow2 -O raw -s \
5 a3 S2 `% W; s2 R- c    snap1 fed18.qcow2 snap1-fed18.img & e. X, F: U5 a; Y

4 k# x) Z' @1 f! M5 e6 X# Get information about the new image
* Q3 i. F5 _/ H9 _* Y$ {2 y# extracted from the snapshot
1 n  p# H, T. Z* j* o% o3 N+ L$ qemu-img info snap1-fed18.img
$ Y; W7 f3 |: F2 Z( A0 v4 ?. g3 N" \) S& V7 Q
# List out file sizes of the original
# ^$ ?% R& w. j3 \4 V0 }# and the snapshot* E5 k: I3 `$ o2 H: r
$ ls -lash fed18.qcow2 snap1-fed18.qcow2   F% `4 E1 ]5 ^  V

( y4 z9 D- h& V2 \% e# c9 ~  {$ _# A2 h# Delete the internal snapshot
$ @+ w* e1 s4 {/ Y8 A9 f# from the original disk' P- m; a* \2 S9 l$ s* M. `
$ qemu-img snapshot -d snap1 fed18.qcow2
. I" ~. R) ?, D4 v
/ E( e$ C1 }" q! F3 X! m, p# Again, get information of the original disk
. G3 F' ?) ~; |- Y; D$ i$ qemu-img info fed18.qcow2 6 W4 `2 O. n5 C0 W

, l- g: P9 ^* i% O& K# Start the guest again
& m2 F/ n# B% ]0 V( c$ u  C$ virsh start fed18

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-10 18:13:22 | 显示全部楼层
# openstack image list
/ _8 X% X* G$ x9 o  i/ n3 [+--------------------------------------+----------------------------+
" ~- [, L" a! k/ ^/ [" ^: u| ID                                   | Name                       |
7 R$ w% y9 g  o0 B( x* k" _+--------------------------------------+----------------------------+
7 S+ s/ G: n2 j" T1 x| ae262f2b-c79c-4b94-9b65-2039cffa856b | Nis-tests-img        
/ ^0 m+ [% K; d) E
4 a; N- V- @1 Z# openstack image show Nis-tests-img
4 S; J9 K/ Z1 D0 t: W+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+ m1 n2 E8 }$ x4 }| Field            | Value                                                                                                                                                                                                                                                                                                                |
: @  @3 z/ H% ?+ X6 ]2 f+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+ h& f% p7 `4 G7 e| checksum         | d47de1f69c46058550d81f6a0ca961f1                                                                                                                                                                                                                                                                                     |
7 l1 y  m! b9 k! S3 n$ c9 f4 f- \| container_format | bare                                                                                                                                                                                                                                                                                                                 |
* i  s$ ]1 Z* u/ b| created_at       | 2017-11-10T09:50:18Z                                                                                                                                                                                                                                                                                                 |; |& T  }# P# A7 n2 L( ^. v9 u* `9 t0 P
| disk_format      | qcow2                                                                                                                                                                                                                                                                                                                |
) M8 Y3 F. ?0 o7 L1 y5 d| file             | /v2/images/ae262f2b-c79c-4b94-9b65-2039cffa856b/file                                                                                                                                                                                                                                                                 |1 c0 ?' u" e2 x: u) D: N, F
| id               | ae262f2b-c79c-4b94-9b65-2039cffa856b                                                                                                                                                                                                                                                                                 |
& B! {5 H$ H9 N( Q0 k# l. |- u8 W| min_disk         | 120                                                                                                                                                                                                                                                                                                                  |: @% A  L, l6 Y9 @$ _8 l& y
| min_ram          | 0                                                                                                                                                                                                                                                                                                                    |* `" o' f2 d) `* k$ z
| name             | Nis-tests-img                                                                                                                                                                                                                                                                                                        |$ {" B1 C. d* J9 T' n% f9 T
| owner            | e7a7b1f7bd5047c699fb333416341de8                                                                                                                                                                                                                                                                                     |# R5 u: l1 `& k
| properties       | base_image_ref='0150c9f4-a6cf-41c2f', image_location='snapshot', image_state='available', image_type='snapshot', instance_uuid='22011666-9414c6932a', kernel_id='None', owner_id='e7a7b1f7bd5047c699fb333416341de8', ramdisk_id='None', user_id='baf7787e10d14f81b922db814e0ad155' |" c0 i, D; [% |4 _
| protected        | False                                                                                                                                                                                                                                                                                                                |
2 D- B  Q9 ^8 q0 h3 C" j5 s4 Z| schema           | /v2/schemas/image                                                                                                                                                                                                                                                                                                    |) _! |5 G- L, t+ p* C
| size             | 1558904832                                                                                                                                                                                                                                                                                                           |$ F) Q& O& R8 m# e
| status           | active                                                                                                                                                                                                                                                                                                               |; Z( ?; m% @- M
| updated_at       | 2017-11-10T09:52:03Z                                                                                                                                                                                                                                                                                                 |# E) Y: m8 |: e2 C% _( `* q
| virtual_size     | None                                                                                                                                                                                                                                                                                                                 |
8 w( K" S* s% y  K2 R: F& w| visibility       | private                                                                                                                                                                                                                                                                                                              |+ [* D8 g$ J! ~( @
+------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+4 W$ o' [! h2 p+ C- W

9 o+ j+ V4 ?. H& c- oWhen viewing a list of images, you can also use grep to filter thelist, as follows:1 R% d/ b2 f5 O; L
$ openstack image list | grep 'cirros'| dfc1dfb0-d7bf-4fff-8994-319dd6f703d7 | cirros-0.3.5-x86_64-uec         | active || a3867e29-c7a1-44b0-9e7f-10db587cad20 | cirros-0.3.5-x86_64-uec-kernel  | active || 4b916fba-6775-4092-92df-f41df7246a6b | cirros-0.3.5-x86_64-uec-ramdisk | active |
' }. n, e& M+ s0 Y' a7 Y
9 m# B& V; q9 f7 C/ g6 a5 o. {0 L6 B7 q- A

. _. p$ k$ O$ @' BNote
; X& K" ~" r9 \& S# W" C3 aTo store location metadata for images, which enables direct file access for a client,update the /etc/glance/glance-api.conf file with the following statements:
$ y* l. o4 ~. G" z
  • show_multiple_locations = True
  • filesystem_store_metadata_file = filePath
    where filePath points to a JSON file that defines the mount point for OpenStackimages on your system and a unique ID. For example:: Q4 K# j  O# `* {! k. D

    2 D  y( s/ F$ e1 h* X- d0 a7 f/ b
[{    "id": "2d9bb53f-70ea-4066-a68b-67960eaae673",    "mountpoint": "/var/lib/glance/images/"}]
2 h8 K  U& O4 N% ~. _& E3 B% C/ k: z) X" Q. I  T8 D) O0 n
After you restart the Image service, you can use the following syntax to viewthe image’s location information:
" q" S) G1 t0 q+ {$ openstack --os-image-api-version 2 image show imageID: x- B8 f9 [3 e+ L

9 W! C' U+ ~4 |, S1 H; j8 R1 F  AFor example, using the image ID shown above, you would issue the command as follows:! x# L2 w4 O6 t% ?' z: t! `3 J
$ openstack --os-image-api-version 2 image show 2d9bb53f-70ea-4066-a68b-67960eaae673
6 {$ L# |  ?6 i/ S
) y7 t5 G( I7 \' c4 K
) R6 y$ i) k9 {6 K4 W
& r/ C1 i+ i& J+ K# j9 NCreate or update an image (glance)¶To create an image, use openstack image create:0 X, l" x. l, ~$ z9 i( x& o
$ openstack image create imageName% U- j' b; V/ `- A7 m( w

! L; d3 q: N$ `+ KTo update an image by name or ID, use openstack image set:
' W- c. I0 X! z' j- a2 p, ~8 n$ openstack image set imageName
& X" z9 O) M' Y$ Y* O; R2 U/ I9 E: Z
The following list explains the optional arguments that you can use withthe create and set commands to modify image properties. Formore information, refer to the OpenStack Image command reference.9 j6 `4 g& T; O/ ^. \2 v
The following example shows the command that you would use to upload aCentOS 6.3 image in qcow2 format and configure it for public access:0 S0 u9 y# a' r9 w' K" A  d* R
$ openstack image create --disk-format qcow2 --container-format bare \  --public --file ./centos63.qcow2 centos63-image
; ]9 v2 u; m5 X! U; l
) n( r, U% y% W, O7 gThe following example shows how to update an existing image with aproperties that describe the disk bus, the CD-ROM bus, and the VIFmodel:* @$ J7 z7 w" E: L# i

% O, p9 b0 s* @% q& U& |$ R, l
2 _, D! H( @" q9 y, \0 L! O! N0 nNote2 p/ A" R# m9 ]8 x" d; `
When you use OpenStack with VMware vCenter Server, you need to specifythe vmware_disktype and vmware_adaptertype properties withopenstack image create.Also, we recommend that you set the hypervisor_type="vmware" property.For more information, see Images with VMware vSpherein the OpenStack Configuration Reference.
8 x# I# A2 a, l; `# i3 a+ k: Y
$ openstack image set \    --property hw_disk_bus=scsi \    --property hw_cdrom_bus=ide \    --property hw_vif_model=e1000 \    f16-x86_64-openstack-sda" K. w# W( _+ L+ C8 Q4 A+ i7 W) F

$ ~5 a3 B5 g7 R% `! w# ACurrently the libvirt virtualization tool determines the disk, CD-ROM,and VIF device models based on the configured hypervisor type(libvirt_type in /etc/nova/nova.conf file). For the sake of optimalperformance, libvirt defaults to using virtio for both disk and VIF(NIC) models. The disadvantage of this approach is that it is notpossible to run operating systems that lack virtio drivers, for example,BSD, Solaris, and older versions of Linux and Windows.
( g1 q; s/ i. f/ g9 [If you specify a disk or CD-ROM bus model that is not supported, seethe Disk_and_CD-ROM_bus_model_values_table.If you specify a VIF model that is not supported, the instance fails tolaunch. See the VIF_model_values_table.3 `- [; W9 K/ m* ]
The valid model values depend on the libvirt_type setting, as shownin the following tables.9 R4 K8 w" c9 \2 j2 N
Disk and CD-ROM bus model values
libvirt_type settingSupported model values
8 J4 G0 j+ ~, Tqemu or kvm
  • ide
  • scsi
  • virtio& X5 C+ z. l- u0 k) A
4 c9 u/ }/ B! V. ~
xen
  • ide
  • xen, P, _5 _+ B" a* \1 {+ I
VIF model values
libvirt_type settingSupported model values
) L" U* ?/ w# L2 Mqemu or kvm
  • e1000
  • ne2k_pci
  • pcnet
  • rtl8139
  • virtio
    4 H, b6 e% s3 k: b
* E& D0 D$ ^  X
xen
  • e1000
  • netfront
  • ne2k_pci
  • pcnet
  • rtl8139' D6 }/ v' F0 Q6 M

7 q) z+ ]- Z5 o3 a4 Lvmware
  • VirtualE1000
  • VirtualPCNet32
  • VirtualVmxnet# ~2 w0 K. b1 a5 k/ n( \& {

1 T. ]4 i! u8 `$ c& D$ Z
" A$ i( s* V8 }; {Note
9 z. L8 s9 @- s/ Z- B2 x3 KBy default, hardware properties are retrieved from the imageproperties. However, if this information is not available, thelibosinfo database provides an alternative source for thesevalues.  d; P" g/ z" b" c5 ^3 @
If the guest operating system is not in the database, or if the useof libosinfo is disabled, the default system values are used.7 w) H& W* h" M6 v
Users can set the operating system ID or a short-id in imageproperties. For example:
& c9 u( {  P, \) o# ]# M) P$ openstack image set --property short-id=fedora23 \  name-of-my-fedora-image1 g! S/ x; l6 y
7 A2 ?# ?: s  w- n
Alternatively, users can set id to a URL:
6 Y6 @; d/ }" @1 `: T" ?$ openstack image set \  --property id=http://fedoraproject.org/fedora/23 \  ID-of-my-fedora-image
  b, Q5 ?" E7 w8 d! s/ y- k- E/ r- R, O

. b% P$ B. P- tCreate an image from ISO image¶You can upload ISO images to the Image service (glance).You can subsequently boot an ISO image using Compute." Z: X( I1 p/ W3 c" t
In the Image service, run the following command:: s: k. Y7 F0 S2 N' O: S
$ openstack image create ISO_IMAGE --file IMAGE.iso \  --disk-format iso --container-format bare" Y8 ~5 j: u% q5 C6 H: n1 Y1 r2 ?
6 |, v4 B. Z! y3 ~" _
Optionally, to confirm the upload in Image service, run:' y2 N8 B8 C# |  I3 }
$ openstack image list# Q( [. A% L' X( V6 B0 ^

, g$ g, K2 E4 W* q/ }, A
6 U& O) f. Y* Y7 Z4 s
7 u) I- Z: ^5 K+ o. O& M0 iTroubleshoot image creation¶If you encounter problems in creating an image in the Image service orCompute, the following information may help you troubleshoot thecreation process.
, m0 A# r# {% ]5 E
  • Ensure that the version of qemu you are using is version 0.14 orlater. Earlier versions of qemu result in an unknown option -serror message in the /var/log/nova/nova-compute.log file.
  • Examine the /var/log/nova/nova-api.log and/var/log/nova/nova-compute.log log files for error messages.
    + k( H& d1 v4 J

% A4 ^' _$ [1 S
- }7 b1 ?$ G4 {" o
* L  e/ G' t" E3 k3 r2 S2 j
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:20 , Processed in 0.016669 second(s), 25 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表