OpenStack实践系列⑥构建虚拟机实例

四、创建一台虚拟机
图解网络,并创建一个真实的桥接网络

创建一个单一扁平网络(名字:flat),网络类型为flat,网络适共享的(share),网络提供者:physnet1,它是和eth0关联起来的(

/etc/neutron/plugins/ml2/linuxbridge_agent.ini配置文件中配置项中的内容physical_interface_mappings = physnet1:eth0)

[[email protected] ~]# source admin-openrc.sh

[[email protected] ~]# neutron net-create flat --shared --provider:physical_network physnet1 --provider:network_type flat
Created a new network:
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | 2cd04d33-60a1-4d16-af09-19ad71f56f75 |
| mtu | 0 |
| name | flat |
| port_security_enabled | True |
| provider:network_type | flat |
| provider:physical_network | physnet1 |
| provider:segmentation_id | |
| router:external | False |
| shared | True |
| status | ACTIVE |
| subnets | |
| tenant_id | eb5d7705ed7147e6beb4cd83a9f70a4a |
+---------------------------+--------------------------------------+

对上一步创建的网络创建一个子网,名字为:subnet-create flat,设置dns和网关

[[email protected] ~]# neutron subnet-create flat 192.168.3.0/24 --name flat-subnet --allocation-pool start=192.168.3.100,end=192.168.3.200 --dns-nameserver 192.168.1.13 --gateway 192.168.3.1
Created a new subnet:
+-------------------+----------------------------------------------------+
| Field | Value |
+-------------------+----------------------------------------------------+
| allocation_pools | {"start": "192.168.3.100", "end": "192.168.3.200"} |
| cidr | 192.168.3.0/24 |
| dns_nameservers | 192.168.1.13 |
| enable_dhcp | True |
| gateway_ip | 192.168.3.1 |
| host_routes | |
| id | c2bc3265-178d-48d9-bef9-0c3544d1b0c3 |
| ip_version | 4 |
| ipv6_address_mode | |
| ipv6_ra_mode | |
| name | flat-subnet |
| network_id | 2cd04d33-60a1-4d16-af09-19ad71f56f75 |
| subnetpool_id | |
| tenant_id | eb5d7705ed7147e6beb4cd83a9f70a4a |
+-------------------+----------------------------------------------------+

查看创建的网络和子网

[[email protected] ~]# neutron net-list
+--------------------------------------+------+-----------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------+-----------------------------------------------------+
| 2cd04d33-60a1-4d16-af09-19ad71f56f75 | flat | c2bc3265-178d-48d9-bef9-0c3544d1b0c3 192.168.3.0/24 |
+--------------------------------------+------+-----------------------------------------------------+

注:创建虚拟机之前,由于一个网络下不能存在多个dhcp,所以一定关闭其他的dhcp选项
下面开始正式创建虚拟机,为了可以连上所创建的虚拟机,在这里要创建一对公钥和私钥,并添加到openstack中

[[email protected] ~]# source demo-openrc.sh
[[email protected] ~]# ssh-keygen -q -N ""
Enter file in which to save the key (/root/.ssh/id_rsa):
[[email protected] ~]# ls .ssh/
id_rsa id_rsa.pub

[[email protected] ~]# nova keypair-add --pub-key .ssh/id_rsa.pub mykey
[[email protected] ~]# nova keypair-list
+-------+-------------------------------------------------+
| Name | Fingerprint |
+-------+-------------------------------------------------+
| mykey | 10:b2:ae:16:3c:76:c4:94:41:d6:16:1d:b5:bc:4b:4d |
+-------+-------------------------------------------------+
[[email protected] ~]# ls .ssh/
id_rsa id_rsa.pub

创建一个安全组,打开icmp和开放22端口

[[email protected] ~]# nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| icmp | -1 | -1 | 0.0.0.0/0 | |
+-------------+-----------+---------+-----------+--------------+
[[email protected] ~]# nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp | 22 | 22 | 0.0.0.0/0 | |
+-------------+-----------+---------+-----------+--------------+

创建虚拟机之前要进行的确认虚拟机类型flavor(相当于EC2的intance的type)、需要的镜像(EC2的AMI),需要的网络(EC2的VPC),安全组(EC2的sg)

列出虚拟机可选类型

[[email protected] ~]# nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True |
| 2 | m1.small | 2048 | 20 | 0 | | 1 | 1.0 | True |
| 3 | m1.medium | 4096 | 40 | 0 | | 2 | 1.0 | True |
| 4 | m1.large | 8192 | 80 | 0 | | 4 | 1.0 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | | 8 | 1.0 | True |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

