Cinder组件详解
一、Cinder组件介绍
1、概念
cinder组件作用:
- 块存储服务,为运行实例提供稳定的数据块存储服务。
- 块存储服务,提供对 volume 从创建到删除整个生命周期的管理。
2、核心架构
3、核心组件
4、工作流程
二、常用操作
1、Volume管理
# 卷列表查看
[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 , --volume-type ]
[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
[root@controller ~]# cinder delete test
Request to delete volume test has been accepted.
# 卷更新
# 1.重命名
cinder rename
[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 ,--attach-status ,--reset-migration-status]
[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
# 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
[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
2、Type管理
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 , --is-public ]
Positional arguments:
Name of new volume type.
Optional arguments:
--description
Description of new volume type.
--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
[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 ,--description ,--is-public ]
[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管理
# 查看快照列表
cinder snapshot-list
# 查看快照详情
cinder snapshot-show
# 创建快照
cinder snapshot-create [--name ]
# 删除快照
cinder snapshot-delete
4、Backup管理
# 开启卷备份服务
systemctl restart openstack-cinder-backup
# 查看备份列表
cinder backup-list
# 查看备份详情
cinder backup-show
# 创建备份
cinder backup-create --name [--container ]
# 删除备份
cinder backup-delete
# 恢复备份
cinder backup-restore [--volume ]
# 备份导出
cinder backup-export
# 备份导入
cinder backup-import
三、高级操作
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 | |
+--------------------------------------+-----------+-------+------+-------------+----------+-------------+
参考:Cinder创建云硬盘状态错误解决