卷是可装可卸的块存储设备,有点类似U盘。您一次只能把一个卷装在一个实例上。要创建和管理卷,您可以通过nova
和cinder
客户端命令。
如果您是系统管理员,您可以给卷和里面连带的数据做迁移,而且这整个过程都是用户无感知、业务无感知的。不过,您只能迁移没有被装载的卷,而且卷上不能有快照。
数据迁移的可能原因有如下几种:
迁移卷的时候,请使用cinder migrate
命令。如下例所示:
$ cinder migrate volumeID destinationHost --force-host-copy True|False
在本例中,--force-host-copy True
会强制使用基于主机的迁移机制,而不使用驱动的优化。
注意: 如果该卷正在被使用,或者该卷上有快照,那目标主机是不会接受这个迁移的。如果执行迁移的用户不是管理员,迁移也会失败。
本节我们用例子来展示如何用镜像来创建一个名为“my-new-volume”的卷。
$ nova image-list
+-----------------------+---------------------------------+--------+--------------------------+
| ID | Name | Status | Server |
+-----------------------+---------------------------------+--------+--------------------------+
| 397e713c-b95b-4186... | cirros-0.3.2-x86_64-uec | ACTIVE | |
| df430cc2-3406-4061... | cirros-0.3.2-x86_64-uec-kernel | ACTIVE | |
| 3cf852bd-2332-48f4... | cirros-0.3.2-x86_64-uec-ramdisk | ACTIVE | |
| 7e5142af-1253-4634... | myCirrosImage | ACTIVE | 84c6e57d-a6b1-44b6-81... |
| 89bcd424-9d15-4723... | mysnapshot | ACTIVE | f51ebd07-c33d-4951-87... |
+-----------------------+---------------------------------+--------+--------------------------+
$ cinder availability-zone-list
+------+-----------+
| Name | Status |
+------+-----------+
| nova | available |
+------+-----------+
$ cinder create 8 --display-name my-new-volume --image-id 397e713c-b95b-4186-ad46-6126863ea0a9 --availability-zone nova
+---------------------+--------------------------------------+
| Property | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| created_at | 2013-07-25T17:02:12.472269 |
| display_description | None |
| display_name | my-new-volume |
| id | 573e024d-5235-49ce-8332-be1576d323f8 |
| image_id | 397e713c-b95b-4186-ad46-6126863ea0a9 |
| metadata | {} |
| size | 8 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| volume_type | None |
+---------------------+--------------------------------------+
$ cinder list
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| 573e024d-523... | available | my-new-volume | 8 | None | true | |
| bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
如果您的卷创建成功,那这个卷的状态应该是available
。如果状态是error
,您很有可能给卷的大小分得太多,超过您的配额了。
$ nova volume-attach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 573e024d-5235-49ce-8332-be1576d323f8 /dev/vdb
+----------+--------------------------------------+
| Property | Value |
+----------+--------------------------------------+
| device | /dev/vdb |
| serverId | 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 |
| id | 573e024d-5235-49ce-8332-be1576d323f8 |
| volumeId | 573e024d-5235-49ce-8332-be1576d323f8 |
+----------+--------------------------------------+
请记录下您卷的ID。
$ cinder show 573e024d-5235-49ce-8332-be1576d323f8
以下信息便是返回结果,其中显示了这个卷被装载到了ID为84c6e57d-a6b1-44b6-81eb-fcb36afd31b5
的机器上,所在的可用区是nova,而且是可引导启动的。
$ nova volume-detach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 573e024d-5235-49ce-8332-be1576d323f8
$ cinder list
+----------------+-----------+-----------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+----------------+-----------+-----------------+------+-------------+----------+-------------+
| 573e024d-52... | available | my-new-volume | 8 | None | true | |
| bd7cf584-45... | available | my-bootable-vol | 8 | None | true | |
+----------------+-----------+-----------------+------+-------------+----------+-------------+
此时该卷已变为可用状态。
$ cinder extend 573e024d-5235-49ce-8332-be1576d323f8 10
用卷名称或ID来指定你要删除哪个卷:
$ cinder delete my-new-volume
deleting
。$ cinder list
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| 573e024d-523... | deleting | my-new-volume | 8 | None | true | |
| bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
$ cinder list
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
| 573e024d-523... | deleting | my-new-volume | 8 | None | true | |
| bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
+-----------------+-----------+-----------------+------+-------------+----------+-------------+
您可以用cinder transfer*
命令将某个卷从一个所有者转移到另一个所有者。卷的出让人,或者说原来的主人,创建一个转移请求,然后把卷ID和认证码发给卷的受让人。受让人,或者说新主人,用卷的ID和认证码接受转移。
注意: 转移卷的操作一般只能在同一个云的内部完成,出让人和受让人必须在同一个云里。
转移卷通常发生在以下场景:
$ cinder list
+-----------------+-----------+--------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-----------------+-----------+--------------+------+-------------+----------+-------------+
| 72bfce9f-cac... | error | None | 1 | None | false | |
| a1cdace0-08e... | available | None | 1 | None | false | |
+-----------------+-----------+--------------+------+-------------+----------+-------------+
$ cinder transfer-create volumeID
该卷必须处在available
状态,否则该请求会被驳回。如果转移请求在数据库中有效(也就是说它既没有超时也没有被删掉),则该卷会被标记为awating transfer
状态,例如:
$ cinder transfer-create a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f
返回的结果如下所示,其中id项是本次的转移ID,授权码也显示出来了:
+------------+--------------------------------------+
| Property | Value |
+------------+--------------------------------------+
| auth_key | b2c8e585cbc68a80 |
| created_at | 2013-10-14T15:20:10.121458 |
| id | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
| name | None |
| volume_id | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
+------------+--------------------------------------+
注意: 您可以使用
--display-name displayName
来指定一次转移的代号。
注意: 虽然
auth_key
这一项在您执行cinder transfer-create VOLUME_ID
时能显示出来,但是在执行cinder transfer-show TRANSFER_ID
时是显示不出来的。
将卷转移ID和授权码发给受让人(比如用邮件发给他)
查看正在进行中的转移
$ cinder transfer-list
+--------------------------------------+--------------------------------------+------+
| ID | VolumeID | Name |
+--------------------------------------+--------------------------------------+------+
| 6e4e9aa4-bed5-4f94-8f76-df43232f44dc | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
+--------------------------------------+--------------------------------------+------+
$ cinder transfer-list
+----+-----------+------+
| ID | Volume ID | Name |
+----+-----------+------+
+----+-----------+------+
如果您是卷的接受者,您要从卷的原主人处获取到transfer ID和授权码。
接受此次转移请求。
$ cinder transfer-accept transferID authKey
例如:
$ cinder transfer-accept 6e4e9aa4-bed5-4f94-8f76-df43232f44dc b2c8e585cbc68a80
+-----------+--------------------------------------+
| Property | Value |
+-----------+--------------------------------------+
| id | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
| name | None |
| volume_id | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
+-----------+--------------------------------------+
$ cinder list
+-------------+-----------------+--------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-------------+-----------------+--------------+------+-------------+----------+-------------+
| 72bfce9f... | error | None | 1 | None | false | |
| a1cdace0... |awaiting-transfer| None | 1 | None | false | |
+-------------+-----------------+--------------+------+-------------+----------+-------------+
$ cinder transfer-list
+--------------------------------------+--------------------------------------+------+
| ID | VolumeID | Name |
+--------------------------------------+--------------------------------------+------+
| a6da6888-7cdf-4291-9c08-8c1f22426b8a | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
+--------------------------------------+--------------------------------------+------+
$ cinder transfer-delete transferID
比如:
$ cinder transfer-delete a6da6888-7cdf-4291-9c08-8c1f22426b8a
$ cinder transfer-list
+----+-----------+------+
| ID | Volume ID | Name |
+----+-----------+------+
+----+-----------+------+
$ cinder list
+-----------------+-----------+--------------+------+-------------+----------+-------------+
| ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
+-----------------+-----------+--------------+------+-------------+----------+-------------+
| 72bfce9f-ca... | error | None | 1 | None | false | |
| a1cdace0-08... | available | None | 1 | None | false | |
+-----------------+-----------+--------------+------+-------------+----------+-------------+