news 2026/7/28 10:58:10

Glance镜像服务的基本使用

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Glance镜像服务的基本使用
1. Glance镜像服务介绍

Glance是OpenStack镜像服务,用来注册、登陆和检索虚拟机镜像。Glance服务提供了一个REST API,使读者能够查询虚拟机镜像元数据和检索实际镜像。通过镜像服务提供的虚拟机镜像可以存储在不同的位置,从简单的文件系统对象存储到类似OpenStack对象存储系统。Glance与其他组件的关系如图1-1所示。

图1-1 Glance与其他组件的关系

默认情况下,上传的虚拟机镜像存储路径为/var/lib/glance/images/。Glance负责镜像文件的注册、查询和存储管理。

● glance-api负责接受Image API请求,处理image查询和存储等

● glance-registry负责存储,处理和检索image的元数据(大小,类型等)

● 使用数据库来存储image文件的元数据

● 支持不同的存储仓库来存储image文件,包括swift,本地磁盘,RADOS块设备,Amazon S3,HTTP。


2. Glance重要概念

(1)镜像状态

镜像状态是Glance管理镜像重要的一个内容,Glance组件给整个OpenStack提供了镜像查询和检索,Glance可以通过虚拟机镜像的状态感知某一镜像的可用状态。如图1-2所示,OpenStack中镜像的状态分成以下几种:

● Queued:Queued状态这是一种初始化镜像状态,在镜像文件刚刚被创建,在glance数据库中已经保存了镜像标示符,但还没有上传至glance中,此时的glance对镜像数据没有任何描述,其存储空间为0。

● Saving:Saving状态是镜像的原始数据在上传中的一种过度状态,它产生在镜像数据上传至glance的过程中,一般来讲,glance收到一个image请求后,才将镜像上传给glance。

● Active:Active状态是当镜像成功上传完毕以后的一种状态,它表明glance中可用的镜像。

● Killed:Killed状态出现在镜像上传失败或者镜像文件不可读的情况下,glance将镜像状态设置成Killed。

● Deleted:Deleted状态表明一个镜像文件马上会被删除,只是当前glance这种仍然保留该镜像文件的相关信息和原始镜像数据。

● Pending_delete:Pending_delete状态类似于deleted,虽然此时的镜像文件没有删除,但镜像文件不能恢复的。

图1-2 Glance镜像文件状态转换过程

(2)Glance基本架构和三大模块

它的设计模式采用C/S架构模式,Client通过Glance提供的REST API与Glance的服务器(Server)程序进行通信,Glance的服务器程序通过网络端口监听,接收Client发送来的镜像操作请求,基本架构如图1-3所示。

图1-3 Glance架构图

● Glance-api:接收REST API的请求,然后通过其他模块(glance-registry及image store)来完成诸如镜像的查找、获取、上传、删除等操作,默认监听端口9292。

● Glance-registry:用于与MariaDB数据库交互,用于存储或获取镜像的元数据(metadata);通过glance-registry,可以向数据库中写入或获取镜像的各种数据,glance-registry监听端口9191。

● Store Adapter:是一个存储的接口层,通过这个接口,glance可以获取镜像,image store支持的存储有Amazon的S3、OpenStack本身的Swift,本地文件存储和其他分布式存储。

(3)Glance组件的工作过程

如图1-4所示介绍了Glance组件在申请镜像时所与OpenStack平台进行交互的流程图。

图1-4 glance工作过程

3. 创建镜像

(1)下载CirrOS镜像文件

CirrOS是一个极小的云操作系统,可以使用这个小的操作系统来进行Glance服务组件的操作练习。将提供的cirros-0.6.2-x86_64-disk.img镜像上传到controller节点的root目录下面。

[root@controller ~]# ll total 20936 -rw-------. 1 root root 1577 Oct 23 2023 anaconda-ks.cfg -rw-r--r--. 1 root root 21430272 Jun 20 17:47 cirros-0.6.2-x86_64-disk.img -rw-r--r--. 1 root root 101 Jun 20 16:01 logininfo.txt

将镜像上传至controller节点后,通过file命令查看镜像文件信息。

[root@controller ~]# file cirros-0.6.2-x86_64-disk.img cirros-0.6.2-x86_64-disk.img: QEMU QCOW Image (v3), 117440512 bytes

(2)创建镜像

通过命令创建镜像,命令的格式如下:

