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

时间:2022-04-29 19:22:56

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

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

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

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 flat
Created a new network:
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | 2cd04d33-60a1-4d16-af09-19ad71f56f75 |
| mtu | |
| 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/ --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/ |
| 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 | |
| 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/ |
+--------------------------------------+------+-----------------------------------------------------+

注:创建虚拟机之前,由于一个网络下不能存在多个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 | :b2:ae::3c::c4:::d6::1d:b5:bc:4b:4d |
+-------+-------------------------------------------------+
[root@node1 ~]# ls .ssh/
id_rsa id_rsa.pub

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

[root@node1 ~]# nova secgroup-add-rule default icmp - - 0.0.0.0/
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| icmp | - | - | 0.0.0.0/ | |
+-------------+-----------+---------+-----------+--------------+
[root@node1 ~]# nova secgroup-add-rule default tcp 0.0.0.0/
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp | | | 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 |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| | m1.tiny | | | | | | 1.0 | True |
| | m1.small | | | | | | 1.0 | True |
| | m1.medium | | | | | | 1.0 | True |
| | m1.large | | | | | | 1.0 | True |
| | m1.xlarge | | | | | | 1.0 | True |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

列出可用镜像

[root@node1 ~]# nova image-list
+--------------------------------------+--------+--------+--------+
| ID | Name | Status | Server |
+--------------------------------------+--------+--------+--------+
| 6a806538---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/ |
+--------------------------------------+------+-----------------------------------------------------+

列出可用安全组

[root@node1 ~]# nova secgroup-list
+--------------------------------------+---------+------------------------+
| Id | Name | Description |
+--------------------------------------+---------+------------------------+
| cf68eabe--4bd4--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- |
| OS-EXT-STS:power_state | |
| 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 | --05T02::40Z |
| flavor | m1.tiny () |
| hostId | |
| id | 3a995e89-4d71-4f70-9ae6-de82b65ebb74 |
| image | cirros (6a806538---b79d-d69ea7bc478c) |
| key_name | mykey |
| metadata | {} |
| name | hello-instance |
| os-extended-volumes:volumes_attached | [] |
| progress | |
| security_groups | default |
| status | BUILD |
| tenant_id | eb5d7705ed7147e6beb4cd83a9f70a4a |
| updated | --05T02::40Z |
| user_id | 4f71615a44c8422cbc034323d0d4c9a7 |
+--------------------------------------+-----------------------------------------------+

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

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

ssh连接虚拟机并简单测试

[root@node1 ~]# ssh cirros@192.168.3.102
$ ls
$ whoami
cirros $ ifconfig
eth0 Link encap:Ethernet HWaddr FA::3E::1A:
inet addr:192.168.3.102 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fe40:1a59/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (185.2 KiB) TX bytes: (27.6 KiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::/ Scope:Host
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (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 |
+-------+------------------------------------------------------------------------------------+

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

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

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

    OpenStack实践系列⑦深入理解neutron和虚拟机 五.深入理解Neutron 5.1 虚拟机网卡和网桥 [root@node1 ~]# ifconfig brq65c11cc3-8e: fl ...

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

    OpenStack实践系列⑨云硬盘服务Cinder八.cinder8.1存储的三大分类 块存储:硬盘,磁盘阵列DAS,SAN存储 文件存储:nfs,GluserFS,Ceph(PB级分布式文件系统), ...

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

    OpenStack实践系列⑧可视化服务Horizon之Dashboard演示 七.可视化服务Horizon之Dashboard演示 仪表板依赖于功能核心服务,包括身份,图像服务,计算和网络两种(neu ...

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

    OpenStack实践系列①openstack简介及基础环境部署 一.OpenStack初探1.1 OpenStack简介 OpenStack是一整套开源软件项目的综合,它允许企业或服务提供者建立.运 ...

  5. OpenStack实践系列⑤网络服务Neutron

    OpenStack实践系列⑤网络服务Neutron 3.8 Neturn 服务部署 注册neutron服务 [root@node1 ~]# source admin-openrc.sh [root@n ...

  6. OpenStack实践系列④计算服务Nova

    OpenStack实践系列④计算服务Nova 3.6 Nova控制节点的部署创建服务的凭证,完成下列步骤: 创建nova用户,并加入到service项目中,赋予admin权限 [root@node1 ...

  7. OpenStack实践系列②认证服务Keystone

    OpenStack实践系列②认证服务Keystone 三.实战OpenStack之控制节点3.1 CentOS7的时间同步服务器chrony 下载chrony # yum install -y chr ...

  8. OpenStack实践系列③镜像服务Glance

    OpenStack实践系列③镜像服务Glance 3.5 Glance部署 修改glance-api和glance-registry的配置文件,同步数据库 [root@node1 ~]# vim /e ...

  9. Openstack实践(1)部署使用实例及neutron网络

    版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://www.cnblogs.com/SuperXJ/ 如何快速部署使用openstack,使用kolla吧,o ...

随机推荐

  1. Thinkphp控制器,1.多层控制器2.多级控制器

    1.多层控制器 ThinkPHP的控制器支持多层和多级,多层指的是控制器可以分层,例如除了默认的Controller控制器层(我们可以称之为访问控制器),还可以添加事件控制器(层),例如: ├─Con ...

  2. 20145225《Java程序设计》实验一 Java开发环境的熟悉(Linux + Eclipse)

    20145225<Java程序设计> 实验一 Java开发环境的熟悉(Linux + Eclipse) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑 ...

  3. ListView配合CheckBox出现position位置错误的解决

    最近做checkBox和ListView配合使用,想把position的位置传入到 checkBox的onCheckedChanged,于是我就在getView的时候, 把position通过chec ...

  4. Deal with Android phones with pattern lock on

    Yesterday my colleague asked me for help...She has two android phones , one is hTC and the other is ...

  5. ASP&period;NET后台调用API方法

    /// <summary> /// 调用API POST请求与获取结果 /// </summary> ///URL 与 JSON串 public static string H ...

  6. MATLAB 实时脚本(live-script)使用

    在matlab2016a及以上的版本不建议安装notebook来编写实施脚本,以为之后的matlab里面会有live-script,他可以创建实施脚本,使脚本与方便操作.那么这个live script ...

  7. android -------- 沉浸式状态栏和沉浸式导航栏(ImmersionBar)

    android 4.4以上沉浸式状态栏和沉浸式导航栏管理,包括状态栏字体颜色,适用于Activity.Fragment.DialogFragment.Dialog,并且适配刘海屏,适配软键盘弹出等问题 ...

  8. boost&period;asio包装类st&lowbar;asio&lowbar;wrapper开发教程(2013&period;12&period;8更新)(二)

    如果你是偶然浏览到这里,请先看 源代码及例程下载地址:命令行:svn checkout http://st-asio-wrapper.googlecode.com/svn/trunk/ st-asio ...

  9. tmux 复制粘贴

    tmux版本(tmux 2.3): $tmux -V 要想让tmux和系统剪贴板之间互相复制粘贴,在linux中需要先安装 xclip: sudo apt-get install xclip 然后在 ...

  10. C&num; oracle 日期型字段,使用参数传值时,遇到ORA-01810&colon; format code appears twice错误

    C#操作oracle数据库时,发现使用to_date('2014-01-03 18:00:00','yyyy-mm-dd hh:MM:ss')时,会出现ORA-01810: format code a ...