Glance基础服务运维

@

Glance镜像服务介绍

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

创建镜像

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

[root@controller ~]# ls cirros-0.3.4-x86_64-disk.img 

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

[root@controller ~]# file cirros-0.3.4-x86_64-disk.img  cirros-0.3.4-x86_64-disk.img: QEMU QCOW Image (v2), 41126400 bytes 

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

[root@controller images]# glance help image-create  usage: glance image-create [--architecture <ARCHITECTURE>]                            [--protected [True|False]] [--name <NAME>]                            [--instance-uuid <INSTANCE_UUID>]                            [--min-disk <MIN_DISK>] [--visibility <VISIBILITY>]                            [--kernel-id <KERNEL_ID>]                            [--tags <TAGS> [<TAGS> ...]]                            [--os-version <OS_VERSION>]                            [--disk-format <DISK_FORMAT>]                            [--os-distro <OS_DISTRO>] [--id <ID>]                            [--owner <OWNER>] [--ramdisk-id <RAMDISK_ID>]                            [--min-ram <MIN_RAM>]                            [--container-format <CONTAINER_FORMAT>]                            [--property <key=value>] [--file <FILE>]                            [--progress]  #参数说明 --disk-format:镜像格式 --container-format: 镜像在其他项目中可见性 --progress: 显示上传镜像的进度 --file:选择本地镜像文件 --name:上传后镜像的名称 

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

[root@controller ~]# glance image-create --name cirros-0.3.4 --disk-format qcow2 --container-format bare --progress < cirros-0.3.4-x86_64-disk.img  [=============================>] 100% +------------------+--------------------------------------------------------------------+ | Property         | Value                                                              | +------------------+--------------------------------------------------------------------+ | checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                   | | container_format | bare                                                               | | created_at       | 2022-02-10T03:15:29Z                                               | | disk_format      | qcow2                                                              | | id               | 32a2513c-e5ba-438b-a5ee-63c35c03b284                               | | min_disk         | 0                                                                  | | min_ram          | 0                                                                  | | name             | cirros-0.3.4                                                       | | os_hash_algo     | sha512                                                             | | os_hash_value    | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9                      19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232      | | os_hidden        | False                                                              | | owner            | 1776912d52a7444d8b2d09eb86e8d1d9                                   | | protected        | False                                                              | | size             | 13267968                                                           | | status           | active                                                             | | tags             | []                                                                 | | updated_at       | 2022-02-10T03:15:29Z                                               | | virtual_size     | Not available                                                      | | visibility       | shared                                                             | +------------------+--------------------------------------------------------------------+ 

查看镜像

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

[root@controller ~]# glance image-list +--------------------------------------+--------------+ | ID                                   | Name         | +--------------------------------------+--------------+ | 32a2513c-e5ba-438b-a5ee-63c35c03b284 | cirros-0.3.4 | +--------------------------------------+--------------+ 

也可以使用命令查看镜像的详细信息

[root@controller ~]# glance image-show  32a2513c-e5ba-438b-a5ee-63c35c03b284 +------------------+--------------------------------------------------------------------+ | Property         | Value                                                              | +------------------+------------------------------------------------------------------ -+ | checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                   | | container_format | bare                                                               | | created_at       | 2022-02-10T03:15:29Z                                               | | disk_format      | qcow2                                                              | | id               | 32a2513c-e5ba-438b-a5ee-63c35c03b284                               | | min_disk         | 0                                                                  | | min_ram          | 0                                                                  | | name             | cirros-0.3.4                                                       | | os_hash_algo     | sha512                                                             | | os_hash_value    | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9                      19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232      | | os_hidden        | False                                                              | | owner            | 1776912d52a7444d8b2d09eb86e8d1d9                                   | | protected        | False                                                              | | size             | 13267968                                                           | | status           | active                                                             | | tags             | []                                                                 | | updated_at       | 2022-02-10T03:15:29Z                                               | | virtual_size     | Not available                                                      | | visibility       | shared                                                             | +------------------+--------------------------------------------------------------------+ 

修改镜像

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

[root@controller images]# glance help image-update  usage: glance image-update [--architecture <ARCHITECTURE>]                            [--protected [True|False]] [--name <NAME>]                            [--instance-uuid <INSTANCE_UUID>]                            [--min-disk <MIN_DISK>] [--visibility <VISIBILITY>]                            [--kernel-id <KERNEL_ID>]                            [--os-version <OS_VERSION>]                            [--disk-format <DISK_FORMAT>]                            [--os-distro <OS_DISTRO>] [--owner <OWNER>]                            [--ramdisk-id <RAMDISK_ID>] [--min-ram <MIN_RAM>]                            [--container-format <CONTAINER_FORMAT>]                            [--property <key=value>] [--remove-property key]                            <IMAGE_ID> #参数说明 --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 32a2513c-e5ba-438b-a5ee-63c35c03b284 +------------------+--------------------------------------------------------------------+ | Property         | Value                                                              | +------------------+--------------------------------------------------------------------+ | checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                   | | container_format | bare                                                               | | created_at       | 2022-02-10T03:15:29Z                                               | | disk_format      | qcow2                                                              | | id               | 32a2513c-e5ba-438b-a5ee-63c35c03b284                               | | min_disk         | 1                                                                  | | min_ram          | 0                                                                  | | name             | cirros-0.3.4                                                       | | os_hash_algo     | sha512                                                             | | os_hash_value    | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9                      19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232      | | os_hidden        | False                                                              | | owner            | 1776912d52a7444d8b2d09eb86e8d1d9                                   | | protected        | False                                                              | | size             | 13267968                                                           | | status           | active                                                             | | tags             | []                                                                 | | updated_at       | 2022-02-10T03:16:59Z                                               | | virtual_size     | Not available                                                      | | visibility       | shared                                                             | +------------------+--------------------------------------------------------------------+ 

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

[root@controller ~]# glance image-update --min-ram=1024 32a2513c-e5ba-438b-a5ee-63c35c03b284 +------------------+--------------------------------------------------------------------+ | Property         | Value                                                              | +------------------+--------------------------------------------------------------------+ | checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                   | | container_format | bare                                                               | | created_at       | 2022-02-10T03:15:29Z                                               | | disk_format      | qcow2                                                              | | id               | 32a2513c-e5ba-438b-a5ee-63c35c03b284                               | | min_disk         | 1                                                                  | | min_ram          | 1024                                                               | | name             | cirros-0.3.4                                                       | | os_hash_algo     | sha512                                                             | | os_hash_value    | f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f9                      19ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232      | | os_hidden        | False                                                              | | owner            | 1776912d52a7444d8b2d09eb86e8d1d9                                   | | protected        | False                                                              | | size             | 13267968                                                           | | status           | active                                                             | | tags             | []                                                                 | | updated_at       | 2022-02-10T03:17:21Z                                               | | virtual_size     | Not available                                                      | | visibility       | shared                                                             | +------------------+--------------------------------------------------------------------+ 

删除镜像

可以使用glance image-delete删除上传至OpenStack平台中的镜像,只需要在命令后跟上镜像ID即可

[root@controller images]# glance image-delete 32a2513c-e5ba-438b-a5ee-63c35c03b284 [root@controller images]# glance image-list +--------------------------------------+------------------------------+ | ID                                   | Name                         | +--------------------------------------+------------------------------+ +--------------------------------------+------------------------------+ 
发表评论

相关文章