列出可用镜像

[[email protected] ~]# nova image-list
+--------------------------------------+--------+--------+--------+
| ID | Name | Status | Server |
+--------------------------------------+--------+--------+--------+
| 6a806538-4532-4331-b79d-d69ea7bc478c | cirros | ACTIVE | |
+--------------------------------------+--------+--------+--------+

列出可用网络

[[email protected] ~]# neutron net-list
+--------------------------------------+------+-----------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------+-----------------------------------------------------+
| 2cd04d33-60a1-4d16-af09-19ad71f56f75 | flat | c2bc3265-178d-48d9-bef9-0c3544d1b0c3 192.168.3.0/24 |
+--------------------------------------+------+-----------------------------------------------------+

列出可用安全组

[[email protected] ~]# nova secgroup-list
+--------------------------------------+---------+------------------------+
| Id | Name | Description |
+--------------------------------------+---------+------------------------+
| cf68eabe-4487-4bd4-8835-4a0ae7295de0 | default | Default security group |
+--------------------------------------+---------+------------------------+

创建一台虚拟机,类型为m1.tiny,镜像为cirros(之前wget下载的),网络id为neutron net-list出来的,安全组就是默认的,选择刚开的创建的key-pair,虚拟机的名字为hello-instance

[[email protected] ~]# nova boot --flavor m1.tiny --image cirros --nic net-id=2cd04d33-60a1-4d16-af09-19ad71f56f75 --security-group default --key-name mykey hello-instance
+--------------------------------------+-----------------------------------------------+
| Property | Value |
+--------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-SRV-ATTR:host | - |
| OS-EXT-SRV-ATTR:hypervisor_hostname | - |
| OS-EXT-SRV-ATTR:instance_name | instance-00000001 |
| OS-EXT-STS:power_state | 0 |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | - |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| adminPass | wsNS4n8iKLoB |
| config_drive | |
| created | 2017-06-05T02:02:40Z |
| flavor | m1.tiny (1) |
| hostId | |
| id | 3a995e89-4d71-4f70-9ae6-de82b65ebb74 |
| image | cirros (6a806538-4532-4331-b79d-d69ea7bc478c) |
| key_name | mykey |
| metadata | {} |
| name | hello-instance |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | default |
| status | BUILD |
| tenant_id | eb5d7705ed7147e6beb4cd83a9f70a4a |
| updated | 2017-06-05T02:02:40Z |
| user_id | 4f71615a44c8422cbc034323d0d4c9a7 |
+--------------------------------------+-----------------------------------------------+

查看虚拟机创建状态,状态为ACTIVE那台虚拟机已经成功创建

[[email protected] ~]# nova list
+--------------------------------------+----------------+--------+------------+-------------+----------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+----------+
| b6ba588b-494d-4055-ac8e-5c3978ba9150 | hello-instance | BUILD | spawning | NOSTATE | |
+--------------------------------------+----------------+--------+------------+-------------+----------+
[[email protected] ~]# nova list
+--------------------------------------+----------------+--------+------------+-------------+--------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+--------------------+
| b6ba588b-494d-4055-ac8e-5c3978ba9150 | hello-instance | ACTIVE | - | Running | flat=192.168.3.102 |
+--------------------------------------+----------------+--------+------------+-------------+--------------------+

ssh连接虚拟机并简单测试

[[email protected] ~]# ssh [email protected]192.168.3.102
$ ls
$ whoami
cirros

