Cinder服务的基本使用
作者:互联网
cinder概述
OpenStack早期版本是使用nova-volume为云平台提供持久性块存储服务器的。从Folsom版本后,就把作为Nova组成部分的nova-volume分离了出来,形成了独立的Cinder组件。Cinder本身并不直接提供块存储设备实际的管理和服务,而是在虚拟机和具体的存储设备之间引入一个抽象的“逻辑存储卷”。Cinder与Neutron类似也是通过Plugins-Agent的方式通过添加了不同厂家的DRIVE来整合多种厂家的后端存储设备,并通过提供统一的API接口的方式为云平台提供持久性的块设备存储服务,类似于Amazon的EBS(Elastic Block Storage)。Cinder服务的实现在OpenStack众多服务中,只依赖Keystone服务提供认证。可能有些人觉得Cinder提供的Volume作为云主机的云磁盘,因此Cinder与Nova也有依赖关系。其实,这是一种错误的映像,Cinder-Volume创建的“逻辑存储卷”不仅可以用于云主机的云磁盘,也可以用于其他场景,其创建卷的过程与Nova创建的云主机的状态并没有直接关联。或者换个角度来看,Nova创建的云主机也可以不用挂载Cinder创建的Volume而正常运行。
使用“openstack volume service list”命令查询块存储服务状态
[root@controller ~]# openstack volume service list
+------------------+----------------------+------+---------+-------+----------------------------+
| Binary | Host | Zone | Status | State | Updated At |
+------------------+----------------------+------+---------+-------+----------------------------+
| cinder-scheduler | controller.novalocal | nova | enabled | up | 2022-05-06T12:18:14.000000 |
| cinder-volume | compute@lvm | nova | enabled | up | 2022-05-06T12:18:09.000000 |
+------------------+----------------------+------+---------+-------+----------------------------+
创建块存储
通过使用命令“openstack volume create”创建块存储
[root@controller ~]# openstack help volume create
usage: openstack volume create [-h] [-f {json,shell,table,value,yaml}]
[-c COLUMN] [--max-width <integer>]
[--fit-width] [--print-empty] [--noindent]
[--prefix PREFIX] [--size <size>]
[--type <volume-type>]
[--image <image> | --snapshot <snapshot> | --source <volume> | --source-replicated <replicated-volume>]
[--description <description>] [--user <user>]
[--project <project>]
[--availability-zone <availability-zone>]
[--consistency-group consistency-group>]
[--property <key=value>] [--hint <key=value>]
[--multi-attach] [--bootable | --non-bootable]
[--read-only | --read-write]
<name>
通过命令创建块存储,大小为2G,名称为“volume”
[root@controller ~]# openstack volume create --size 2 volume
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2022-05-06T12:20:33.000000 |
| description | None |
| encrypted | False |
| id | 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 |
| migration_status | None |
| multiattach | False |
| name | volume |
| properties | |
| replication_status | None |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | None |
| updated_at | None |
| user_id | beafd0ad1b67482e968af2c8a6575c26 |
+---------------------+--------------------------------------+
查看块存储
使用“openstack volume list”命令查看块存储列表信息
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | available | 2 | |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
[root@controller ~]# openstack volume show volume
+--------------------------------+--------------------------------------+
| Field | Value |
+--------------------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2022-05-06T12:20:33.000000 |
| description | None |
| encrypted | False |
| id | 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 |
| migration_status | None |
| multiattach | False |
| name | volume |
| 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 | bf36698d9afd45c4b46c1933469a9101 |
| properties | |
| replication_status | None |
| size | 2 |
| snapshot_id | None |
| source_volid | None |
| status | available |
| type | None |
| updated_at | 2022-05-06T12:20:34.000000 |
| user_id | beafd0ad1b67482e968af2c8a6575c26 |
+--------------------------------+--------------------------------------+
挂载云硬盘
将块存储挂载至云主机的命令为“openstack server add volume”,其命令格式为
[root@controller ~]# openstack help server add volume
usage: openstack server add volume [-h] [--device <device>] <server> <volume>
Add volume to server
positional arguments:
<server> Server (name or ID)
<volume> Volume to add (name or ID)
使用命令将创建的“volume”块存储添加至云主机“test”上,并查看
[root@controller ~]# openstack server add volume test volume
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------------------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | in-use | 2 | Attached to test on /dev/vdb |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------------------------+
扩展卷的大小
创建完卷后可能因为需求的变更,需要对已有的卷进行扩容操作,这时需要用到“openstack volume set”命令修改卷的信息
[root@controller ~]# openstack help volume set
usage: openstack volume set [-h] [--name <name>] [--size <size>]
[--description <description>] [--no-property]
[--property <key=value>]
[--image-property <key=value>] [--state <state>]
[--type <volume-type>]
[--retype-policy <retype-policy>]
[--bootable | --non-bootable]
[--read-only | --read-write]
<volume>
使用nova volume-detach命令先分离卷,才能进行扩展
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------------------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | in-use | 2 | Attached to test on /dev/vdb |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------------------------+
[root@controller ~]# nova volume-detach test 13a971b9-3c30-46dd-a9b9-b51d9690c9c3
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | available | 2 | |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
通过命令将 “volume” 卷大小从2G扩容至3G,使用--size参数可修改已创建好的卷大小
[root@controller ~]# openstack volume set --size 3 volume
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | available | 3 | |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
验证卷大小
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | available | 3 | |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------+
[root@controller ~]# openstack server add volume test volume
[root@controller ~]# openstack volume list
+--------------------------------------+--------+-----------+------+-------------------------------+
| ID | Name | Status | Size | Attached to |
+--------------------------------------+--------+-----------+------+-------------------------------+
| 13a971b9-3c30-46dd-a9b9-b51d9690c9c3 | volume | in-use | 3 | Attached to test on /dev/vdb |
| 6b474457-5942-457e-8c18-8a57b8b3977f | | available | 20 | |
+--------------------------------------+--------+-----------+------+-------------------------------+
标签:基本,None,服务,--,volume,controller,openstack,Cinder,root 来源: https://www.cnblogs.com/hoyeong/p/16228232.html