在openstack上创建第一个虚拟机

一、创建虚拟网络

第一次创建虚拟机,使用命令行来创建

在控制节点上,加载 admin 凭证来获取管理员能执行的命令访问权限

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

创建提供者网络

[[email protected] ~]# neutron net-create --shared --provider:physical_network public --provider:network_type flat public-net
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2016-11-09T17:03:20                  |
| description               |                                      |
| id                        | 2cbfb54c-b760-41e1-ba69-83131220463b |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| mtu                       | 1500                                 |
| name                      | public-net                           |
| port_security_enabled     | True                                 |
| provider:network_type     | flat                                 |
| provider:physical_network | public                               |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | 53f72af1420a4d098d48f2c82d7e9ec7     |
| updated_at                | 2016-11-09T17:03:20                  |
+---------------------------+--------------------------------------+
#参数解释
#--provider:physical_network网络类型选项,在配置文件中设置的为public,public映射的是eth0端口
#--provider:network_type 提供者的网络类型flat
#public-net是提供者网络的名称,按照自己的意愿定义

查看已经创建的网络

[[email protected] ~]# neutron net-list
+--------------------------------------+------------+---------+
| id                                   | name       | subnets |
+--------------------------------------+------------+---------+
| 2cbfb54c-b760-41e1-ba69-83131220463b | public-net |         |
+--------------------------------------+------------+---------+

创建子网

[[email protected] ~]# neutron subnet-create --name public-subnet --allocation-pool start=192.168.56.100,end=192.168.56.200 --dns-nameserver 223.5.5.5 --gateway 192.168.56.2 public-net 192.168.56.0/24
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.56.100", "end": "192.168.56.200"} |
| cidr              | 192.168.56.0/24                                      |
| created_at        | 2016-11-10T02:56:27                                  |
| description       |                                                      |
| dns_nameservers   | 223.5.5.5                                            |
| enable_dhcp       | True                                                 |
| gateway_ip        | 192.168.56.2                                         |
| host_routes       |                                                      |
| id                | 6e217cbe-3201-4b47-8765-84ba932afa93                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | public-subnet                                        |
| network_id        | 2cbfb54c-b760-41e1-ba69-83131220463b                 |
| subnetpool_id     |                                                      |
| tenant_id         | 53f72af1420a4d098d48f2c82d7e9ec7                     |
| updated_at        | 2016-11-10T02:56:27                                  |
+-------------------+------------------------------------------------------+

查看创建的子网

[[email protected] ~]# neutron subnet-list
+--------------------------------------+---------------+-----------------+------------------------------------------------------+
| id                                   | name          | cidr            | allocation_pools                                     |
+--------------------------------------+---------------+-----------------+------------------------------------------------------+
| 6e217cbe-3201-4b47-8765-84ba932afa93 | public-subnet | 192.168.56.0/24 | {"start": "192.168.56.100", "end": "192.168.56.200"} |
+--------------------------------------+---------------+-----------------+------------------------------------------------------+

再次执行neutron net-list,可以看到创建的网络与子网已经关联在一起

[[email protected] ~]# neutron net-list
+--------------------------------------+------------+------------------------------------------------------+
| id                                   | name       | subnets                                              |
+--------------------------------------+------------+------------------------------------------------------+
| 2cbfb54c-b760-41e1-ba69-83131220463b | public-net | 6e217cbe-3201-4b47-8765-84ba932afa93 192.168.56.0/24 |
+--------------------------------------+------------+------------------------------------------------------+

二、创建m1.nano规格的主机

1、创建一个nano规格的主机

默认的最小规格的主机需要512 MB内存。对于环境中计算节点内存不足4 GB的,我们推荐创建只需要64 MB的m1.nano规格的主机。若单纯为了测试的目的,请使用m1.nano规格的主机来加载CirrOS镜像

[[email protected] ~]# 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       |
+----------------------------+---------+
#--id,主机类型的ID
#--vcpus,创建主机的cpu的数量
#--ram,内存,默认单位为M
#--disk,硬盘,默认单位为G
[[email protected] ~]# 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      |
+----+-----------+-------+------+-----------+-------+-----------+
#ID为0的是刚才创建的,生产环境中可以依据自己的需要进行创建

2、生成一个键值对

(1)导入demo用户的环境变量

[[email protected] ~]# cat demo-openstack.sh 
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=demo
export OS_USERNAME=demo
export OS_PASSWORD=DEMO_PASS
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
[[email protected] ~]# source demo-openstack.sh

