功能
归档
200
2017 年 01 月 18 日
openstack搭建之创建实例(六)

一、实验平台:CentOS Linux release 7.3.1611 (Core)

二、openstack版本:Mitake

三、本机所有IP:内网:192.168.1.2 192.168.1.3

外网:192.168.2.4 192.168.2.5

四、openstack1:192.168.1.2 #控制节点 1 处理器, 4 GB 内存, 及20 GB 存储

五、openstack2:192.168.1.3 #计算节点 1 处理器, 2 GB 内存, 及20 GB 存储


步骤:


一、启动一个实例


创建虚拟网络 -> 创建提供者网络
控制节点上,加载admin凭证来获取管理员能执行的命令访问权限:

. admin-openstack.sh

创建网络:

neutron net-create --shared --provider:physical_network provider --provider:network_type flat provider
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2017-07-20T07:17:36                  |
| description               |                                      |
| id                        | 08f147be-722b-4d5c-82de-33df2939404b |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| mtu                       | 1500                                 |
| name                      | provider                             |
| port_security_enabled     | True                                 |
| provider:network_type     | flat                                 |
| provider:physical_network | provider                             |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | db84902f7b1a4553a97684f210395abe     |
| updated_at                | 2017-07-20T07:17:36                  |
+---------------------------+--------------------------------------+
#-–shared选项允许所有项目使用虚拟网络
#--provider:physical_network(物理网络) provider(物理网络的名称) #--provider:network_type(创建的网络类型为flat)
#flat public-net(自定义一个名称)

检查是否创建成功

neutron net-list
+--------------------------------------+----------+---------+
| id                                   | name     | subnets |
+--------------------------------------+----------+---------+
| 08f147be-722b-4d5c-82de-33df2939404b | provider |         |
+--------------------------------------+----------+---------+

在网络上创建一个子网:

neutron subnet-create --name provider \
--allocation-pool start=192.168.1.100,end=192.168.1.200 \
--dns-nameserver 8.8.8.8 --gateway 192.168.1.254 \
provider 192.168.1.0/24
Created a new subnet:
+-------------------+----------------------------------------------------+
| Field             | Value                                              |
+-------------------+----------------------------------------------------+
| allocation_pools  | {"start": "192.168.1.100", "end": "192.168.1.200"} |
| cidr              | 192.168.1.0/24                                     |
| created_at        | 2017-07-20T07:24:19                                |
| description       |                                                    |
| dns_nameservers   | 8.8.8.8                                            |
| enable_dhcp       | True                                               |
| gateway_ip        | 192.168.1.254                                      |
| host_routes       |                                                    |
| id                | caf8cf6d-52e2-4ef2-8674-29375ce57939               |
| ip_version        | 4                                                  |
| ipv6_address_mode |                                                    |
| ipv6_ra_mode      |                                                    |
| name              | provider                                           |
| network_id        | 08f147be-722b-4d5c-82de-33df2939404b               |
| subnetpool_id     |                                                    |
| tenant_id         | db84902f7b1a4553a97684f210395abe                   |
| updated_at        | 2017-07-20T07:24:19                                |
+-------------------+----------------------------------------------------+
网络192.168.1.0/24的网关为192.168.1.254。DHCP服务为每个实例分配IP,IP从192.168.1.100到 192.168.1.200。所有实例的DNS使用8.8.8.8。

#neutron subnet-create  子网创建
#--name (名称)
#--allocation—pool 分配地址池
#start=开始IP地址
#end=结束IP地址
#dns-nameserver DNS地址
#--gateway  网关
#provider  提供者的网络(要跟创建网络的名称对应起来)

检查是否关联成功

neutron net-list
+--------------------------------------+----------+-----------------------------------------------------+
| id                                   | name     | subnets                                             |
+--------------------------------------+----------+-----------------------------------------------------+
| 08f147be-722b-4d5c-82de-33df2939404b | provider | caf8cf6d-52e2-4ef2-8674-29375ce57939 192.168.1.0/24 |
+--------------------------------------+----------+-----------------------------------------------------+
#subnets    #关联信息

查看子网

neutron subnet-list
+--------------------------------------+----------+----------------+----------------------------------------------------+
| id                                   | name     | cidr           | allocation_pools                                   |
+--------------------------------------+----------+----------------+----------------------------------------------------+
| caf8cf6d-52e2-4ef2-8674-29375ce57939 | provider | 192.168.1.0/24 | {"start": "192.168.1.100", "end": "192.168.1.200"} |
+--------------------------------------+----------+----------------+----------------------------------------------------+

创建m1.nano规格的主机

openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
+----------------------------+---------+
| Field                      | Value   |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled   | False   |
| OS-FLV-EXT-DATA:ephemeral  | 0       |
| disk                       | 1       |
| id                         | 0       |
| name                       | m1.nano |
| os-flavor-access:is_public | True    |
| ram                        | 64      |
| rxtx_factor                | 1.0     |
| swap                       |         |
| vcpus                      | 1       |
+----------------------------+---------+
#openstack flavor create 创建主机
#--id 主机ID
#--vcpus   cpu
#--ram 64兆(如果想加G,直接写64G即可)
#--disk  磁盘(单位是G)

生成一个键值对
大部分云镜像支持公共密钥认证而不是传统的密码认证。在启动实例前,你必须添加一个公共密钥到计算服务。
导入租户demo的凭证

. demo-openstack.sh

生成和添加秘钥对:

ssh-keygen -q -N ""
Enter file in which to save the key (/root/.ssh/id_rsa):        #回车报错密钥文件

openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | 99:3a:a0:43:9a:bd:96:b2:81:38:0d:01:6d:22:0c:f2 |
| name        | mykey                                           |
| user_id     | 3ac154bc2e654b74a39e366f4bee4318                |
+-------------+-------------------------------------------------+
#另外,你可以跳过执行 ssh-keygen 命令而使用已存在的公钥。

验证公钥的添加:

openstack keypair list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 99:3a:a0:43:9a:bd:96:b2:81:38:0d:01:6d:22:0c:f2 |
+-------+-------------------------------------------------+

增加安全组规则
添加规则到default安全组
ICMP (ping)

openstack security group rule create --proto icmp default
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | 4def5a36-41a2-49ea-87d8-1c77ba3fd40c |
| ip_protocol           | icmp                                 |
| ip_range              | 0.0.0.0/0                            |
| parent_group_id       | ff325663-ba52-4146-a989-07588f764a86 |
| port_range            |                                      |
| remote_security_group |                                      |
+-----------------------+--------------------------------------+

启动一个实例
您必须至少指定一个类型镜像名称网络安全组密钥实例名称
控制节点上,获得 admin 凭证来获取只有管理员能执行的命令的访问权限:

 . demo-openstack.sh

一个实例指定了虚拟机资源的大致分配,包括处理器、内存和存储。

列出可用类型:

openstack flavor list
+----+-----------+-------+------+-----------+-------+-----------+
| ID | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+-------+------+-----------+-------+-----------+
| 0  | m1.nano   |    64 |    1 |         0 |     1 | True      |
| 1  | m1.tiny   |   512 |    1 |         0 |     1 | True      |
| 2  | m1.small  |  2048 |   20 |         0 |     1 | True      |
| 3  | m1.medium |  4096 |   40 |         0 |     2 | True      |
| 4  | m1.large  |  8192 |   80 |         0 |     4 | True      |
| 5  | m1.xlarge | 16384 |  160 |         0 |     8 | True      |
+----+-----------+-------+------+-----------+-------+-----------+

列出可用镜像:

openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| db5d11d7-0006-4b14-a5d5-71b18a41eb85 | cirros | active |
+--------------------------------------+--------+--------
#这个实例使用cirros镜像。

列出可用网络:

openstack network list
+--------------------------------------+--------------+--------------------------------------+
| ID                                   | Name         | Subnets                              |
+--------------------------------------+--------------+--------------------------------------+
| 4716ddfe-6e60-40e7-b2a8-42e57bf3c31c | selfservice  | 2112d5eb-f9d6-45fd-906e-7cabd38b7c7c |
| 08f147be-722b-4d5c-82de-33df2939404b | provider     | caf8cf6d-52e2-4ef2-8674-29375ce57939 |
+--------------------------------------+--------------+--------------------------------------+
#这个实例使用provider公有网络。 你必须使用ID而不是名称才可以使用这个网络。
#如果你选择选项2,输出信息应该也包含私网selfservice的信息。

列出可用的安全组:

openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID                                   | Name    | Description            | Project                          |
+--------------------------------------+---------+------------------------+----------------------------------+
| ff325663-ba52-4146-a989-07588f764a86 | default | Default security group | 67e8d71973f74c73bce88de7f88626cd |
+--------------------------------------+---------+------------------------+----------------------------------+
#这个实例使用 default 安全组。

创建实例
启动实例:

openstack server create --flavor m1.tiny --image cirros \
--nic net-id=08f147be-722b-4d5c-82de-33df2939404b --security-group default \
--key-name mykey provider-instance
+--------------------------------------+-----------------------------------------------+
| Field                                | Value                                         |
+--------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                        |
| OS-EXT-AZ:availability_zone          |                                               |
| OS-EXT-STS:power_state               | 0                                             |
| 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                            | UiS29mvQTxwm                                  |
| config_drive                         |                                               |
| created                              | 2017-07-20T07:41:19Z                          |
| flavor                               | m1.tiny (1)                                   |
| hostId                               |                                               |
| id                                   | 0bc969e2-3cec-4ddd-a6ed-20596c552966          |
| image                                | cirros (db5d11d7-0006-4b14-a5d5-71b18a41eb85) |
| key_name                             | mykey                                         |
| name                                 | provider-instance                             |
| os-extended-volumes:volumes_attached | []                                            |
| progress                             | 0                                             |
| project_id                           | 67e8d71973f74c73bce88de7f88626cd              |
| properties                           |                                               |
| security_groups                      | [{u'name': u'default'}]                       |
| status                               | BUILD                                         |
| updated                              | 2017-07-20T07:41:21Z                          |
| user_id                              | 3ac154bc2e654b74a39e366f4bee4318              |
+--------------------------------------+-----------------------------------------------+
#openstack server create 创建实例
#--flavor  创建的类型
#--image 镜像
#--nic net-id= 网络ID
#--security-group 设置安全组
#--key-name key设置
#最后一个是实例名称

检查实例的状态:

openstack server list
+--------------------------------------+-------------------+--------+---------------------------+
| ID                                   | Name              | Status | Networks                  |
+--------------------------------------+-------------------+--------+---------------------------+
| 0bc969e2-3cec-4ddd-a6ed-20596c552966 | provider-instance | ACTIVE | public-net=192.168.1.110  |
+--------------------------------------+-------------------+--------+---------------------------+

Over~

留言
Loading...

发表评论

电子邮件地址不会被公开。 必填项已用*标注