A15. openstack架构实战-cinder卷类型

创建卷类型:

[root@controller01 ~]# cinder type-create ssd --description ssd
[root@controller01 ~]# cinder type-list
+--------------------------------------+------+-------------+-----------+
| ID                                   | Name | Description | Is_Public |
+--------------------------------------+------+-------------+-----------+
| 9100474e-7840-46b5-8425-c32074a13bb4 | ssd  | ssd         | True      |
+--------------------------------------+------+-------------+-----------+

查看卷类型详细信息:发现extra_specs(卷类型扩展规格)没有

type-key            Sets or unsets extra_spec for a volume type.

指定卷类型扩展规格:

将ssd卷类型指定后端规格(/etc/cinder/cinder.conf中配置的规格)

[root@controller01 ~]# cinder type-key  ssd set volume_backend_name=ssd

查看规格:

[root@controller01 ~]# cinder extra-specs-list
+--------------------------------------+------+--------------------------------+
| ID                                   | Name | extra_specs                    |
+--------------------------------------+------+--------------------------------+
| 9100474e-7840-46b5-8425-c32074a13bb4 | ssd  | {'volume_backend_name': 'ssd'} |
+--------------------------------------+------+--------------------------------+

[root@controller01 ~]# cinder type-show 9100474e-7840-46b5-8425-c32074a13bb4
+---------------------------------+--------------------------------------+
| Property                        | Value                                |
+---------------------------------+--------------------------------------+
| description                     | ssd                                  |
| extra_specs                     | volume_backend_name : ssd            |
| id                              | 9100474e-7840-46b5-8425-c32074a13bb4 |
| is_public                       | True                                 |
| name                            | ssd                                  |
| os-volume-type-access:is_public | True                                 |
| qos_specs_id                    | None                                 |
+---------------------------------+--------------------------------------+

创建一个卷,指定卷类型:

[root@controller01 ~]# cinder create 2 --name volume02 --volume-type ssd

[root@controller01 ~]# cinder list
+--------------------------------------+-----------+----------+------+-------------+----------+--------------------------------------+
| ID                                   | Status    | Name     | Size | Volume Type | Bootable | Attached to                          |
+--------------------------------------+-----------+----------+------+-------------+----------+--------------------------------------+
| a2871929-c1d7-4fe1-b2ff-737209410f5e | in-use    | volume1  | 1    | -           | false    | 8fbf0f77-9591-47a6-a086-4d1daab6673a |
| e580c431-bdb6-4c27-91e8-ce348f8594c3 | available | volume02 | 2    | ssd         | false    |                                      |
+--------------------------------------+-----------+----------+------+-------------+----------+--------------------------------------

[root@controller01 ~]# cinder show  e580c431-bdb6-4c27-91e8-ce348f8594c3
+--------------------------------+--------------------------------------+
| Property                       | Value                                |
+--------------------------------+--------------------------------------+
| attached_servers               | []                                   |
| attachment_ids                 | []                                   |
| availability_zone              | nova                                 |
| bootable                       | false                                |
| consistencygroup_id            | None                                 |
| created_at                     | 2020-06-02T08:08:52.000000           |
| description                    | None                                 |
| encrypted                      | False                                |
| id                             | e580c431-bdb6-4c27-91e8-ce348f8594c3 |
| metadata                       |                                      |
| migration_status               | None                                 |
| multiattach                    | False                                |
| name                           | volume02                             |
| os-vol-host-attr:host          | compute01@ssd#ssd                    |
| os-vol-mig-status-attr:migstat | None                                 |
| os-vol-mig-status-attr:name_id | None                                 |
| os-vol-tenant-attr:tenant_id   | f4228d6dfa07453c84996e5f2be19ca2     |
| replication_status             | None                                 |
| size                           | 2                                    |
| snapshot_id                    | None                                 |
| source_volid                   | None                                 |
| status                         | available                            |
| updated_at                     | 2020-06-02T08:08:54.000000           |
| user_id                        | 34520ff331cf418a9ad3b70d0c0c76a6     |
| volume_type                    | ssd                                  |
+--------------------------------+--------------------------------------+

 将卷挂载到云主机中

openstack server add volume zhaopei02  volume1

对于云主机挂载之后的云硬盘我们可以进行备份:

[root@compute01 mapper]# dd if=/dev/mapper/cinder--volumes01-volume--e580c431--bdb6--4c27--91e8--ce348f8594c3 of=/data/volume01-back.raw
4194304+0 records in
4194304+0 records out
2147483648 bytes (2.1 GB) copied, 17.6175 s, 122 MB/s


[root@compute01 mapper]# qemu-img info /data/volume01-back.raw
image: /data/volume01-back.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G

我们还可以将拷贝之后的硬盘进行挂载到其他目录进行使用:

此处格式化不了请使用sudo su -

 挂载保错请忽略

向挂载的目录写入数据测试:

[root@compute01 ~]# dd if=/dev/mapper/cinder--volumes02-volume--a2871929--c1d7--4fe1--b2ff--737209410f5e of=/data/volume02-back.raw
2097152+0 records in
2097152+0 records out
1073741824 bytes (1.1 GB) copied, 10.2772 s, 104 MB/s

直接挂载使用:

[root@compute01 ~]# mount /data/volume02-back.raw volume/

[root@compute01 ~]# cd volume/
[root@compute01 volume]# ls
a.txt  lost+found
[root@compute01 volume]# cat a.txt
this is ceshi mnt mount use

原文地址:https://www.cnblogs.com/zhaopei123/p/12982526.html