生成密钥对

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

在openstack上创建密钥对

[[email protected] ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | 76:e0:a8:ff:ec:20:43:40:5d:42:0a:f1:90:1f:78:38 |
| name        | mykey                                           |
| user_id     | 6762a6adffd140b1906bbe69dbf42518                |
+-------------+-------------------------------------------------+

验证密钥对是否创建成功

[[email protected] ~]# openstack keypair list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 76:e0:a8:ff:ec:20:43:40:5d:42:0a:f1:90:1f:78:38 |
+-------+-------------------------------------------------+

3、增加安全组规则

默认情况下, default安全组适用于所有实例并且包括拒绝远程访问实例的防火墙规则。对诸如CirrOS这样的Linux镜像,至少允许ICMP (ping) 和安全shell(SSH)规则。

添加规则到default安全组

允许icmp
[[email protected] ~]# openstack security group rule create --proto icmp default
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | ca56bc9b-5f12-43ea-b72f-4638cfb55094 |
| ip_protocol           | icmp                                 |
| ip_range              | 0.0.0.0/0                            |
| parent_group_id       | a6670191-a77f-44f1-86b1-a617a5c7547d |
| port_range            |                                      |
| remote_security_group |                                      |
+-----------------------+--------------------------------------+
允许ssh连接
[[email protected] ~]# openstack security group rule create --proto tcp --dst-port 22 default
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| id                    | 5457a51f-a177-4db3-bac5-5b8d1cfb939d |
| ip_protocol           | tcp                                  |
| ip_range              | 0.0.0.0/0                            |
| parent_group_id       | a6670191-a77f-44f1-86b1-a617a5c7547d |
| port_range            | 22:22                                |
| remote_security_group |                                      |
+-----------------------+--------------------------------------+

4、创建实例

[[email protected] ~]# openstack server create --flavor m1.nano --image cirros   --nic net-id=2cbfb54c-b760-41e1-ba69-83131220463b --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                            | Q9KXwLniQpoM                                  |
| config_drive                         |                                               |
| created                              | 2016-11-10T06:13:27Z                          |
| flavor                               | m1.nano (0)                                   |
| hostId                               |                                               |
| id                                   | 0006405c-db45-42b4-a65a-d4a2041e2e88          |
| image                                | cirros (29d99654-ba91-4d04-8808-e1b8d16861fb) |
| key_name                             | mykey                                         |
| name                                 | provider-instance                             |
| os-extended-volumes:volumes_attached | []                                            |
| progress                             | 0                                             |
| project_id                           | 81e76ab533b14b448b1c6394bc5e4d86              |
| properties                           |                                               |
| security_groups                      | [{u‘name‘: u‘default‘}]                       |
| status                               | BUILD                                         |
| updated                              | 2016-11-10T06:13:28Z                          |
| user_id                              | 6762a6adffd140b1906bbe69dbf42518              |
+--------------------------------------+-----------------------------------------------+
#--nic 这里使用网络的ID

查看已创建的主机

[[email protected] ~]# openstack server list
+--------------------------------------+-------------------+--------+---------------------------+
| ID                                   | Name              | Status | Networks                  |
+--------------------------------------+-------------------+--------+---------------------------+
| 0006405c-db45-42b4-a65a-d4a2041e2e88 | provider-instance | ACTIVE | public-net=192.168.56.101 |
+--------------------------------------+-------------------+--------+---------------------------+

5、连接虚拟机

默认的用户名是cirros,密码是cubswin:)

[[email protected] ~]# ssh [email protected]
[email protected]‘s password: 
$ sudo su -
# ifconfig
eth0      Link encap:Ethernet  HWaddr FA:16:3E:C5:10:81  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::f816:3eff:fec5:1081/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133 errors:0 dropped:0 overruns:0 frame:0
          TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16003 (15.6 KiB)  TX bytes:15456 (15.0 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)
时间: 2024-10-20 06:34:54

在openstack上创建第一个虚拟机的相关文章

创建第一台虚拟机在Azure Stack TP2

前面一片博文我们已经成功的部署了Azure Stack TP2的POC环境,那么今天我们就来看一下如何在Azure Stack上创建我们的第一台虚拟机. Azure Stack TP2部署成功以后,我们需要打开虚拟机MAS-CON1的控制台(可以使用RDP的方式连接),登陆虚拟机MAS-CON1以后我们会发现在桌面上有一个快捷方式"Microsoft Azure Stack POC Portal",双击快捷方式启动新门户. 使用部署Azure Stack的时候使用的Azure账号登陆:

