博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenStack实践系列⑥构建虚拟机实例
阅读量:5821 次
发布时间:2019-06-18

本文共 9507 字,大约阅读时间需要 31 分钟。

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

四、创建一台虚拟机

图解网络,并创建一个真实的桥接网络

 

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

/etc/neutron/plugins/ml2/linuxbridge_agent.ini配置文件中配置项中的内容physical_interface_mappings = physnet1:eth0)[root@node1 ~]# source admin-openrc.sh[root@node1 ~]# neutron net-create flat --shared --provider:physical_network physnet1 --provider:network_type flatCreated 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和网关

[root@node1 ~]# 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.1Created 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 |+-------------------+----------------------------------------------------+

 

查看创建的网络和子网

[root@node1 ~]# 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中

[root@node1 ~]# source demo-openrc.sh [root@node1 ~]# ssh-keygen -q -N ""Enter file in which to save the key (/root/.ssh/id_rsa): [root@node1 ~]# ls .ssh/id_rsa id_rsa.pub[root@node1 ~]# nova keypair-add --pub-key .ssh/id_rsa.pub mykey[root@node1 ~]# nova keypair-list+-------+-------------------------------------------------+| Name | Fingerprint |+-------+-------------------------------------------------+| mykey | 10:b2:ae:16:3c:76:c4:94:41:d6:16:1d:b5:bc:4b:4d |+-------+-------------------------------------------------+[root@node1 ~]# ls .ssh/id_rsa id_rsa.pub

 

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

[root@node1 ~]# 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 | |+-------------+-----------+---------+-----------+--------------+[root@node1 ~]# 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)

列出虚拟机可选类型

[root@node1 ~]# 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 |+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

列出可用镜像

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

 

列出可用网络

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

列出可用安全组

[root@node1 ~]# 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

[root@node1 ~]# 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那台虚拟机已经成功创建

[root@node1 ~]# nova list+--------------------------------------+----------------+--------+------------+-------------+----------+| ID | Name | Status | Task State | Power State | Networks |+--------------------------------------+----------------+--------+------------+-------------+----------+| b6ba588b-494d-4055-ac8e-5c3978ba9150 | hello-instance | BUILD | spawning | NOSTATE | |+--------------------------------------+----------------+--------+------------+-------------+----------+[root@node1 ~]# 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连接虚拟机并简单测试

[root@node1 ~]# ssh cirros@192.168.3.102$ ls$ whoamicirros$ ifconfigeth0 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.0inet6 addr: fe80::f816:3eff:fe40:1a59/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:2767 errors:0 dropped:0 overruns:0 frame:0TX packets:244 errors:0 dropped:0 overruns:0 carrier:0collisions: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.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

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

[root@node1 ~]# 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 |
+-------+------------------------------------------------------------------------------------+

转载于:https://www.cnblogs.com/reblue520/p/6944169.html

你可能感兴趣的文章
马云谈农村教育,推进并校落实寄宿制,要给孩子们一个不同的境遇
查看>>
Formik官方应用案例解析(四)组件生命周期事件
查看>>
为什么架构设计需要方法论?
查看>>
【VMCloud云平台】SCOM配置(十五)-启用SCOM日志审计(ACS)
查看>>
富士通也搞全闪存
查看>>
从拉手网万人“聚餐”看团购020模式的广阔前景
查看>>
揭秘灰色项目,特别是iPhone果粉要小心了
查看>>
了解Exchange server 2010角色
查看>>
第十一章 Shell常用命令与工具(二)
查看>>
诺基亚的情怀正变得越来越廉价
查看>>
启动与关闭Oracle rac数据库集群
查看>>
印度庙墓堡之旅(之一)
查看>>
Exchange 2010 RPC配置静态RPC端口客户端访问、通讯簿服务和公用文件夹连接
查看>>
C# 自动登录网页,浏览页面【转载】
查看>>
武汉大学2013年数学分析考研试题参考解答
查看>>
ddraw 视频下画图 不闪烁的方法
查看>>
[詹兴致矩阵论习题参考解答]习题2.7
查看>>
事务(Transaction)概念和特性
查看>>
ListView 使用方法(Asp.Net)
查看>>
BNUOJ34973Liserious战队
查看>>