Cinder组件详解
一、Cinder组件介绍
Cinder前身是 Nova 中的 nova-volume 服务,在 Folsom 版本发布时,从 Nova 中剥离作为一个独立的 Openstack 项目存在。
Cinder 类似 Amazon 的 EBS(Elastic Block Storage),为虚拟机提供持久化的块存储能力
,实现虚拟机存储卷(Volume)的创建、挂载、卸载、快照(snapshot)等生命周期管理。
1、概念
cinder组件作用:
- 块存储服务,为运行实例提供稳定的数据块存储服务。
- 块存储服务,提供对
volume
从创建到删除整个生命周期的管理。
块存储(Block Storage):“块”是指存储系统采用一整块的存储设备。块存储可虚拟出整块硬盘给云主机使用。
文件存储(File Storage):依靠文件系统来存储文件,文件直接存储在文件系统中,通过FTP、NFS等服务进行访问。
2、核心架构
Cinder主要由 cinder-api、cinder-scheduler、cinder-volume、volume-provider、volume-backup几个服务所组成,它们之间通过 AMQP消息队列进行通信。
3、核心组件
在块存储中,裸硬盘通常被称为卷(Volume),Cinder的任务就是管理卷,包括卷的创建、删除等操作。
模块名 | 功能说明 |
---|---|
cinder-api | 用于接收和响应外部请求,也是外部可用于管理Cinder的唯一入口。 |
cinder-volume | 对卷管理的模块,运行在存储节点上管理具体存储设备的存储空间。 |
cinder-scheduler | 负责通过调度算法从多个存储节点中选择合适的节点来处理用户请求(创建卷)。 |
volume-provider | 负责通过驱动调用具体的卷管理系统实现对卷的具体操作。支持多种卷管理系统:LVM、NFS、Ceph等 |
volume-backup | 为卷提供备份服务 |
message queue | 各个子服务通过消息队列实现进程间通信和相互协作。 |
database cinder | 存储数据文件的数据库。 |
4、工作流程
Cinder各个模块分工合作的大致流程如下(注意模块之间的通信都是通过消息队列传递的)。
- “cinder-api”接收到用户通过管理界面或命令行发起的卷创建请求后,完成必要处理后将其发送到消息队列中。
- “cinder-scheduler”从消息队列获得请求和数据以后,从若干存储节点中选出一个能存放该卷的节点。然后又将信息发送到消息队列。
- “cinder-volume”从消息队列获取请求后,通过“volume-provider”调用具体的卷管理系统在存储设备上创建卷。
二、常用操作
1、Volume管理
(1)openstack命令格式案例
# 查看卷列表
[root@controller ~]# openstack volume list
+--------------------------------------+------+--------+------+------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+------+--------+------+------------------------------+
| 8fff2b49-f0b1-45c4-b89f-89d1ccb4be9f | | in-use | 12 | Attached to vm1 on /dev/vda |
+--------------------------------------+------+--------+------+------------------------------+
# 查看卷详情
[root@controller ~]# openstack volume show 8fff2b49-f0b1-45c4-b89f-89d1ccb4be9f
+--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| attachments | [{u'server_id': u'2797b1d1-c962-47c3-9d3f-c8b0519bbbf5', u'attachment_id': u'605b8042-24f9-405c-ac6b-010aa698f3c4', u'attached_at': u'2024-11-27T10:55:53.000000', u'host_name': None, u'volume_id': u'8fff2b49-f0b1-45c4-b89f-89d1ccb4be9f', u'device': u'/dev/vda', u'id': u'8fff2b49-f0b1-45c4-b89f-89d1ccb4be9f'}] |
| availability_zone | nova |
| bootable | true |
| consistencygroup_id | None |
| created_at | 2024-11-27T10:55:47.000000 |
| description | |
| encrypted | False |
| id | 8fff2b49-f0b1-45c4-b89f-89d1ccb4be9f |
| migration_status | None |
| multiattach | False |
| name | |
| os-vol-host-attr:host | compute@lvm#LVM |
| os-vol-mig-status-attr:migstat | None |
| os-vol-mig-status-attr:name_id | None |
| os-vol-tenant-attr:tenant_id | dd7e899b615d4e1baa88fee42ad89913 |
| properties | attached_mode='rw' |
| replication_status | None |
| size | 12 |
| snapshot_id | None |
| source_volid | None |
| status | in-use |
| type | __DEFAULT__ |
| updated_at | 2024-11-27T10:55:53.000000 |
| user_id | e23d783ff5ce4899910a9b746a8668e8 |
| volume_image_metadata | {u'checksum': u'1d3062cd89af34e419f7100277f38b2b', u'min_ram': u'0', u'disk_format': u'qcow2', u'image_name': u'cirros', u'image_id': u'b329a268-3db9-41fe-b976-167056aa1922', u'signature_verified': u'False', u'container_format': u'bare', u'min_disk': u'0', u'size': u'16338944'} |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
# 卷创建
usage: openstack volume create [-h等选项] <name>
positional arguments:
<name> Volume name 卷名称
optional arguments:
-h, --help show this help message and exit
--size <size> Volume size in GB (Required unless --snapshot or 卷的大小(GB)
--source is specified)
--type <volume-type> Set the type of volume 卷的类型
--image <image> Use <image> as source of volume (name or ID) 使用某镜像作为卷的源
--snapshot <snapshot>
Use <snapshot> as source of volume (name or ID) 使用某快照作为卷的源
--source <volume> Volume to clone (name or ID) 使用某个卷克隆
--description <description>
Volume description 卷描述信息
--availability-zone <availability-zone>
Create volume in <availability-zone> 创建卷的可用域
--consistency-group consistency-group>
Consistency group where the new volume belongs to 新卷所属的一致性组
--property <key=value>
Set a property to this volume (repeat option to set 设置卷的属性(键值对)
multiple properties)
--hint <key=value> Arbitrary scheduler hint key-value pairs to help boot 任意调度程序提示键值对以帮助启动实例
an instance (repeat option to set multiple hints) (重复选项以设置多个提示)
--bootable Mark volume as bootable 标记卷可引导
--non-bootable Mark volume as non-bootable (default) 标记卷不可引导(默认)
--read-only Set volume to read-only access mode 设置卷为只读访问模式
--read-write Set volume to read-write access mode (default) 设置卷为读写模式(默认)
[root@controller ~]# openstack volume create --description "new volume" --availability-zone nova --size 2 test-vol
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2024-12-18T06:35:45.000000 |
| description | new volume |
| encrypted | False |
| id | 6e4f4cbf-7f10-4560-801b-d80f545bc014 |
| migration_status | None |
| multiattach | False |
| name | test-vol |
| properties | |
| replication_status | None |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | e23d783ff5ce4899910a9b746a8668e8 |
+---------------------+--------------------------------------+
# 删除卷
[root@controller ~]# openstack volume delete test-vol
# 卷更新
openstack volume set [-h] [--name <name>] [--size <size>]... <volume>
optional arguments:
-h, --help show this help message and exit
--name <name> New volume name 新的卷名称
--size <size> Extend volume size in GB 扩展卷(只能更大)
--description <description>
New volume description 设置新的卷描述
--no-property Remove all properties from <volume> (specify both 删除卷的所有属性
--no-property and --property to remove the current
properties before setting new properties.)
--property <key=value>
Set a property on this volume (repeat option to set 设置卷属性
multiple properties)
--image-property <key=value>
Set an image property on this volume (repeat option to 设置镜像属性给卷
set multiple image properties)
--state <state> New volume state ("available", "error", "creating", 设置卷的状态
"deleting", "in-use", "attaching", "detaching",
"error_deleting" or "maintenance") (admin only) (This
option simply changes the state of the volume in the
database with no regard to actual status, exercise
caution when using)
--attached Set volume attachment status to "attached" (admin 设置卷的附加状态为已附加
only) (This option simply changes the state of the
volume in the database with no regard to actual
status, exercise caution when using)
--detached Set volume attachment status to "detached" (admin 设置卷的附加状态为未附加
only) (This option simply changes the state of the
volume in the database with no regard to actual
status, exercise caution when using)
--type <volume-type> New volume type (name or ID) 新卷的类型
--retype-policy <retype-policy>
Migration policy while re-typing volume ("never" or
"on-demand", default is "never" ) (available only when
--type option is specified) 重新键入卷时的迁移策略(“从不”或“按需”,默认为“从不”)(仅在指定--type选项时可用)
--bootable Mark volume as bootable 标记卷为可引导
--non-bootable Mark volume as non-bootable 标记卷为不可引导
--read-only Set volume to read-only access mode 标记卷只读
--read-write Set volume to read-write access mode 标记卷读写
# 1)重命名
[root@controller ~]# openstack volume set --name yun1-test-vol test-vol
[root@controller ~]# openstack volume list
+--------------------------------------+---------------+-----------+------+------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------------+-----------+------+------------------------------+
| 5da1d301-1325-4ddc-a48f-e281419e9345 | yun1-test-vol | available | 2 | |
# 2)修改状态
# 可修改的状态:"available", "error", "creating", "deleting", "in-use", "attaching", "detaching", "error_deleting" and "maintenance".
# 附加状态:"attached" , "detached". 默认状态为:None.
cinder reset-state [--state <state>,--attach-status <attach-status>,--reset-migration-status] <volume>
[root@controller ~]# openstack volume set --state deleting yun1-test-vol
[root@controller ~]# openstack volume list
+--------------------------------------+---------------+----------+------+------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------------+----------+------+------------------------------+
| 5da1d301-1325-4ddc-a48f-e281419e9345 | yun1-test-vol | deleting | 2 |
# 注意:使用"--attached" , "--detached"无法真的修改附加状态,此选项仅更改数据库中卷的状态,与实际状态无关。
# 3)卷扩容
[root@controller ~]# openstack volume set --size 1 yun1-test-vol
Failed to set volume size: Volume is in deleting state, it must be available before size can be extended
One or more of the set operations failed
[root@controller ~]# openstack volume set --state available yun1-test-vol
[root@controller ~]# openstack volume list
+--------------------------------------+---------------+-----------+------+------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------------+-----------+------+------------------------------+
| 5da1d301-1325-4ddc-a48f-e281419e9345 | yun1-test-vol | available | 2 | |
+--------------------------------------+---------------+-----------+------+------------------------------+
[root@controller ~]# openstack volume set --size 1 yun1-test-vol
Failed to set volume size: New size must be greater than 2 GB # 修改卷只能更大不能更小
One or more of the set operations failed
[root@controller ~]# openstack volume set --size 3 yun1-test-vol
[root@controller ~]# openstack volume list
+--------------------------------------+---------------+-----------+------+------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+---------------+-----------+------+------------------------------+
| 5da1d301-1325-4ddc-a48f-e281419e9345 | yun1-test-vol | available | 3 |
(2)cinder命令格式案例
# 卷列表查看
[root@controller ~]# cinder list
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
| 9f9022f5-1b11-447e-bc0c-d3889712120a | available | test2 | 1 | - | false | |
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
# 卷详情查看
[root@controller ~]# cinder show test2
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2021-11-14T02:16:13.000000 |
| description | None |
| encrypted | False |
| id | 9f9022f5-1b11-447e-bc0c-d3889712120a |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | test2 |
| os-vol-host-attr:host | compute@lvm#LVM |
| os-vol-mig-status-attr:migstat | None |
| os-vol-mig-status-attr:name_id | None |
| os-vol-tenant-attr:tenant_id | 386dbfcf77e444c7872e4e23d5829fcc |
| replication_status | disabled |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | available |
| updated_at | 2021-11-14T02:16:14.000000 |
| user_id | 0f217182b5af448c988f5464c706a337 |
| volume_type | None |
+--------------------------------+--------------------------------------+
# 卷创建
# size只能是整数
cinder create [--name <name>, --volume-type <type>] <size(GB)>
[root@controller ~]# cinder create --name test --description 'new volume' --availability-zone nova 2
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2021-11-14T02:54:52.000000 |
| description | new volume |
| encrypted | False |
| id | 8190367e-4874-4e5e-86f7-0a3c4e2ae4cc |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | test |
| 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 | 386dbfcf77e444c7872e4e23d5829fcc |
| replication_status | disabled |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| updated_at | None |
| user_id | 0f217182b5af448c988f5464c706a337 |
| volume_type | None |
+--------------------------------+--------------------------------------+
# 卷删除
cinder delete <volume>
[root@controller ~]# cinder delete test
Request to delete volume test has been accepted.
# 卷更新
# 1.重命名
cinder rename <volume> <name>
[root@controller ~]# cinder rename test test-volume-01
[root@controller ~]# cinder list
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
| 5b117210-9f6e-4d2c-94f4-66c2e3953584 | available | test-volume-01 | 2 | - | false | |
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
# 2.修改状态
# 可修改的状态:"available", "error", "creating", "deleting", "in-use", "attaching", "detaching", "error_deleting" and "maintenance".
# 附加状态:"attached" , "detached". 默认状态为:None.
cinder reset-state [--state <state>,--attach-status <attach-status>,--reset-migration-status] <volume>
[root@controller ~]# cinder reset-state --state deleting test-volume-01
[root@controller ~]# cinder list
+--------------------------------------+----------+----------------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+----------+----------------+------+-------------+----------+-------------+
| 5b117210-9f6e-4d2c-94f4-66c2e3953584 | deleting | test-volume-01 | 2 | - | false | |
+--------------------------------------+----------+----------------+------+-------------+----------+-------------+
# 3.修改类型
# 注意:改状态卷状态必须是available状态
cinder retype <volume> <volume_type>
# 1)修改卷状态为available
[root@controller ~]# cinder reset-state --state available test-volume-01
# 2)查看(创建)卷类型
[root@controller ~]# cinder type-create lvm
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| b16ab5aa-f9d2-4402-89a8-1a72e9c51914 | lvm | - | True |
+--------------------------------------+------+-------------+-----------+
[root@controller ~]# cinder type-list
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 5780bda0-0ac4-4f5a-a8c4-807980c28aaa | 性能 | | True |
| b16ab5aa-f9d2-4402-89a8-1a72e9c51914 | lvm | - | True |
+--------------------------------------+------+-------------+-----------+
# 3)修改为对应的类型
[root@controller ~]# cinder retype test-volume-01 5780bda0-0ac4-4f5a-a8c4-807980c28aaa
[root@controller ~]# cinder show test-volume-01
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2021-11-14T02:56:04.000000 |
| description | new volume |
| encrypted | False |
| id | 5b117210-9f6e-4d2c-94f4-66c2e3953584 |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | test-volume-01 |
| os-vol-host-attr:host | compute@lvm#LVM |
| os-vol-mig-status-attr:migstat | None |
| os-vol-mig-status-attr:name_id | None |
| os-vol-tenant-attr:tenant_id | 386dbfcf77e444c7872e4e23d5829fcc |
| replication_status | disabled |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | available |
| updated_at | 2021-11-14T03:00:07.000000 |
| user_id | 0f217182b5af448c988f5464c706a337 |
| volume_type | 性能 |
+--------------------------------+--------------------------------------+
# 4.扩容
# 注意:可以从小改大,但是不可以从大改小。
# 注意:卷大小只能设置为整数值。
cinder extend <volume> <new size>
[root@controller ~]# cinder extend test-volume-01 5
[root@controller ~]# cinder list
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
| 5b117210-9f6e-4d2c-94f4-66c2e3953584 | available | test-volume-01 | 5 | 性能 | false | |
+--------------------------------------+-----------+----------------+------+-------------+----------+-------------+
# 5.迁移
# 迁移一个卷到特定的主机,在请求体中指定 os-migrate_volume action。
# 一般不推荐对处于in-use状态,且挂载在多个虚机上的卷进行迁移。
# 默认只有管理员用户有迁移的权限,但是可以通过policy.json文件进行权限的设置。
cinder migrate <volume> <host>
2、Type管理
(1)openstack命令格式案例
openstack volume type create 创建卷类型
volume type delete 删除卷类型
volume type list 查看卷类型列表
volume type set 修改卷类型
volume type show 查看卷类型详情
volume type unset 取消卷类型属性
# 查看卷类型列表
[root@controller ~]# openstack volume type list
+--------------------------------------+-------------+-----------+
| ID | Name | Is Public |
+--------------------------------------+-------------+-----------+
| 3f409230-f501-407e-85f7-ab85f7dacbcc | __DEFAULT__ | True |
+--------------------------------------+-------------+-----------+
# 创建卷类型
openstack volume type create [--description <description>] [--public | --private][...] <name>
optional arguments:
--description <description>
Volume type description 卷类型描述
--public Volume type is accessible to the public 卷类型公开
--private Volume type is not accessible to the public 卷类型不公开
--property <key=value>
Set a property on this volume type (repeat option to 设置属性
set multiple properties)
--project <project> Allow <project> to access private type (name or ID) 允许某项目访问私有类型
(Must be used with --private option)
--encryption-provider <provider> 设置此卷类型的加密提供程序格式(例如“luks”或“plain”)(仅限管理员)
Set the encryption provider format for this volume
type (e.g "luks" or "plain") (admin only) (This option
is required when setting encryption type of a volume.
Consider using other encryption options such as:
"--encryption-cipher", "--encryption-key-size" and
"--encryption-control-location")
--encryption-cipher <cipher> 设置此卷的加密算法或模式
Set the encryption algorithm or mode for this volume
type (e.g "aes-xts-plain64") (admin only)
--encryption-key-size <key-size> 设置此卷类型的加密密钥的大小
Set the size of the encryption key of this volume type
(e.g "128" or "256") (admin only)
--encryption-control-location <control-location> 设置执行加密的名义服务
Set the notional service where the encryption is
performed ("front-end" or "back-end") (admin only)
(The default value for this option is "front-end" when
setting encryption type of a volume. Consider using
other encryption options such as: "--encryption-
cipher", "--encryption-key-size" and "--encryption-
provider")
--project-domain <project-domain> 项目所属的域(名称或ID)
Domain the project belongs to (name or ID). This can
be used in case collisions between project names
exist.
# 创建卷类型
[root@controller ~]# openstack volume type create sata-hb-project
+-------------+--------------------------------------+
| Field | Value |
+-------------+--------------------------------------+
| description | None |
| id | fd467064-2661-4494-848d-0ad6cb1668ed |
| is_public | True |
| name | sata-hb-project |
+-------------+--------------------------------------+
# 删除卷类型
[root@controller ~]# openstack volume type delete sata-hb-project
# 修改卷类型
[root@controller ~]# openstack volume type create yun1-ssd
+-------------+--------------------------------------+
| Field | Value |
+-------------+--------------------------------------+
| description | None |
| id | e575aef9-f066-4dde-bea6-320208a6904b |
| is_public | True |
| name | yun1-ssd |
+-------------+--------------------------------------+
[root@controller ~]# openstack volume type set --name yun1-best-ssd --description "best of all" yun1-ssd
[root@controller ~]# openstack volume type show yun1-best-ssd
+--------------------+--------------------------------------+
| Field | Value |
+--------------------+--------------------------------------+
| access_project_ids | None |
| description | best of all |
| id | e575aef9-f066-4dde-bea6-320208a6904b |
| is_public | True |
| name | yun1-best-ssd |
| properties | |
| qos_specs_id | None |
+--------------------+--------------------------------------+
(2)cinder命令格式案例
type-create Creates a volume type. # 类型创建
type-default List the default volume type.
type-delete Deletes a volume type. # 类型删除
type-key Sets or unsets extra_spec for a volume type.
type-list Lists available 'volume types'. (Admin only will see
private types) # 类型列表查看
type-show Show volume type details. # 类型详情查看
type-update Updates volume type name, description, and/or
is_public. # 类型更新
# 查看类型
cinder type-list
[root@controller ~]# cinder type-list
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 5780bda0-0ac4-4f5a-a8c4-807980c28aaa | 性能 | | True |
| b16ab5aa-f9d2-4402-89a8-1a72e9c51914 | lvm | - | True |
+--------------------------------------+------+-------------+-----------+
# 创建类型
cinder type-create [ --description <description>, --is-public <is-public>] <name>
Positional arguments:
<name> Name of new volume type.
Optional arguments:
--description <description>
Description of new volume type.
--is-public <is-public>
Make type accessible to the public (default true).
[root@controller ~]# cinder type-create sata-hb-project
+--------------------------------------+-----------------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+-----------------+-------------+-----------+
| ac57dcb7-d157-419f-bd63-3ea0eb6ff940 | sata-hb-project | - | True |
+--------------------------------------+-----------------+-------------+-----------+
# 删除类型
# 注意:必须使用卷类型的id
cinder type-delete <type_id>
[root@controller ~]# cinder type-delete lvm
ERROR: Volume type lvm could not be found. (HTTP 404) (Request-ID: req-6144d4f5-61ee-4b83-b45d-f11ac54b8229)
[root@controller ~]# cinder type-delete ac57dcb7-d157-419f-bd63-3ea0eb6ff940
[root@controller ~]# cinder type-list
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 5780bda0-0ac4-4f5a-a8c4-807980c28aaa | 性能 | | True |
| b16ab5aa-f9d2-4402-89a8-1a72e9c51914 | lvm | - | True |
+--------------------------------------+------+-------------+-----------+
# 修改类型
cinder type-update [--name <name>,--description <description>,--is-public <is-public>] <type_id>
[root@controller ~]# cinder type-update b16ab5aa-f9d2-4402-89a8-1a72e9c51914 --name ssd --description 'best of all'
+--------------------------------------+------+-------------+-----------+
| ID | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| b16ab5aa-f9d2-4402-89a8-1a72e9c51914 | ssd | best of all | False |
+--------------------------------------+------+-------------+-----------+
3、Snapshot快照管理
(1)openstack命令行格式案例
# 语法
openstack
server image create Create a new server disk image from an existing server # 为已存在的服务器创建一个新的硬盘镜像
volume snapshot create Create new volume snapshot # 创建新的卷快照
volume snapshot delete Delete volume snapshot(s) # 删除卷快照
volume snapshot list List volume snapshots # 查看卷快照列表
volume snapshot set Set volume snapshot properties # 修改卷快照属性
volume snapshot show Display volume snapshot details # 查看卷快照详情
volume snapshot unset Unset volume snapshot properties # 取消卷快照修改设置
# 创建一个云主机
openstack server create VM_host --image cirros --flavor m1.small --network vir-net
# 对云主机拍摄快照生成镜像,可用来还原云主机或创建新云主机
# 语法:
openstack server image create [--name <image-name>] [--wait] <server>
# 为云主机拍快照,生成镜像
[root@controller ~]# openstack server image create hqs01 --name vmSnapshot
[root@controller ~]# openstack image list
+--------------------------------------+------------------+--------+
| ID | Name | Status |
+--------------------------------------+------------------+--------+
| 356cdc45-ad0b-493c-a0ba-cf3a889ec23b | centos7.2 | active |
| 1eb75af5-43ef-44e0-9367-83681181312a | centos7.5-docker | active |
| 7096885c-0a58-4086-8014-b92affceb0e8 | cirros | active |
| 26a9da63-b975-4512-ac1a-9432c31a8f0d | vmSnapshot | active |
+--------------------------------------+------------------+--------+
# 操作前置——有卷volume存在
[root@controller ~]# openstack volume list
# 创建卷快照
openstack volume snapshot create [--options] <snapshot-name>
--volume <volume> Volume to snapshot (name or ID) (default is <snapshot-
name>) # 指定要快照的卷
--description <description> # 描述快照
Description of the snapshot
--force Create a snapshot attached to an instance. Default is
False # 强制拍快照,默认只有available的卷可以快照
--property <key=value> # 设置快照的属性
Set a property to this snapshot (repeat option to set
multiple properties)
--remote-source <key=value> # 远程快照属性?
The attribute(s) of the exsiting remote volume
snapshot (admin required)
[root@controller ~]# openstack volume snapshot create --description 'test snapshot' --volume 87d595dd-3089-4d37-b8e4-bc0a597c92c7 --force hqs01_backup
+-------------+--------------------------------------+
| Field | Value |
+-------------+--------------------------------------+
| created_at | 2022-12-09T12:01:21.472986 |
| description | test snapshot |
| id | d23fb39f-7078-46ef-9148-be9f42145838 |
| name | hqs01_backup |
| properties | |
| size | 10 |
| status | creating |
| updated_at | None |
| volume_id | 87d595dd-3089-4d37-b8e4-bc0a597c92c7 |
+-------------+--------------------------------------+
# 查看卷快照列表(包含openstack server image create创的)
[root@controller ~]# openstack volume snapshot list
+--------------------------------------+-------------------------+---------------+-----------+------+
| ID | Name | Description | Status | Size |
+--------------------------------------+-------------------------+---------------+-----------+------+
| d23fb39f-7078-46ef-9148-be9f42145838 | hqs01_backup | test snapshot | available | 10 |
| f6829d63-9ac6-419e-91df-8fb2cb489bbb | snapshot for vmSnapshot | | available | 10 |
+--------------------------------------+-------------------------+---------------+-----------+------+
# 查看卷快照详情
[root@controller ~]# openstack volume snapshot show hqs01_backup
+--------------------------------------------+--------------------------------------+
| Field | Value |
+--------------------------------------------+--------------------------------------+
| created_at | 2022-12-09T12:01:21.000000 |
| description | test snapshot |
| id | d23fb39f-7078-46ef-9148-be9f42145838 |
| name | hqs01_backup |
| os-extended-snapshot-attributes:progress | 100% |
| os-extended-snapshot-attributes:project_id | 4188570a34464b938ed3fa7e08681df8 |
| properties | |
| size | 10 |
| status | available |
| updated_at | 2022-12-09T12:01:22.000000 |
| volume_id | 87d595dd-3089-4d37-b8e4-bc0a597c92c7 |
+--------------------------------------------+--------------------------------------+
# 删除卷快照
[root@controller ~]# openstack volume snapshot delete hqs01_backup
(2)cinder命令行格式案例
# 语法
cinder
snapshot-create Creates a snapshot.
snapshot-delete Removes one or more snapshots.
snapshot-list Lists all snapshots.
snapshot-show Shows snapshot details.
snapshot-rename Renames a snapshot.
snapshot-reset-state
Explicitly updates the snapshot state.
snapshot-manage Manage an existing snapshot.
snapshot-unmanage Stop managing a snapshot.
snapshot-metadata Sets or deletes snapshot metadata.
snapshot-metadata-show
Shows snapshot metadata.
snapshot-metadata-update-all
Updates snapshot metadata.
# 创建快照
cinder snapshot-create [--name <name>,--force [<True|False>],--description <description>,--metadata [<key=value> [<key=value> ...]]] <volume>
[root@controller keystone]# cinder snapshot-create --name snapshot-01 --description 'test snapshot of a volume' 92ad953c-a7a1-4ef7-8929-85835143cb26
+-------------+--------------------------------------+
| Property | Value |
+-------------+--------------------------------------+
| created_at | 2021-11-04T15:17:24.382623 |
| description | test snapshot of a volume |
| id | b360d2c0-9a32-4d5b-afe3-112f6cd0e215 |
| metadata | {} |
| name | snapshot-01 |
| size | 2 |
| status | creating |
| updated_at | None |
| volume_id | 92ad953c-a7a1-4ef7-8929-85835143cb26 |
+-------------+--------------------------------------+
# 查看快照列表
cinder snapshot-list
[root@controller keystone]# cinder snapshot-list
+--------------------------------------+--------------------------------------+-----------+-------------+------+
| ID | Volume ID | Status | Name | Size |
+--------------------------------------+--------------------------------------+-----------+-------------+------+
| b360d2c0-9a32-4d5b-afe3-112f6cd0e215 | 92ad953c-a7a1-4ef7-8929-85835143cb26 | available | snapshot-01 | 2 |
+--------------------------------------+--------------------------------------+-----------+-------------+------+
# 查看快照详情
cinder snapshot-show <snapshot>
[root@controller keystone]# cinder snapshot-show snapshot-01
+--------------------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------------------+--------------------------------------+
| created_at | 2021-11-04T15:17:24.000000 |
| description | test snapshot of a volume |
| id | b360d2c0-9a32-4d5b-afe3-112f6cd0e215 |
| metadata | {} |
| name | snapshot-01 |
| os-extended-snapshot-attributes:progress | 100% |
| os-extended-snapshot-attributes:project_id | 386dbfcf77e444c7872e4e23d5829fcc |
| size | 2 |
| status | available |
| updated_at | 2021-11-04T15:17:24.000000 |
| volume_id | 92ad953c-a7a1-4ef7-8929-85835143cb26 |
+--------------------------------------------+--------------------------------------+
# 删除快照
cinder snapshot-delete <snapshot>
[root@controller keystone]# cinder snapshot-delete snapshot-01
[root@controller keystone]# cinder snapshot-list
+----+-----------+--------+------+------+
| ID | Volume ID | Status | Name | Size |
+----+-----------+--------+------+------+
+----+-----------+--------+------+------+
# 快照改名
cinder snapshot-rename [--description <description>] <snapshot> [<name>]
[root@controller keystone]# cinder snapshot-rename --description 'You Have Only One Life' snapshot-01 new-test-snapshot
[root@controller keystone]# cinder snapshot-show snapshot-01
ERROR: No snapshot with a name or ID of 'snapshot-01' exists.
[root@controller keystone]# cinder snapshot-show new-test-snapshot
+--------------------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------------------+--------------------------------------+
| created_at | 2021-11-04T15:19:39.000000 |
| description | You Have Only One Life |
| id | a54e8e02-911c-482f-bc49-fac2060ad7c3 |
| metadata | {} |
| name | new-test-snapshot |
| os-extended-snapshot-attributes:progress | 100% |
| os-extended-snapshot-attributes:project_id | 386dbfcf77e444c7872e4e23d5829fcc |
| size | 2 |
| status | available |
| updated_at | 2021-11-04T15:36:26.000000 |
| volume_id | 92ad953c-a7a1-4ef7-8929-85835143cb26 |
+--------------------------------------------+--------------------------------------+
# 更新快照状态
# 可更新的状态:"available", "error", "creating", "deleting", and "error_deleting".
cinder snapshot-reset-state [--state <state>] <snapshot> [<snapshot> ...]
[root@controller keystone]# cinder snapshot-reset-state --state error new-test-snapshot
[root@controller keystone]# cinder snapshot-show new-test-snapshot
+--------------------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------------------+--------------------------------------+
| created_at | 2021-11-04T15:19:39.000000 |
| description | You Have Only One Life |
| id | a54e8e02-911c-482f-bc49-fac2060ad7c3 |
| metadata | {} |
| name | new-test-snapshot |
| os-extended-snapshot-attributes:progress | 100% |
| os-extended-snapshot-attributes:project_id | 386dbfcf77e444c7872e4e23d5829fcc |
| size | 2 |
| status | error |
| updated_at | 2021-11-04T15:39:40.000000 |
| volume_id | 92ad953c-a7a1-4ef7-8929-85835143cb26 |
+--------------------------------------------+--------------------------------------+
# 管理快照
cinder snapshot-manage [--id-type <id-type>,--name <name>,--description <description>,] [--name <name>,--metadata [<key=value> [<key=value> ...]]]
<volume> <identifier>
[root@controller keystone]# cinder snapshot-manage test2 new-test-snapshot
+--------------------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------------------+--------------------------------------+
| created_at | 2021-11-04T15:46:23.000000 |
| description | None |
| id | 26efb6e5-ff02-47c0-bb1c-6a36718bd68a |
| metadata | {} |
| name | None |
| os-extended-snapshot-attributes:progress | 0% |
| os-extended-snapshot-attributes:project_id | 386dbfcf77e444c7872e4e23d5829fcc |
| size | 2 |
| status | creating |
| updated_at | None |
| volume_id | 456a40c6-65c4-41ee-9958-63bae91ec189 |
+--------------------------------------------+--------------------------------------+
# 停止管理快照
[root@controller keystone]# cinder snapshot-unmanage 26efb6e5-ff02-47c0-bb1c-6a36718bd68a
[root@controller keystone]# cinder snapshot-list
+--------------------------------------+--------------------------------------+-----------+-------------------+------+
| ID | Volume ID | Status | Name | Size |
+--------------------------------------+--------------------------------------+-----------+-------------------+------+
| a54e8e02-911c-482f-bc49-fac2060ad7c3 | 92ad953c-a7a1-4ef7-8929-85835143cb26 | available | new-test-snapshot | 2 |
+--------------------------------------+--------------------------------------+-----------+-------------------+------+
# 设置或删除快照的meta数据
cinder snapshot-metadata <snapshot> <action> <key=value>
[<key=value> ...]
Positional arguments:
<snapshot> ID of snapshot for which to update metadata.
<action> The action. Valid values are "set" or "unset."
<key=value> Metadata key and value pair to set or unset. For unset, specify
only the key.
# 设置快照meta
[root@controller keystone]# cinder snapshot-metadata a54e8e02-911c-482f-bc49-fac2060ad7c3 set function='Backup data'
+----------+-------------+
| Property | Value |
+----------+-------------+
| function | Backup data |
+----------+-------------+
[root@controller keystone]# cinder snapshot-metadata a54e8e02-911c-482f-bc49-fac2060ad7c3 set update-date='2021-11-24'
+-------------+-------------+
| Property | Value |
+-------------+-------------+
| function | Backup data |
| update-date | 2021-11-24 |
+-------------+-------------+
# 删除快照meta
[root@controller keystone]# cinder snapshot-metadata a54e8e02-911c-482f-bc49-fac2060ad7c3 unset update-date='2021-11-24'
[root@controller keystone]# cinder snapshot-metadata-show a54e8e02-911c-482f-bc49-fac2060ad7c3
+-------------------+-------------+
| Metadata-property | Value |
+-------------------+-------------+
| function | Backup data |
+-------------------+-------------+
# 查看快照meta数据
[root@controller keystone]# cinder snapshot-metadata-show a54e8e02-911c-482f-bc49-fac2060ad7c3
+-------------------+-------------+
| Metadata-property | Value |
+-------------------+-------------+
| function | Backup data |
| update-date | 2021-11-24 |
+-------------------+-------------+
# 更新快照meta数据
cinder snapshot-metadata-update-all <snapshot> <key=value>
[<key=value> ...]
[root@controller keystone]# cinder snapshot-metadata-update-all a54e8e02-911c-482f-bc49-fac2060ad7c3 create-date='2021-11-1 12:00:11' update-date='2021/11/24 17:24:15' function='tank T-54'
+----------+------------------------------------------------------------------------------------------------------------+
| Property | Value |
+----------+------------------------------------------------------------------------------------------------------------+
| metadata | {u'function': u'tank T-54', u'update-date': u'2021/11/24 17:24:15', u'create-date': u'2021-11-1 12:00:11'} |
+----------+------------------------------------------------------------------------------------------------------------+
[root@controller keystone]# cinder snapshot-metadata-show a54e8e02-911c-482f-bc49-fac2060ad7c3
+-------------------+---------------------+
| Metadata-property | Value |
+-------------------+---------------------+
| create-date | 2021-11-1 12:00:11 |
| function | tank T-54 |
| update-date | 2021/11/24 17:24:15 |
+-------------------+---------------------+
4、Backup管理
# 开启卷备份服务
systemctl restart openstack-cinder-backup
# 查看备份列表
cinder backup-list
# 查看备份详情
cinder backup-show <backup>
# 创建备份
cinder backup-create --name <name> [--container <container>] <volume>
# 删除备份
cinder backup-delete <backup>
# 恢复备份
cinder backup-restore [--volume <volume>] <backup>
# 备份导出
cinder backup-export <backup>
# 备份导入
cinder backup-import <backup_service> <backup_url>
三、高级操作
1、Qos管理
2、Transfer管理
3、Service管理
4、Consisgroup管理
5、Encryption管理
四、故障处理
1、cinder创建云硬盘状态错误
错误情况:创建一个云硬盘后,查询硬盘时显示error
[root@controller ~]# cinder create 1 --name test2
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2021-11-14T02:01:12.000000 |
| description | None |
| encrypted | False |
| id | dfad6645-73d3-4d0f-bd83-f8e50c48cb7b |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | test2 |
| 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 | 386dbfcf77e444c7872e4e23d5829fcc |
| replication_status | disabled |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| updated_at | None |
| user_id | 0f217182b5af448c988f5464c706a337 |
| volume_type | None |
+--------------------------------+--------------------------------------+
[root@controller ~]# cinder list
+--------------------------------------+--------+-------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+--------+-------+------+-------------+----------+-------------+
| dfad6645-73d3-4d0f-bd83-f8e50c48cb7b | error | test2 | 1 | - | false | |
+--------------------------------------+--------+-------+------+-------------+----------+-------------+
查询块存储服务日志,找到报错信息:
[root@controller cinder]# vi /var/log/cinder/scheduler.log
2021-11-13 20:54:38.708 1268 ERROR cinder.scheduler.flows.create_volume [req-afe87e8b-cc3a-4275-8e58-fb0034da8be7 0f217182b5af448c988f5464c706a337 386dbfcf77e444c7872e4e23d5829fcc - - -]
Failed to run task cinder.scheduler.flows.create_volume.ScheduleCreateVolumeTask;
volume:create: No valid host was found. No weighed hosts available
计算节点上查看openstack的组件服务状态:
[root@compute ~]# openstack-status
== Cinder services ==
openstack-cinder-api: inactive (disabled on boot)
openstack-cinder-scheduler: inactive (disabled on boot)
openstack-cinder-volume: active
openstack-cinder-backup: inactive (disabled on boot)
确保cinder显示active,正常启动。
本次错误原因:两个节点的系统时间不同,导致计算节点的openstack-cinder-volume服务down掉了。需要在计算节点做如下操作:
[root@compute ~]# ntpdate 192.168.16.10
13 Nov 21:00:18 ntpdate[3689]: step time server 192.168.16.10 offset -324038.658500 sec
[root@compute ~]# date
Sat Nov 13 21:00:21 EST 2021
[root@compute ~]# systemctl restart openstack-cinder-volume
执行如上操作后问题解决,可查看dashboard上的系统信息cinder-volume服务从down改为up,如下图所示:
再创建云硬盘时状态改为availability:
[root@controller ~]# cinder create 1 --name test2
+--------------------------------+--------------------------------------+
| Property | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2021-11-14T02:16:13.000000 |
| description | None |
| encrypted | False |
| id | 9f9022f5-1b11-447e-bc0c-d3889712120a |
| metadata | {} |
| migration_status | None |
| multiattach | False |
| name | test2 |
| 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 | 386dbfcf77e444c7872e4e23d5829fcc |
| replication_status | disabled |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| updated_at | None |
| user_id | 0f217182b5af448c988f5464c706a337 |
| volume_type | None |
+--------------------------------+--------------------------------------+
[root@controller ~]# cinder list
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
| ID | Status | Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
| 9f9022f5-1b11-447e-bc0c-d3889712120a | available | test2 | 1 | - | false | |
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
2、openstack平台重启虚拟机创建失败
计算节点服务down掉处理:
systemctl restart openstack-cinder-volume
systemctl restart openstack-nova-compute
service neutron-metadata-agent restart
service neutron-openvswitch-agent restart
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
2018-11-17 lxml模块(应用xpath技术)