$ ifconfig
eth0 Link encap:Ethernet HWaddr FA:16:3E:40:1A:59
inet addr:192.168.3.102 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fe40:1a59/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2767 errors:0 dropped:0 overruns:0 frame:0
TX packets:244 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:189669 (185.2 KiB) TX bytes:28305 (27.6 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

通过vnc生成URL在web界面上链接虚拟机

[[email protected] ~]# nova get-vnc-console hello-instance novnc
+-------+------------------------------------------------------------------------------------+
| Type | Url |
+-------+------------------------------------------------------------------------------------+
| novnc | http://192.168.3.199:6080/vnc_auto.html?token=a9483376-e7d1-4f12-8c82-72ee861afd15 |
+-------+------------------------------------------------------------------------------------+

时间: 2024-10-11 06:43:52

OpenStack实践系列⑥构建虚拟机实例的相关文章

OpenStack实践系列⑨云硬盘服务Cinder

OpenStack实践系列⑨云硬盘服务Cinder八.cinder8.1存储的三大分类 块存储:硬盘,磁盘阵列DAS,SAN存储 文件存储:nfs,GluserFS,Ceph(PB级分布式文件系统),MooserFS(缺点Metadata数据丢失,虚拟机就毁了) 11.2网络类型选择 对象存储:swift,S3 8.2 cinder控制节点的部署 安装cinder [[email protected] ~]# yum install openstack-cinder python-cinderc

OpenStack实践系列⑦深入理解neutron和虚拟机

五.深入理解Neutron 5.1 虚拟机网卡和网桥 [[email protected] ~]# ifconfig brq65c11cc3-8e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.3.199 netmask 255.255.255.0 broadcast 192.168.3.255 ether 00:50:56:3b:dc:7e txqueuelen 1000 (Ethernet) RX pac

OpenStack实践系列①openstack简介及基础环境部署

一.OpenStack初探1.1 OpenStack简介 OpenStack是一整套开源软件项目的综合,它允许企业或服务提供者建立.运行自己的云计算和存储设施.Rackspace与NASA是最初重要的两个贡献者,前者提供了"云文件"平台代码,该平台增强了OpenStack对象存储部分的功能,而后者带来了"Nebula"平台形成了OpenStack其余的部分.而今,OpenStack基金会已经有150多个会员,包括很多知名公司如"Canonical.DELL

OpenStack实践系列⑧可视化服务Horizon之Dashboard演示

七.可视化服务Horizon之Dashboard演示 仪表板依赖于功能核心服务,包括身份,图像服务,计算和网络两种(neutron)或传统网络(nova-neutron).与独立的服务环境,如对象存储不能使用仪表板. 配置和使用在安装和配置标识服务节中描述了ApacheHTTP服务器和Memcached的服务认证服务的运行. 默认的配置文件由分布有所不同.您可能需要添加这些部分和选项,而不是修改现有的部分和选项.此外,在配置片段省略号(...)表示您应保留潜在的默认配置选项. 7.1 编辑/et

OpenStack实践系列⑤网络服务Neutron

3.8 Neturn 服务部署 注册neutron服务 [[email protected] ~]# source admin-openrc.sh [[email protected] ~]# openstack service create --name neutron --description "OpenStack Networking" network +-------------+----------------------------------+ | Field | Va

Openstack实践(1)安装部署第一个实例及neutron网络

版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://www.cnblogs.com/SuperXJ/ 如何快速部署使用openstack,使用kolla吧,openstack技术结合容器分分钟部署(单点或者多节点,任选),分分钟升级,kolla项目是为了容器化openstack,目标是做到开箱即用,所有的组件的HA都具备.kolla是一个革命性的项目,我们以前积累的安装部署经验,全部都报废.使用kolla可以快速部署可扩展,可靠的生产就绪的opensta

openstack学习笔记一 虚拟机启动过程代码跟踪

本文主要通过对虚拟机创建过程的代码跟踪.观察虚拟机启动任务状态的变化,来透彻理解openstack各组件之间的作用过程. 当从horizon界面发送一个创建虚拟机请求,horizon api 将会依据前端给定的数据信息.调用novaclient 生成一个创建虚拟机的http post 请求来创建vm服务. >/usr/lib/python2.6/site-packages/horizon/api/nova.py(334)server_create() > /usr/lib/python2.6/

ASP.NET Web API实践系列05,消息处理管道

ASP.NET Web API的消息处理管道可以理解为请求到达Controller之前.Controller返回响应之后的处理机制.之所以需要了解消息处理管道,是因为我们可以借助它来实现对请求和响应的自定义处理.所有的请求被封装到HttpRequestMessage这个类中,所有的响应被封装到HttpResponseMessage这个类中. 既然消息处理管道是可扩展的,那么,ASP.NET Web API一定为我们准备了便于扩展的接口或抽象类,它就是HttpMessageHandler抽象类.

[ 搭建Redis本地服务器实践系列 ] :序言

说起来,是在一个气候适宜的下午,虽然临近下班,不过办公室里还是充满了忙碌的身影,不时的还会从办公区传来小伙伴们为了一个需求而激烈争论的声音,自从入了互联网这个行业,说实话,也就很少休息了,当然了也不全然是因为工作压力大,相比倒更加觉得是自己内心潜在的危机意识在不断的促使自己,往前走,在这个时局不断变化的时代,不进步就意味着倒退.不过忙归忙,该休息,还是得休息,亦或许是因为周五的缘故,哈哈哈,给自己一点时间,回溯总结下最近一周的得失. 前段时间一直忙于项目的进度,都是新项目,不过因为公司基建服务的