[root@controller ~]# glance help image-create usage: glance image-create [--architecture ] [--protected [True|False]] [--name ] [--instance-uuid ] [--min-disk ] [--visibility ] [--kernel-id ] [--tags [ ...]] [--os-version ] [--disk-format ] [--os-distro ] [--id ] [--owner ] [--ramdisk-id ] [--min-ram ] [--container-format ] [--property ] [--file ] [--progress]

参数说明:

--disk-format:镜像格式 --container-format: 镜像在其他项目中可见性 --progress: 显示上传镜像的进度 --file:选择本地镜像文件 --name:上传后镜像的名称

使用镜像cirros-0.6.2-x86_64-disk.img通过命令上传镜像至OpenStack中。

[root@controller ~]# glance image-create --name cirros-0.6.2 --disk-format qcow2 --container-format bare --progress --file cirros-0.6.2-x86_64-disk.img [=============================>] 100% +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | c8fc807773e5354afe61636071771906 | | container_format | bare | | created_at | 2024-06-20T09:53:23Z | | disk_format | qcow2 | | id | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | | min_disk | 0 | | min_ram | 0 | | name | cirros-0.6.2 | | os_hash_algo | sha512 | | os_hash_value | 1103b92ce8ad966e41235a4de260deb791ff571670c0342666c8582fbb9caefe6af07ebb11d34f44 | | | f8414b609b29c1bdf1d72ffa6faa39c88e8721d09847952b | | os_hidden | False | | owner | bf368e64a3e64d9c9ae695253f1f3879 | | protected | False | | size | 21430272 | | status | active | | tags | [] | | updated_at | 2024-06-20T09:53:24Z | | virtual_size | Not available | | visibility | shared | +------------------+----------------------------------------------------------------------------------+
4. 管理镜像

(1)查看镜像

通过命令可以在OpenStack平台中查看当前glance中所上传的镜像名称。具体命令如下:

[root@controller ~]# glance image-list +--------------------------------------+--------------+ | ID | Name | +--------------------------------------+--------------+ | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | cirros-0.6.2 | +--------------------------------------+--------------+

也可以使用命令查看镜像的详细信息。具体命令如下:

[root@controller ~]# glance image-show def65f8d-2a6e-4be0-b05f-15fcd80c26f9 +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | c8fc807773e5354afe61636071771906 | | container_format | bare | | created_at | 2024-06-20T09:53:23Z | | disk_format | qcow2 | | id | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | | min_disk | 0 | | min_ram | 0 | | name | cirros-0.6.2 | | os_hash_algo | sha512 | | os_hash_value | 1103b92ce8ad966e41235a4de260deb791ff571670c0342666c8582fbb9caefe6af07ebb11d34f44 | | | f8414b609b29c1bdf1d72ffa6faa39c88e8721d09847952b | | os_hidden | False | | owner | bf368e64a3e64d9c9ae695253f1f3879 | | protected | False | | size | 21430272 | | status | active | | tags | [] | | updated_at | 2024-06-20T09:53:24Z | | virtual_size | Not available | | visibility | shared | +------------------+----------------------------------------------------------------------------------+

(2)修改镜像

可以使用glance image-update更新镜像信息,命令的格式如下:

[root@controller ~]# glance help image-update usage: glance image-update [--architecture ] [--protected [True|False]] [--name ] [--instance-uuid ] [--min-disk ] [--visibility ] [--kernel-id ] [--os-version ] [--disk-format ] [--os-distro ] [--owner ] [--ramdisk-id ] [--min-ram ] [--container-format ] [--property ] [--remove-property key]

参数说明:

--min-disk:镜像启动最小硬盘大小 --name:镜像名称 --disk-format:镜像格式 --min-ram:镜像启动最小内存大小 --container-format:镜像在项目中可见性

如果需要改变镜像启动硬盘最低要求值(min-disk)1G,min-disk默认单位为G。使用glance image-update更新镜像信息操作如下。

[root@controller ~]# glance image-update --min-disk=1 def65f8d-2a6e-4be0-b05f-15fcd80c26f9 +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | c8fc807773e5354afe61636071771906 | | container_format | bare | | created_at | 2024-06-20T09:53:23Z | | disk_format | qcow2 | | id | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | | min_disk | 1 | | min_ram | 0 | | name | cirros-0.6.2 | | os_hash_algo | sha512 | | os_hash_value | 1103b92ce8ad966e41235a4de260deb791ff571670c0342666c8582fbb9caefe6af07ebb11d34f44 | | | f8414b609b29c1bdf1d72ffa6faa39c88e8721d09847952b | | os_hidden | False | | owner | bf368e64a3e64d9c9ae695253f1f3879 | | protected | False | | size | 21430272 | | status | active | | tags | [] | | updated_at | 2024-06-20T09:56:17Z | | virtual_size | Not available | | visibility | shared | +------------------+----------------------------------------------------------------------------------+

