尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
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 S3HTTP。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镜像文件状态转换过程2Glance基本架构和三大模块它的设计模式采用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本地文件存储和其他分布式存储。3Glance组件的工作过程如图1-4所示介绍了Glance组件在申请镜像时所与OpenStack平台进行交互的流程图。图1-4 glance工作过程3. 创建镜像1下载CirrOS镜像文件CirrOS是一个极小的云操作系统可以使用这个小的操作系统来进行Glance服务组件的操作练习。将提供的cirros-0.6.2-x86_64-disk.img镜像上传到controller节点的root目录下面。[rootcontroller ~]# 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命令查看镜像文件信息。[rootcontroller ~]# file cirros-0.6.2-x86_64-disk.img cirros-0.6.2-x86_64-disk.img: QEMU QCOW Image (v3), 117440512 bytes2创建镜像通过命令创建镜像命令的格式如下[rootcontroller ~]# 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中。[rootcontroller ~]# 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中所上传的镜像名称。具体命令如下[rootcontroller ~]# glance image-list ---------------------------------------------------- | ID | Name | ---------------------------------------------------- | def65f8d-2a6e-4be0-b05f-15fcd80c26f9 | cirros-0.6.2 | ----------------------------------------------------也可以使用命令查看镜像的详细信息。具体命令如下[rootcontroller ~]# 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更新镜像信息命令的格式如下[rootcontroller ~]# 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-disk1Gmin-disk默认单位为G。使用glance image-update更新镜像信息操作如下。[rootcontroller ~]# glance image-update --min-disk1 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为1Gmin-ram默认单位为M。使用glance image-update更新镜像信息操作如下[rootcontroller ~]# glance image-update --min-ram1024 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平台中的镜像使用命令格式如下[rootcontroller ~]# 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即可。命令如下[rootcontroller ~]# glance image-delete def65f8d-2a6e-4be0-b05f-15fcd80c26f9 [rootcontroller ~]# glance image-list ---------- | ID | Name | ---------- ----------
RELATED

相关推荐

强化学习实战指南:从PPO、DQN算法原理到工程落地

强化学习实战指南:从PPO、DQN算法原理到工程落地

去年,我带着团队做一个自动化决策项目,目标是让一个系统能根据实时数据动态调整策略。一开始,我们尝试了各种基于规则的硬编码逻辑,结果发现规则越写越多,逻辑越来越复杂,系统却越来越“笨”——面对稍微超出预设边界的情况就束手无策。直到我们开始尝试引入强化学习,才…

📅 2026/9/13 0:44:03
免费文档下载终极指南:kill-doc如何帮你突破30+文库平台限制

免费文档下载终极指南:kill-doc如何帮你突破30+文库平台限制

免费文档下载终极指南:kill-doc如何帮你突破30文库平台限制 【免费下载链接】kill-doc 看到经常有小伙伴们需要下载一些免费文档,但是相关网站浏览体验不好各种广告,各种登录验证,需要很多步骤才能下载文档,该脚本就是…

📅 2026/9/8 3:28:59
「科研记录」图像篡改检测数据集整理

「科研记录」图像篡改检测数据集整理

【专业服务】提供图像篡改检测与鉴伪技术支持,欢迎咨询合作哦! 声明:对于所获得数据集,请遵循数据集作者的规定进行使用,请勿用于非法研究。本文章仅提供部分下载地址或下载链接,不对数据集版权内容负责。…

📅 2026/9/13 13:34:57
MORE NEWS

更多资讯

📰

UnoCSS Compile Class 转换器实战:用 `:uno:` 标记将工具类批量编译为单一类名

UnoCSS Compile Class 转换器实战:用 :uno: 标记将工具类批量编译为单一类名 【免费下载链接】unocss The instant on-demand atomic CSS engine. 项目地址: https://gitcode.com/GitHub_Trending/un/unocss 导读 unocss/transformer-compile-class 是 UnoC…

📰

门限环签名电子投票系统:Python密码学实战指南

简介:这是一份面向计算机类专业本科生的毕业设计级电子投票系统实现方案,聚焦密码学前沿应用——门限环签名技术,解决匿名性、不可伪造性与容错性兼顾的投票安全需求,适用于毕设、课程设计及密码学实践学习。资源包共104个文件&am…

📰

Android逆向实战:还原激励类App签到接口的签名算法

有一位做运营的朋友跟我抱怨,说自己手机里那款“看视频赚金币”的App提现门槛越来越高,想让我帮忙看看到底是哪里卡住了。我拿到手之后,索性做了一轮完整的Android逆向案例分析,目标很直接:理清它的签到接口和任务上报…

📰

AI Agent安全操作数据库:SQL注入防御与参数化查询实战

最近我把OpenClaw部署到本地服务器,给Agent接上数据库查询这个功能之后,踩到的第一个大坑就是SQL注入。尤其是参数化查询和ORM的安全使用,这两个基本功如果没打牢,后面加再多花哨的skill都白搭。这篇文章既是给同样在折腾OpenClaw…

📰

51单片机开环控制磁阻传感器的硬件匹配与代码实现

简介:本资源是一份面向嵌入式初学者与单片机课程实践者的51单片机开关磁阻电机(SRM)开环控制教学方案,聚焦磁阻位置检测、固定时序驱动与基础状态可视化。资源包含1个C语言主程序文件(zhuang600.c)实现电机…

📰

Iosevka 24.1.4 更新解析:新增字符全览与字形修复背后的源码逻辑

Iosevka 24.1.4 更新解析:新增字符全览与字形修复背后的源码逻辑 【免费下载链接】Iosevka Versatile typeface for code, from code. 项目地址: https://gitcode.com/GitHub_Trending/io/Iosevka Iosevka 是一套"由代码生成的代码字体"&#xff0…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