CentOS 7部署OpenStack(8)—创建第一台虚拟机

创建key [[email protected] ~]# source kevin-openrc.sh [[email protected] ~]# ssh-keygen -q -N "" [[email protected] ~]# nova keypair-add --pub-key .ssh/id_rsa.pub mykey [[email protected] ~]# nova keypair-list +-------+----------------------------

在ESXi上建立第一台虚拟机

利用Vsphere Client连接ESXi主机,然后右击主机,在弹出的快捷菜单里选择"新建虚拟机"选择.当然也可以再清单里选择新建虚拟机如图: 这里选择新虚拟机的配置项,其中"典型"选项是跳过一些很少需要更改其默认值的选项,从而缩短了虚拟机创建过程:"自定义"选项是列出了每个需要设置的虚拟硬件.选择"典型"选项后,可以在虚拟机建立完成后再修改每个需要设置的虚拟机硬件.这里我选择了"典型"安装,如图: 在虚

quick-cocos2d-x教程1:在window上创建第一个项目文件夹,并制作helloworld

说明:此教程是针对cocos2dx 2.0系列的,3.0的版本号,如今还没有公布出来. 1)首先从github.com把这个项目下载到本地.然后装到d盘的根文件夹,并设置文件夹路径为d:\quick-cocos2d-x 站点地址:https://github.com/chukong/quick-cocos2d-x 2)然后通过cmd进入命令模式, cd d:\quick-cocos2d-x cd bin  进入命令文件夹 d: 进入d盘 create_project -h 查看帮助 create

openstack部署之创建第一个实例

简介 当完成keystone.glance.nova.neutron组件的部署(部署方法参考之前的博文)之后,我们就可以创建第一个虚拟机实例了,下边具体操作下创建第一个虚拟机实例. 创建第一个实例 创建provider network 设置环境变量,这个在所有服务部署中都会用到,所以如果有报错,首先考虑是否设置环境变量 [[email protected] ~]# source admin-openstack.sh 创建网络 $ openstack network create --share

KVM虚拟化技术之使用Qemu-kvm创建和管理虚拟机

一.KVM简介 KVM(名称来自英语:Kernel-basedVirtual Machine的缩写,即基于内核的虚拟机),是一种用于Linux内核中的虚拟化基础设施,可以将Linux内核转化为一个hypervisor.KVM在2007年2月被导入Linux 2.6.20核心中,以可加载核心模块的方式被移植到FreeBSD及illumos上. KVM在具备Intel VT或AMD-V功能的x86平台上运行.它也被移植到S/390,PowerPC与IA-64平台上.在Linux内核3.9版中,加入A

KVM虚拟化:使用qemu-kvm创建和管理虚拟机

CentOS 6加载了KVM模块后,我们是无法进行虚拟机的管理的,如果需要管理KVM虚拟机,还需要管理工具才可以.先看一下KVM的管理工具栈. yum grouplist |grep -i "virtualization" Virtualization: qemu-kvm Virtualization Client: python-virtinst, virt-manager, virt-viewer Virtualization Platform: libvirt, libvirt-

使用virt-manager创建和管理虚拟机

1.虚拟机管理程序和虚拟机管理 一个服务器上只安装单一操作系统的时代已经过去,单个服务器可通过安装多个虚拟机来运行不同操作系统.虚拟机的大量使用减少了所需的服务其硬件,降低了服务器的功耗,但却带来了另外一个问题,多虚拟机数目的增加使其管理变得更加复杂. 虚拟化为管理虚拟机及其资源以及物理主机的基础资源带来了新的挑战.多个操作系统现在以虚拟机的形式共享一个物理主机的资源,操作系统与物理主机之间不再存在一对一的映射关系.每个虚拟机使用一个容器和其他元数据来表示,该容器持有一个或多个虚拟磁盘,而这些元

Azure技术08-虚拟机-创建高性能存储,并创建DS系列虚拟机

在使用Azure虚拟机过程中,不免遇到一些应用对磁盘IOPS要求非常高,针对高IOPS要求的应用,我们在以前只能通过Windows系统层面创建RAID的方式来提升磁盘性能,其实Azure高级存储Premium Storage在今年上半年就已经正式向广大用户推出,亮点在于Premium Storage服务采用SSD,并能够带来最高32TB存储容量以及每个VM高达64000 IOPS(即每秒IO操作次数). 在Azure Portal上现在是不支持图形化界面来创建Premium Storage的,所