• 管理卷
    • 迁移卷
    • 创建卷
  • 将卷装载在实例上
  • 重设卷的大小
  • 删除卷
  • 转移卷
    • 创建卷转移请求
    • 接受卷转移请求
    • 删除一次转移请求

    管理卷

    卷是可装可卸的块存储设备,有点类似U盘。您一次只能把一个卷装在一个实例上。要创建和管理卷,您可以通过novacinder客户端命令。

    迁移卷

    如果您是系统管理员,您可以给卷和里面连带的数据做迁移,而且这整个过程都是用户无感知、业务无感知的。不过,您只能迁移没有被装载的卷,而且卷上不能有快照。

    数据迁移的可能原因有如下几种:

    • 在不影响业务的情况下,关掉物理存储设备进行维护。
    • 修改卷的属性。
    • 腾空间。

    迁移卷的时候,请使用cinder migrate命令。如下例所示:

    1. $ cinder migrate volumeID destinationHost --force-host-copy True|False

    在本例中,--force-host-copy True会强制使用基于主机的迁移机制,而不使用驱动的优化。

    注意:
    如果该卷正在被使用,或者该卷上有快照,那目标主机是不会接受这个迁移的。如果执行迁移的用户不是管理员,迁移也会失败。

    创建卷

    本节我们用例子来展示如何用镜像来创建一个名为“my-new-volume”的卷。

    1. 列出镜像,记下您创建卷想用的镜像的ID。
    1. $ nova image-list
    2. +-----------------------+---------------------------------+--------+--------------------------+
    3. | ID | Name | Status | Server |
    4. +-----------------------+---------------------------------+--------+--------------------------+
    5. | 397e713c-b95b-4186... | cirros-0.3.2-x86_64-uec | ACTIVE | |
    6. | df430cc2-3406-4061... | cirros-0.3.2-x86_64-uec-kernel | ACTIVE | |
    7. | 3cf852bd-2332-48f4... | cirros-0.3.2-x86_64-uec-ramdisk | ACTIVE | |
    8. | 7e5142af-1253-4634... | myCirrosImage | ACTIVE | 84c6e57d-a6b1-44b6-81... |
    9. | 89bcd424-9d15-4723... | mysnapshot | ACTIVE | f51ebd07-c33d-4951-87... |
    10. +-----------------------+---------------------------------+--------+--------------------------+
    1. 列出可用的域(zone),记下您创建卷时想用的可用域的ID。
    1. $ cinder availability-zone-list
    2. +------+-----------+
    3. | Name | Status |
    4. +------+-----------+
    5. | nova | available |
    6. +------+-----------+
    1. 创建一个8 GiB的空间,同时指定这个卷用到的可用域和镜像。
    1. $ cinder create 8 --display-name my-new-volume --image-id 397e713c-b95b-4186-ad46-6126863ea0a9 --availability-zone nova
    2. +---------------------+--------------------------------------+
    3. | Property | Value |
    4. +---------------------+--------------------------------------+
    5. | attachments | [] |
    6. | availability_zone | nova |
    7. | bootable | false |
    8. | created_at | 2013-07-25T17:02:12.472269 |
    9. | display_description | None |
    10. | display_name | my-new-volume |
    11. | id | 573e024d-5235-49ce-8332-be1576d323f8 |
    12. | image_id | 397e713c-b95b-4186-ad46-6126863ea0a9 |
    13. | metadata | {} |
    14. | size | 8 |
    15. | snapshot_id | None |
    16. | source_volid | None |
    17. | status | creating |
    18. | volume_type | None |
    19. +---------------------+--------------------------------------+
    1. 想要查看您的卷是否创建成功,请列出可用卷:
    1. $ cinder list
    2. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    5. | 573e024d-523... | available | my-new-volume | 8 | None | true | |
    6. | bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
    7. +-----------------+-----------+-----------------+------+-------------+----------+-------------+

    如果您的卷创建成功,那这个卷的状态应该是available。如果状态是error,您很有可能给卷的大小分得太多,超过您的配额了。

    将卷装载在实例上

    1. 要将您的卷装载在服务器上,您需要指定服务器ID和卷ID:
    1. $ nova volume-attach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 573e024d-5235-49ce-8332-be1576d323f8 /dev/vdb
    2. +----------+--------------------------------------+
    3. | Property | Value |
    4. +----------+--------------------------------------+
    5. | device | /dev/vdb |
    6. | serverId | 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 |
    7. | id | 573e024d-5235-49ce-8332-be1576d323f8 |
    8. | volumeId | 573e024d-5235-49ce-8332-be1576d323f8 |
    9. +----------+--------------------------------------+

    请记录下您卷的ID。

    1. 查看您卷的信息。
    1. $ cinder show 573e024d-5235-49ce-8332-be1576d323f8

    以下信息便是返回结果,其中显示了这个卷被装载到了ID为84c6e57d-a6b1-44b6-81eb-fcb36afd31b5的机器上,所在的可用区是nova,而且是可引导启动的。

    重设卷的大小

    1. 如果要重设某个卷的大小,前提是该卷没有被装载在任何实例上。使用卸载的命令时您需要提供实例ID和卷ID,命令如下:
    1. $ nova volume-detach 84c6e57d-a6b1-44b6-81eb-fcb36afd31b5 573e024d-5235-49ce-8332-be1576d323f8
    1. 列出实例:
    1. $ cinder list
    2. +----------------+-----------+-----------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +----------------+-----------+-----------------+------+-------------+----------+-------------+
    5. | 573e024d-52... | available | my-new-volume | 8 | None | true | |
    6. | bd7cf584-45... | available | my-bootable-vol | 8 | None | true | |
    7. +----------------+-----------+-----------------+------+-------------+----------+-------------+

    此时该卷已变为可用状态。

    1. 使用如下命令来重新设定卷的大小。您需要将卷ID和新的大小作为参数传递给扩容命令。而且,调整后的大小必须要比调整前的大:
    1. $ cinder extend 573e024d-5235-49ce-8332-be1576d323f8 10

    删除卷

    1. 要删除卷,您同样要保证该卷没有被装载在任何实例上。如果在服务器上卸载卷、查看卷列表,请参阅Resize a volume章节的第一步和第二步。

    用卷名称或ID来指定你要删除哪个卷:

    1. $ cinder delete my-new-volume
    1. 再次列出卷列表,您会发现您的卷的状态已经变为deleting
    1. $ cinder list
    2. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    5. | 573e024d-523... | deleting | my-new-volume | 8 | None | true | |
    6. | bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
    7. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    1. 当该卷被完全删除后,它就不会显示在卷列表中了。
    1. $ cinder list
    2. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-----------------+-----------+-----------------+------+-------------+----------+-------------+
    5. | 573e024d-523... | deleting | my-new-volume | 8 | None | true | |
    6. | bd7cf584-45d... | available | my-bootable-vol | 8 | None | true | |
    7. +-----------------+-----------+-----------------+------+-------------+----------+-------------+

    转移卷

    您可以用cinder transfer*命令将某个卷从一个所有者转移到另一个所有者。卷的出让人,或者说原来的主人,创建一个转移请求,然后把卷ID和认证码发给卷的受让人。受让人,或者说新主人,用卷的ID和认证码接受转移。

    注意:
    转移卷的操作一般只能在同一个云的内部完成,出让人和受让人必须在同一个云里。

    转移卷通常发生在以下场景:

    • 您创建了一个可引导卷,或者一个装了很多内容的卷,现在要把它转移给顾客。
    • 向云中批量上传数据时;数据导入系统创建了一个新的块存储设备时;将数据从物理存储转移到云中时;或者将设备所有权转移给最终用户时,等等。

    创建卷转移请求

    1. 以卷的出让人身份登录,列出所有可用卷:
    1. $ cinder list
    2. +-----------------+-----------+--------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-----------------+-----------+--------------+------+-------------+----------+-------------+
    5. | 72bfce9f-cac... | error | None | 1 | None | false | |
    6. | a1cdace0-08e... | available | None | 1 | None | false | |
    7. +-----------------+-----------+--------------+------+-------------+----------+-------------+
    1. 针对某一个卷,创建一个卷转移授权码
    1. $ cinder transfer-create volumeID

    该卷必须处在available状态,否则该请求会被驳回。如果转移请求在数据库中有效(也就是说它既没有超时也没有被删掉),则该卷会被标记为awating transfer状态,例如:

    1. $ cinder transfer-create a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f

    返回的结果如下所示,其中id项是本次的转移ID,授权码也显示出来了:

    1. +------------+--------------------------------------+
    2. | Property | Value |
    3. +------------+--------------------------------------+
    4. | auth_key | b2c8e585cbc68a80 |
    5. | created_at | 2013-10-14T15:20:10.121458 |
    6. | id | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
    7. | name | None |
    8. | volume_id | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
    9. +------------+--------------------------------------+

    注意:
    您可以使用--display-name displayName来指定一次转移的代号。

    注意:
    虽然auth_key这一项在您执行cinder transfer-create VOLUME_ID时能显示出来,但是在执行cinder transfer-show TRANSFER_ID时是显示不出来的。

    1. 将卷转移ID和授权码发给受让人(比如用邮件发给他)

    2. 查看正在进行中的转移

    1. $ cinder transfer-list
    2. +--------------------------------------+--------------------------------------+------+
    3. | ID | VolumeID | Name |
    4. +--------------------------------------+--------------------------------------+------+
    5. | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
    6. +--------------------------------------+--------------------------------------+------+
    1. 在卷的受让人,或者新主人,接受了这次转移,您会发现本次转移已经不在转移列表上了
    1. $ cinder transfer-list
    2. +----+-----------+------+
    3. | ID | Volume ID | Name |
    4. +----+-----------+------+
    5. +----+-----------+------+

    接受卷转移请求

    1. 如果您是卷的接受者,您要从卷的原主人处获取到transfer ID和授权码。

    2. 接受此次转移请求。

    1. $ cinder transfer-accept transferID authKey

    例如:

    1. $ cinder transfer-accept 6e4e9aa4-bed5-4f94-8f76-df43232f44dc b2c8e585cbc68a80
    2. +-----------+--------------------------------------+
    3. | Property | Value |
    4. +-----------+--------------------------------------+
    5. | id | 6e4e9aa4-bed5-4f94-8f76-df43232f44dc |
    6. | name | None |
    7. | volume_id | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f |
    8. +-----------+--------------------------------------+
    1. 如果您没有足够的剩余空间来接受此次转移,此次转移会被自动拒绝。

    删除一次转移请求

    1. 列出可用卷及其状态
    1. $ cinder list
    2. +-------------+-----------------+--------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-------------+-----------------+--------------+------+-------------+----------+-------------+
    5. | 72bfce9f... | error | None | 1 | None | false | |
    6. | a1cdace0... |awaiting-transfer| None | 1 | None | false | |
    7. +-------------+-----------------+--------------+------+-------------+----------+-------------+
    1. 找到对应的转移ID:
    1. $ cinder transfer-list
    2. +--------------------------------------+--------------------------------------+------+
    3. | ID | VolumeID | Name |
    4. +--------------------------------------+--------------------------------------+------+
    5. | a6da6888-7cdf-4291-9c08-8c1f22426b8a | a1cdace0-08e4-4dc7-b9dc-457e9bcfe25f | None |
    6. +--------------------------------------+--------------------------------------+------+
    1. 删除卷的转移操作:
    1. $ cinder transfer-delete transferID

    比如:

    1. $ cinder transfer-delete a6da6888-7cdf-4291-9c08-8c1f22426b8a
    1. 查看卷转移列表,您会发现现在该表已被清空,该卷又可以被转移了。
    1. $ cinder transfer-list
    2. +----+-----------+------+
    3. | ID | Volume ID | Name |
    4. +----+-----------+------+
    5. +----+-----------+------+
    1. $ cinder list
    2. +-----------------+-----------+--------------+------+-------------+----------+-------------+
    3. | ID | Status | Display Name | Size | Volume Type | Bootable | Attached to |
    4. +-----------------+-----------+--------------+------+-------------+----------+-------------+
    5. | 72bfce9f-ca... | error | None | 1 | None | false | |
    6. | a1cdace0-08... | available | None | 1 | None | false | |
    7. +-----------------+-----------+--------------+------+-------------+----------+-------------+