1.8 创建第一台OpenStack云主机

好的,到目前为止,你已经完成了启动一台虚拟机所有的必备条件。

  • MySQL:为各个服务提供数据存储
  • RabbitMQ:为各个服务之间通信提供交通枢纽
  • KeyStone:为各个服务器之间通信提供认证和服务注册
  • Glance:为虚拟机提供镜像管理
  • Nova:为虚拟机提供计算资源
  • Neutron:为虚拟机提供网络资源。

现在你可以着手启动一台虚拟机,剩下的OpenStack服务都可以认为是可选的,不过通常我们会用到Dashboard来通过Web界面来管理,后面的章节我们会讲到,现在我们使用命令来创建我们的第一台虚拟机。

创建FLAT网络

首先我们需要创建一个网络。我们现在为demo租户,创建一个FLAT类型的网络。如下图所示。

  1. 创建Flant网络
[root@linux-node1 ~]# source admin-openstack.sh
[root@linux-node1 ~]# openstack network create  --share --external \
  --provider-physical-network provider \
  --provider-network-type flat provider
  1. 查看网络
[root@linux-node1 ~]# openstack network list
  1. 创建子网
[root@linux-node1 ~]# openstack subnet create --network provider \
  --allocation-pool start=192.168.56.100,end=192.168.56.200 \
  --dns-nameserver 223.5.5.5  --gateway 192.168.56.2 \
  --subnet-range 192.168.56.0/24 provider-subnet
  1. 查看子网
[root@linux-node1 ~]# openstack subnet list
+--------------------------------------+----------+--------------------------------------+-----------------+
| ID                                   | Name     | Network                              | Subnet          |
+--------------------------------------+----------+--------------------------------------+-----------------+
| 297530f8-62b6-4954-ad33-c8a4ba922a3e | provider | 6cf562b4-0537-4232-a2b9-ce5481e6a505 | 192.168.56.0/24 |
+--------------------------------------+----------+--------------------------------------+-----------------+

创建云主机

  1. 创建云主机类型

由于默认的云主机大小内存最小是512M,考虑到多数人自己PC的实验环境内存有限,我们创建一个比较小的云主机类型。

[root@linux-node1 ~]# openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
  1. 创建密钥对

密钥对用来使用登录创建后的虚拟机,OpenStack在创建虚拟机的时候会把公钥放到虚拟机里面,这样我们就可以不使用密码连接。 注意现在切换到demo用户,因为我们要使用demo用户来创建第一台云主机

[root@linux-node1 ~]# source demo-openstack.sh
[root@linux-node1 ~]# ssh-keygen -q -N ""
[root@linux-node1 ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
[root@linux-node1 ~]# openstack keypair list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | d2:e0:bc:3e:35:58:5f:7b:fd:c1:0a:93:5e:bf:8f:2d |
+-------+-------------------------------------------------+
  1. 添加安全组规则

默认情况下,有一个default安全组,这个安全组会拒绝所有访问,所以为了创建虚拟机能够连接,我们需要设置运行ICMP和22端口访问。

[root@linux-node1 ~]# openstack security group rule create --proto icmp default
[root@linux-node1 ~]# openstack security group rule create --proto tcp --dst-port 22 default
  1. 启动实例前准备
[root@linux-node1 ~]# source demo-openstack.sh
  • 查看可用的云主机类型
[root@linux-node1 ~]# openstack flavor list
+----+---------+-----+------+-----------+-------+-----------+
| ID | Name    | RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+---------+-----+------+-----------+-------+-----------+
| 0  | m1.nano |  64 |    1 |         0 |     1 | True      |
+----+---------+-----+------+-----------+-------+-----------+
  • 查看可用的镜像
[root@linux-node1 ~]# openstack image list
+--------------------------------------+--------+--------+--------+
| ID                                   | Name   | Status | Server |
+--------------------------------------+--------+--------+--------+
| 68615b2c-d10e-422f-9acb-c724808657ab | cirros | ACTIVE |        |
+--------------------------------------+--------+--------+--------+
  • 查看可用的网络
[root@linux-node1 ~]# openstack network list
+--------------------------------------+--------+--------------------------------------+
| ID                                   | Name   | Subnets                              |
+--------------------------------------+--------+--------------------------------------+
| 557a00fa-f61d-4244-b350-29ffe0a03125 | public | c003b4b5-23d1-4211-ad2d-a62ec07d8853 |
+--------------------------------------+--------+--------------------------------------+
  • 查看可用的安全组
[root@linux-node1 ~]# openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID                                   | Name    | Description            | Project                          |
+--------------------------------------+---------+------------------------+----------------------------------+
| 74d74309-0660-4eb9-abba-e89fb6fd23ae | default | Default security group | aec911c3ae68464ba989213e5f6060b1 |
  1. 创建虚拟机
[root@linux-node1 ~]# openstack server create --flavor m1.nano --image cirros \
--nic net-id=5c4d0706-24cd-4d42-ba78-36a05b6c81c8 --security-group default \
--key-name mykey demo-instance

注意指定网络的时候需要使用ID,而不是名称。

测试云主机

  1. 查看云主机状态
[root@linux-node1 ~]# openstack server list
+--------------------------------------+-----------------+--------+------------+-------------+-----------------------+
| ID                                   | Name            | Status | Task State | Power State | Networks              |
+--------------------------------------+-----------------+--------+------------+-------------+-----------------------+
| 7f94df9a-e547-4f56-9887-bbc52c4e0fff | public-instance | ACTIVE | -          | Running     | public=192.168.56.101 |
+--------------------------------------+-----------------+--------+------------+-------------+-----------------------+
  1. 测试虚拟机连接
[root@linux-node1 ~]# ping -c 2 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=5.90 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.484 ms

连接虚拟机
[root@linux-node1 ~]# ssh cirros@192.168.56.101
The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.
RSA key fingerprint is 29:4d:76:17:05:1a:4e:e6:f9:81:a5:1d:8c:27:ff:2c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.101' (RSA) to the list of known hosts.
$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr FA:16:3E:E8:B9:C1  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::f816:3eff:fee8:b9c1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:150 errors:0 dropped:0 overruns:0 frame:0
          TX packets:162 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:18634 (18.1 KiB)  TX bytes:17264 (16.8 KiB)

如果无法ping通虚拟机,还可以登陆虚拟机Web页面查看,是否启动

[root@linux-node1 ~]# openstack console url show demo-instance
+-------+------------------------------------------------------------------------------------+
| Type  | Url                                                                                |
+-------+------------------------------------------------------------------------------------+
| novnc | http://192.168.56.11:6080/vnc_auto.html?token=e97cffb8-cf0c-4c22-8dbc-fa88ff61f453 |
+-------+------------------------------------------------------------------------------------+

恭喜!你成功的使用OpenStack创建了第一台虚拟机,可能这一路走来有点坎坷,但是你成功了。不过这只是你在OpenStack世界里完成的第一步!

Copyright © 赵班长@新运维社区 2019 all right reserved,powered by Gitbook该文件修订时间: 2020-01-29 12:08:03

results matching ""

    No results matching ""