前置条件
HBlock服务已经正确配置,且可以正常启动。
正确安装OpenStack,支持的OpenStack版本详见环境要求。
正确安装OpenStack的接入插件,且功能正常。
说明
在使用Stor Cinder进行镜像创建卷的场景下,它支持采用克隆方式进行底层处理。当镜像文件较大时,利用克隆方式可以快速高效地完成卷的创建任务,大大提升了操作效率和用户体验。使用此方式的前提条件是:
Glance配置了HBlock存储。
cinder.conf中配置:allowed_direct_url_schemes=cinder,配置位置在[DEFAULT]标签下,否则不生效。
glance-api.conf中配置:glance-api.conf: show_image_direct_url = True,配置位置在[DEFAULT]标签下,否则不生效。
对应的image必须是基于下列条件创建的:HBlock的卷,格式为raw,容器为bare。
使用方法
修改Glance的配置文件/etc/glance/glance-api.conf,修改enabled_backends,支持使用Cinder作为Glance的后端存储,同时通过cinder_volume_type来指定卷类型。
[DEFAULT] show_image_direct_url = True enabled_backends="file:file,cinder-a:cinder,cinder-b:cinder" [glance_store] stores=file,cinder-a,cinder-b default_backend=file [file] filesystem_store_datadir = /opt/stack/data/glance/images/ [os_glance_tasks_store] filesystem_store_datadir = /opt/stack/data/glance/tasks_work_dir [os_glance_staging_store] filesystem_store_datadir = /opt/stack/data/glance/staging [cinder-a] cinder_os_region_name=RegionOne cinder_store_auth_address=http://10.179.32.198:5000/v3 cinder_store_user_name=cinder cinder_store_password=nomoresecret cinder_store_project_name=service cinder_volume_type=hblocka cinder_enforce_multipath=True cinder_use_multipath=True rootwrap_config = /etc/cinder/rootwrap.conf [cinder-b] cinder_os_region_name=RegionOne cinder_store_auth_address=http://10.179.32.198:5000/v3 cinder_store_user_name=cinder cinder_store_password=nomoresecret cinder_store_project_name=service cinder_volume_type=hblockb cinder_enforce_multipath=True cinder_use_multipath=True rootwrap_config = /etc/cinder/rootwrap.conf
部分参数描述,具体详细参数请参考OpenStack官网。
参数 描述 show_image_direct_url 是否允许通过直接url的方式表示镜像。
取值:
True。
False。
说明
在使用Stor Cinder进行镜像创建卷的场景下,支持采用克隆方式进行底层处理。如果使用克隆进行底层处理,必须配置此项,且该项取值为True。
enabled_backends 存储标识符和存储类型。配置形式为key:value。value的合法值为file、rbd、http、swift、cinder。key为default_backend的值。
说明
可以一次配置多个key:value,以英文逗号隔开,如key1:value1,key1:value2。enabled_backends中的每一个key都需要有一个单独的一个配置组[key],配置组中需要配置该配置的所有详细配置项。
default_backend 必须为enabled_backends中的key。 cinder_os_region_name 从服务目录中查找cinder服务的区域名称。 cinder_store_auth_address Openstack实际的identity服务url,对应的账户密码需找管理员获取。在PackStack部署模式下,此值为类似的地址: http://10.179.32.198:5000/v3。 cinder_store_user_name OpenStack鉴权账户名。 cinder_store_password OpenStack鉴权密码。 cinder_store_project_name 镜像卷存储在Cinder中的项目名称。 cinder_volume_type 在Cinder中创建卷的卷类型。 cinder_enforce_multipath 如果它被设置为True,则当Multipathd未运行时,镜像传输的卷附加将中止。
取值:
- True。
- False。
说明
如果HBlock集群版,需要配置为True,如果HBlock单机版,配置为False。仅在cinder_use_multipath设置为True时,才将此字段设置为True。
cinder_use_multipath 在部署中支持用于识别Mutipath的标记。
如果不支持多路径,则将其设置为False。
- True:Cinder使用多路径。
- False:Cinder不使用多路径。
说明
如果HBlock集群版,需要配置为True,如果HBlock单机版,配置为False。
rootwrap_config 用于以root用户身份运行命令的rootwrap配置文件的路径。
Cinder存储需要root特权才能运行镜像卷(用于连接到 iSCSI/FC 卷以及读/写卷数据等)。配置文件应允许cinder store和os-brick库所需的命令。
注意
注意:以下仅为示例,请按照实际的OpenStack环境信息进行填写。
[DEFAULT] show_image_direct_url = True enabled_backends="file:file,cinder:cinder,cinder-stor8:cinder" [glance_store] stores=file,cinder default_backend=file [file] filesystem_store_datadir = /opt/stack/data/glance/images/ [os_glance_tasks_store] filesystem_store_datadir = /opt/stack/data/glance/tasks_work_dir [os_glance_staging_store] filesystem_store_datadir = /opt/stack/data/glance/staging [cinder] cinder_os_region_name=RegionOne cinder_store_auth_address=http://10.179.32.198:5000/v3 # cinder_store_auth_address为openstack实际的identity服务url, 对应的账户密码需找管理员获取。 cinder_store_user_name=cinder cinder_store_password=nomoresecret cinder_store_project_name=service cinder_volume_type=stor cinder_enforce_multipath=True cinder_use_multipath=True rootwrap_config = /etc/cinder/rootwrap.conf [cinder-stor8] cinder_os_region_name=RegionOne cinder_store_auth_address=http://10.179.32.198:5000/v3 cinder_store_user_name=admin cinder_store_password=0ac3ffd8157c4692 cinder_store_project_name=admin cinder_volume_type=stor8 cinder_enforce_multipath=False cinder_use_multipath=False rootwrap_config = /etc/cinder/rootwrap.conf
命令行创建images。
[root@controller gw(keystone_admin)]# glance image-create --name centos-instance-test1 --visibility public --disk-format raw --container-format bare --file /home/gw/output.raw --store cinder-stor8 +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | 56730d3091a764d5f8b38feeef0bfcef | | container_format | bare | | created_at | 2025-05-09T06:15:25Z | | direct_url | cinder://cinder-stor8/313eaedf-3e11-4da3-b5ca-0723fc356c14 | | disk_format | raw | | id | 12072d0b-b47d-435b-a5c4-cc77f9ed9742 | | min_disk | 0 | | min_ram | 0 | | name | centos-instance-test1 | | os_hash_algo | sha512 | | os_hash_value | 34f5709bc2363eafe857ba1344122594a90a9b8cc9d80047c35f7e34e8ac28ef1e14e2e3c13d55a4 | | | 3b841f533435e914b01594f2c14dd597ff9949c8389e3006 | | os_hidden | False | | owner | 97be599dfa1f4d2584719a2511b82207 | | protected | False | | size | 41126400 | | status | active | | stores | cinder-stor8 | | tags | [] | | updated_at | 2025-05-09T06:15:30Z | | virtual_size | 41126400 | | visibility | public | +------------------+----------------------------------------------------------------------------------+ [root@controller gw(keystone_admin)]# glance image-create --name centos-instance-test2 --visibility public --disk-format qcow2 --container-format bare --file /home/gw/cirros-0.3.4-x86_64-disk.img --store cinder-stor8 +------------------+----------------------------------------------------------------------------------+ | Property | Value | +------------------+----------------------------------------------------------------------------------+ | checksum | ee1eca47dc88f4879d8a229cc70a07c6 | | container_format | bare | | created_at | 2025-05-09T08:02:01Z | | direct_url | cinder://cinder-stor8/4c3d3910-4fbf-4a01-b434-2ce65263f02c | | disk_format | qcow2 | | id | c1995b47-d3a8-4d34-9bd0-d904388d88ae | | min_disk | 0 | | min_ram | 0 | | name | centos-instance-test2 | | os_hash_algo | sha512 | | os_hash_value | 1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f7 | | | 39d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2 | | os_hidden | False | | owner | 97be599dfa1f4d2584719a2511b82207 | | protected | False | | size | 13287936 | | status | active | | stores | cinder-stor8 | | tags | [] | | updated_at | 2025-05-09T08:02:04Z | | virtual_size | 41126400 | | visibility | public | +------------------+----------------------------------------------------------------------------------+
检查创建的images。
[root@controller gw(keystone_admin)]# glance image-list +--------------------------------------+------------------------+ | ID | Name | +--------------------------------------+------------------------+ | 12072d0b-b47d-435b-a5c4-cc77f9ed9742 | centos-instance-test1 | | c1995b47-d3a8-4d34-9bd0-d904388d88ae | centos-instance-test2 | +--------------------------------------+------------------------+
创建卷。
[root@controller gw(keystone_admin)]# cinder create --name stor8-test3 --image-id 12072d0b-b47d-435b-a5c4-cc77f9ed9742 --volume-type stor8 100 +--------------------------------+--------------------------------------+ | Property | Value | +--------------------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | cluster_name | None | | consistencygroup_id | None | | consumes_quota | True | | created_at | 2025-05-09T08:48:00.000000 | | description | None | | encrypted | False | | group_id | None | | id | d4f7fa8a-4090-4b34-8084-cde24755a56b | | metadata | {} | | migration_status | None | | multiattach | False | | name | stor8-test3 | | os-vol-host-attr:host | None | | os-vol-mig-status-attr:migstat | None | | os-vol-mig-status-attr:name_id | None | | os-vol-tenant-attr:tenant_id | 97be599dfa1f4d2584719a2511b82207 | | provider_id | None | | replication_status | None | | service_uuid | None | | shared_targets | True | | size | 100 | | snapshot_id | None | | source_volid | None | | status | creating | | updated_at | None | | user_id | d60fa5458fda4f96bbf581bf6c2dd63e | | volume_type | stor8 | | volume_type_id | 997c4eb1-4473-4c0a-a1f6-4f4967fd2c3a | +--------------------------------+--------------------------------------+