Openstack 使用Centos官方镜像创建实例记录

Posted zooqkl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Openstack 使用Centos官方镜像创建实例记录相关的知识,希望对你有一定的参考价值。

Openstack 使用Centos官方镜像创建实例记录

准备centos镜像

官方地址:http://cloud.centos.org/centos/7/images

可以看到有各种版本的镜像,我在此处下载的是

https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.raw.tar.gz

其实应该下载https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1907.qcow2

后面我将raw格式的镜像又转化为了qcow2格式,因为openstack只支持qcow2格式的镜像。

转化也比较方便,转换方式如下:

#首先解压,压缩后的镜像比较小,下载也比较快
$ tar -zxvf CentOS-7-x86_64-GenericCloud-1907.raw.tar.gz
#转化镜像格式,raw格式转化为qcow2格式
$ qemu-img convert -f raw -O qcow2 CentOS-7-x86_64-GenericCloud-1907.raw CentOS-7-x86_64-GenericCloud-1907.qcow2
$ ls
CentOS-7-x86_64-GenericCloud-1907.qcow2

上传镜像到OpenStack

$ openstack image create "centos-7" --file CentOS-7-x86_64-GenericCloud-1907.qcow2 --disk-format qcow2 --container-format bare --public
# 上传成功后即可查看到已存在镜像列表中
$ openstack image list
+--------------------------------------+---------------------------------+--------+
| ID                                   | Name                            | Status |
+--------------------------------------+---------------------------------+--------+
| eeff6c96-3255-451b-bd26-8368ac701bae | Centos-7                        | active |
| 62903720-0c33-4238-b2fc-106167b3b240 | debian-8.11.0                   | active |
| aeae3608-ded5-45af-aca3-bb96df1b3320 | openSUSE                        | active |
| 721becd1-b2bf-4674-b5d1-7be9e7a9c263 | ubuntu-16.04-x86_64             | active |
+--------------------------------------+---------------------------------+--------+

用新镜像创建实例

首先需要准备创建镜像所需要的条件,例如 实例类型、网络、秘钥等等,由于我之前已经创建过了,此处就直接拿来用即可,新环境需要去创建这些东西,此处不赘述。

此处用命令行去创建实例,也可在页面上去创建实例。

# 查看已创建好的实例类型
$  openstack flavor list
+--------------------------------------+-----------------+-------+------+-----------+-------+-----------+
| ID                                   | Name            |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+-----------------+-------+------+-----------+-------+-----------+
| 0bd4ccb3-7fdb-493a-a7b4-1be94dee1cd5 | 4core_8G_100GB  |  8192 |  100 |         0 |     4 | True      |
| 2cf9cf3a-14eb-48ac-bbff-a930aeadca10 | 8core_16G_100G  | 16384 |  100 |         0 |     8 | True      |
| 8d14ecaa-6920-4d68-a69e-9f6e7a4a244c | 2core_4G_50G    |  4096 |   50 |         0 |     2 | True      |
+--------------------------------------+-----------------+-------+------+-----------+-------+-----------+
# 查看镜像列表
$ openstack image list
+--------------------------------------+---------------------------------+--------+
| ID                                   | Name                            | Status |
+--------------------------------------+---------------------------------+--------+
| eeff6c96-3255-451b-bd26-8368ac701bae | Centos-7                        | active |
| 62903720-0c33-4238-b2fc-106167b3b240 | debian-8.11.0                   | active |
| aeae3608-ded5-45af-aca3-bb96df1b3320 | openSUSE                        | active |
| 721becd1-b2bf-4674-b5d1-7be9e7a9c263 | ubuntu-16.04-x86_64             | active |
+--------------------------------------+---------------------------------+--------+
# 查看网络
$  openstack network list
+--------------------------------------+----------+--------------------------------------+
| ID                                   | Name     | Subnets                              |
+--------------------------------------+----------+--------------------------------------+
| 24ab4664-3d97-4ec8-99fb-75ba5f92fa77 | public   | 0507ad6b-153a-4713-93ee-e274d37ce3fa |
| 610c4193-5dff-419c-8df8-442cf8c49bba | provider | 3d59f5f5-2b85-4cb5-b738-a6003aa29bd9 |
| 6ba8cae0-b544-47e3-bcec-da0c8737da74 | private  | 29b1a65a-acb2-4e18-af2f-a00083a1c50e |
+--------------------------------------+----------+--------------------------------------+
# 查看秘钥对
$ openstack keypair list
+----------------+-------------------------------------------------+
| Name           | Fingerprint                                     |
+----------------+-------------------------------------------------+
| xiaoming       | 5a:d2:8f:2f:40:c2:84:1e:95:7a:23:aa:3e:af:aa:10 |
| xiaohong       | 00:4c:7e:7c:6e:29:51:cf:af:71:c3:ec:2c:90:83:ea |
+----------------+-------------------------------------------------+

利用以上信息创建实例

$ openstack server create --flavor 4core_8G_100GB  --image Centos-7  --nic net-id=610c4193-5dff-419c-8df8-442cf8c49bba  --security-group default  --key-name xiaoming centos7-test

+-------------------------------------+------------------------------------------------+
| Field                               | Value                                          |
+-------------------------------------+------------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                         |
| OS-EXT-AZ:availability_zone         |                                                |
| OS-EXT-SRV-ATTR:host                | None                                           |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                           |
| OS-EXT-SRV-ATTR:instance_name       |                                                |
| OS-EXT-STS:power_state              | NOSTATE                                        |
| OS-EXT-STS:task_state               | scheduling                                     |
| OS-EXT-STS:vm_state                 | building                                       |
| OS-SRV-USG:launched_at              | None                                           |
| OS-SRV-USG:terminated_at            | None                                           |
| accessIPv4                          |                                                |
| accessIPv6                          |                                                |
| addresses                           |                                                |
| adminPass                           | Lg4mubYrHX2U                                   |
| config_drive                        |                                                |
| created                             | 2019-08-14T07:06:18Z                           |
| flavor                              | 4core_8G_100GB (0bd4ccb3-7fdb-493a-            |
|                                     | a7b4-1be94dee1cd5)                             |
| hostId                              |                                                |
| id                                  | aeb3da93-d492-45ee-9f16-7e5a8327fcdf           |
| image                               | CentOS7-image (eeff6c96-3255-451b-             |
|                                     | bd26-8368ac701bae)                             |
| key_name                            | xiaoming                                       |
| name                                | centos7-test                                     |
| progress                            | 0                                              |
| project_id                          | 08fe311820f24af489ffce1112f45769               |
| properties                          |                                                |
| security_groups                     | name='default'                                 |
| status                              | BUILD                                          |
| updated                             | 2019-08-14T07:06:19Z                           |
| user_id                             | d518cc05787b49aa8c8f6759c0747aeb               |
| volumes_attached                    |                                                |
+-------------------------------------+------------------------------------------------+

此时,实例已经创建成功,并且已经将xiaoming的公钥注入到该实例中,此时可以ssh到该实例上使用啦。

以上是关于Openstack 使用Centos官方镜像创建实例记录的主要内容,如果未能解决你的问题,请参考以下文章

OpenStack制作CentOS6.7镜像

openstack 官方镜像qcow2 下载和修改密码

OpenStack手动制作CentOS 7 KVM镜像

制作openstack windows镜像模板(官方镜像)

openstack上传镜像

Create a virtualbox Based CentOS 6 OpenStack Cloud Image