也可以使用命令更新镜像启动内存最低要求值(min-ram)为1G,min-ram默认单位为M。使用glance image-update更新镜像信息操作如下:

[root@controller ~]# glance image-update --min-ram=1024 def65f8d-2a6e-4be0-b05f-15fcd80c26f9 +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | c8fc807773e5354afe61636071771906 | | container_format | bare | | created_at | 2024-06-20T09:53:23Z | | disk_format | qcow2 | | id | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | | min_disk | 1 | | min_ram | 1024 | | name | cirros-0.6.2 | | os_hash_algo | sha512 | | os_hash_value | 1103b92ce8ad966e41235a4de260deb791ff571670c0342666c8582fbb9caefe6af07ebb11d34f44 | | | f8414b609b29c1bdf1d72ffa6faa39c88e8721d09847952b | | os_hidden | False | | owner | bf368e64a3e64d9c9ae695253f1f3879 | | protected | False | | size | 21430272 | | status | active | | tags | [] | | updated_at | 2024-06-20T09:57:18Z | | virtual_size | Not available | | visibility | shared | +------------------+----------------------------------------------------------------------------------+

(3)删除镜像

可以使用glance image-delete删除上传至OpenStack平台中的镜像,使用命令格式如下:

[root@controller ~]# glance help image-delete usage: glance image-delete [ ...] Delete specified image. Positional arguments: ID of image(s) to delete. Run `glance --os-image-api-version 1 help image-delete` for v1 help

只需要在命令后跟上镜像ID即可。命令如下:

[root@controller ~]# glance image-delete def65f8d-2a6e-4be0-b05f-15fcd80c26f9 [root@controller ~]# glance image-list +----+------+ | ID | Name | +----+------+ +----+------+
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/28 10:56:32

NBM7100A芯片在低功耗物联网设备中的优化应用

1. 项目背景与核心挑战在低功耗物联网设备设计中,CR2032这类不可充电的纽扣电池面临着两个关键痛点:一是高脉冲电流需求导致的电压骤降,二是电池容量利用率低。传统方案中,当无线模块启动发射时,瞬间电流可能高达20-50…

作者头像 李华
网站建设 2026/7/28 10:55:40

WebRTC实时通信原理与Java/Vue实现详解

1. WebRTC实时通信的核心原理WebRTC(Web Real-Time Communication)作为现代实时音视频通信的基石,其核心在于绕过传统服务器中转,实现端到端(P2P)的直接数据传输。这种架构带来的最大优势是显著降低延迟——…

作者头像 李华
网站建设 2026/7/28 10:53:35

bq27510EVM电量计评估实战:从硬件解析到软件配置的完整指南

1. 项目概述:从官方文档到实战指南的深度转化 如果你是一名硬件工程师或嵌入式开发者,正在为你的单节锂电池供电产品寻找一个可靠的电量计解决方案,那么德州仪器的bq27510系列芯片和其对应的bq27510EVM评估模块,大概率已经进入了你…

作者头像 李华
网站建设 2026/7/28 10:52:38

TranslucentTB终极指南:如何免费打造Windows任务栏透明特效

TranslucentTB终极指南:如何免费打造Windows任务栏透明特效 【免费下载链接】TranslucentTB A lightweight utility that makes the Windows taskbar translucent/transparent. 项目地址: https://gitcode.com/gh_mirrors/tr/TranslucentTB TranslucentTB是一…

作者头像 李华
网站建设 2026/7/28 10:52:35

终极指南:如何用LinkSwift一键获取9大网盘真实下载链接

终极指南:如何用LinkSwift一键获取9大网盘真实下载链接 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 ,支持 百度网盘 / 阿里云盘 / 中国移动云盘 / 天翼…

作者头像 李华
网站建设 2026/7/28 10:48:39

H-ui响应式设计技巧:让你的网页在各种设备上完美展示

H-ui响应式设计技巧:让你的网页在各种设备上完美展示 【免费下载链接】h-ui h-ui前端框架 项目地址: https://gitcode.com/gh_mirrors/hu/h-ui 在移动互联网时代,用户通过手机、平板、电脑等多种设备访问网站,如何让网页在不同屏幕尺寸…

作者头像 李华