openstack从卷启动虚拟机

原创
2017/11/23 16:11
阅读数 6K

好处

开始之前先说下从卷启动虚拟机的好处,不然哪有动力去看呢?

从卷启动虚拟机的好处在于创建快照是通过调用卷管理接口(cinder),因而速度非常快。通过卷创建虚拟机,然后再创建快照是比较推荐的创建虚拟机快照方式,参见5分钟玩转openstack

但是资料中并未就如何通过卷创建虚拟机给出说明,这篇文章以命令行操作形式,给出如何实现

实现步骤

要想实现从卷启动虚拟机总共分两步:

  1. 基于镜像创建启动卷
  2. 基于启动卷创建虚拟机

基于镜像创建启动卷

首先,查看以下可用的镜像,因为我们需要基于某个镜像来创建供创建虚拟机使用的启动卷

$ openstack image list

+--------------------------------------+------------------------------------+--------+
| ID                                   | Name                               | Status |
+--------------------------------------+------------------------------------+--------+
| 1d9b293e-cba0-4306-80da-a6392cabe319 | CentOS 6 i386                      | ACTIVE |
| 28c077ac-1352-4821-9f2c-dbc8855e9df1 | CentOS 6 x86_64                    | ACTIVE |
| 64653f86-1897-4767-bf3a-e6416b4bb074 | CentOS 7 x86_64 (10/02/15)         | ACTIVE |
| 787cba9d-bdbb-4f3a-9c39-50db9688faf5 | CentOS 7 x86_64 (12/02/15)         | ACTIVE |
| a1ced3fb-af70-40f6-adbe-89e6301fdfd0 | CentOS 7 x86_64 (20/10/14)         | ACTIVE |
| 24adac27-ca19-48e7-90b2-c38bc480693f | CoreOS                             | ACTIVE |
| 4a48c61e-bf88-4d82-bf07-52796700f22f | Debian 7 (20/10/14)                | ACTIVE |
| 6cfef669-4897-4d19-aa7c-6f0087d7c13b | Fedora 19 i386                     | ACTIVE |
| 011c9957-920f-4446-b7bf-8d60b15c6d54 | Fedora 19 x86_64                   | ACTIVE |
| 769cf0aa-c5f2-4e69-8a49-70f9c9efcd93 | Fedora 20 x86_64 (29/09/14)        | ACTIVE |
| 251557ed-ffc6-407d-ac93-110892445dc6 | Fedora 21 x86_64 (02/01/14)        | ACTIVE |
| 63ba4a7a-0909-4e7b-b62e-f146f0140e8b | Ubuntu 12.04 i386                  | ACTIVE |
| 8b20af24-1946-4fe5-a7c3-ad908c684712 | Ubuntu 12.04 x86_64                | ACTIVE |
| d3336991-3472-4ab6-8168-cac26f0b6d50 | Ubuntu 12.04 x86_64 (29/09/14)     | ACTIVE |
| 249d6dc3-235e-4021-86a1-a3636ac3f134 | Ubuntu 14.04 x86_64 (29/09/14)     | ACTIVE |
| a1718edf-f2b4-436a-9c06-af2630e09908 | Windows Server 2008 R2             | ACTIVE |
| fbd2a49a-d514-442e-a541-24ff0d539646 | Windows Server 2012 R2             | ACTIVE |
+--------------------------------------+------------------------------------+--------+

然后,通过调用命令来创建启动卷

$ openstack volume create --image 249d6dc3-235e-4021-86a1-a3636ac3f134 Ubuntu-14.04-15

+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
|     attachments     |                  []                  |
|  availability_zone  |                 nova                 |
|       bootable      |                false                 |
|      created_at     |      2015-11-11T14:23:32.710621      |
| display_description |                 None                 |
|     display_name    |             Ubuntu-14.04             |
|      encrypted      |                False                 |
|          id         | d86de794-60cb-4725-8e8d-e9f4e097b63e |
|       image_id      | 249d6dc3-235e-4021-86a1-a3636ac3f134 |
|       metadata      |                  {}                  |
|         size        |                  15                  |
|     snapshot_id     |                 None                 |
|     source_volid    |                 None                 |
|        status       |               creating               |
|     volume_type     |                 None                 |
+---------------------+--------------------------------------+

等卷创建好后,卷的bootable属性会变成true

基于启动卷创建虚拟机

准备工作包含获取一个可用的flavor和network,过程如下:

$ openstack flavor list

+--------------------------------------+------------+-----------+------+-----------+-------+-----------+
| ID                                   | Name       |    RAM    | Disk | Ephemeral | VCPUs | Is_Public |
+--------------------------------------+------------+-----------+------+-----------+-------+-----------+
| 1791eb32-68a1-4ec9-ac8d-e2374ca9c909 | 1 GB       | 1024      | 30   | 0         | 1     | True      |
| 34719f08-452d-4e8d-a29f-548d82985477 | 4 GB - HC  | 4096      | 60   | 0         | 4     | True      |
| 569d85f5-647c-420d-98e6-85149e6eebf6 | 32 GB - HM | 32768     | 60   | 0         | 6     | True      |
| 64c94219-1452-4934-a09a-d702c9370c3d | 8 GB - HM  | 8192      | 60   | 0         | 2     | True      |
| 677cac99-6a5a-4c6a-9884-23338d01c04d | 2 GB       | 2048      | 60   | 0         | 1     | True      |
| 75518817-da1b-4fbf-bd11-dffce8e73b49 | 8 GB - HC  | 8192      | 60   | 0         | 8     | True      |
| 885f9496-5de5-4894-bab9-98ef88e4892c | 8 GB       | 8192      | 120  | 0         | 4     | True      |
| b5ae8e6f-03f3-4146-9add-6e84e6944ead | 4 GB       | 4096      | 80   | 0         | 2     | True      |
| baec2dce-b1ea-4898-a259-9a3bf66f6262 | 512 MB     | 512       | 10   | 0         | 1     | True      |
| cdb1ff78-66ea-4848-a93e-f843a75c7f59 | 16 GB - HC | 16384     | 60   | 0         | 12    | True      |
| d0e71e26-1d9e-4476-bf8b-11d32dc30483 | 16 GB - HM | 16384     | 60   | 0         | 4     | True      |
| e989b4c4-4aa2-4b5c-8086-d3f407fb131f | 16 GB      | 16384     | 200  | 0         | 6     | True      |
| f021e071-261c-43e3-b1d7-834bc714e06b | 32 GB      | 32768     | 200  | 0         | 8     | True      |
+--------------------------------------+------------+-----------+------+-----------+-------+-----------+

$ openstack network list

+--------------------------------------+--------------+------------------------------------------------------+
| id                                   | name         | subnets                                              |
+--------------------------------------+--------------+------------------------------------------------------+
| 7bc79d7b-0d04-488b-9513-b4695988840e | Demo Network | 28359fd5-5858-4ad3-94f4-673a31927603 10.200.100.0/24 |
+--------------------------------------+--------------+------------------------------------------------------+

在获取到flavor和network后就可以调用命令来创建虚拟机

$ openstack server create --flavor b5ae8e6f-03f3-4146-9add-6e84e6944ead --volume 3646ab44-e6b2-41d6-85ae-cc3dfbfb8f9a --nic net-id=7bc79d7b-0d04-488b-9513-b4695988840e boot-from-vol
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部