一、创建网络:
1、在控制节点上创建一个单一扁平网络(名字:flat),网络类型为flat,网络适共享的(share),网络提供者:physnet1,它是和eth0关联起来的
[root@linux-node1 ~]# source admin-openrc.sh [root@linux-node1 ~]# neutron net-create flat --shared --provider:physical_network physnet1 --provider:network_type flat Created a new network: +---------------------------+--------------------------------------+ | Field | Value | +---------------------------+--------------------------------------+ | admin_state_up | True | | availability_zone_hints | | | availability_zones | | | created_at | 2018-03-07T06:33:06Z | | description | | | id | 252e8345-0933-422e-a131-717747c03de8 | | ipv4_address_scope | | | ipv6_address_scope | | | mtu | 1500 | | name | flat | | port_security_enabled | True | | project_id | 503b0eab0420454e909a46e476bf1ede | | provider:network_type | flat | | provider:physical_network | physnet1 | | provider:segmentation_id | | | revision_number | 3 | | router:external | False | | shared | True | | status | ACTIVE | | subnets | | | tags | | | tenant_id | 503b0eab0420454e909a46e476bf1ede | | updated_at | 2018-03-07T06:33:09Z | +---------------------------+--------------------------------------+
2、对上一步创建的网络创建一个子网,名字为:subnet-create flat,设置dns和网关
[root@linux-node1 ~]# neutron subnet-create flat 172.22.0.0/24 --name flat-subnet --allocation-pool start=172.22.0.240,end=172.22.0.250 --dns-nameserver 172.16.9.60 --gateway 172.22.0.2 Created a new subnet: +-------------------+--------------------------------------------------+ | Field | Value | +-------------------+--------------------------------------------------+ | allocation_pools | {"start": "172.22.0.240", "end": "172.22.0.250"} | | cidr | 172.22.0.0/24 | | created_at | 2018-03-07T06:38:53Z | | description | | | dns_nameservers | 172.16.9.60 | | enable_dhcp | True | | gateway_ip | 172.22.0.2 | | host_routes | | | id | afb09c29-ae05-4ea5-820b-39dabbc42c0f | | ip_version | 4 | | ipv6_address_mode | | | ipv6_ra_mode | | | name | flat-subnet | | network_id | 252e8345-0933-422e-a131-717747c03de8 | | project_id | 503b0eab0420454e909a46e476bf1ede | | revision_number | 2 | | service_types | | | subnetpool_id | | | tenant_id | 503b0eab0420454e909a46e476bf1ede | | updated_at | 2018-03-07T06:38:54Z | +-------------------+--------------------------------------------------+
3、查看创建的网络和子网
[root@linux-node1 ~]# neutron net-list +-------------------------------------+------+-------------------------------------+ | id | name | subnets | +-------------------------------------+------+-------------------------------------+ | 252e8345-0933-422e-a131-717747c03de | flat | afb09c29-ae05-4ea5-820b- | | 8 | | 39dabbc42c0f 172.22.0.0/24 | +-------------------------------------+------+-------------------------------------+
注:创建虚拟机之前,由于一个网络下不能存在多个dhcp,所以一定关闭其他的dhcp选项下面开始正式创建虚拟机,为了可以连上所创建的虚拟机,在这里要创建一对公钥和私钥,并添加到openstack中
二、创建虚拟主机:
1、创建公钥:
root@linux-node1 ~]# source demo-openrc.sh [root@linux-node1 ~]# ssh-keygen -q -N "" Enter file in which to save the key (/root/.ssh/id_rsa): [root@linux-node1 ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | 25:5c:63:9a:61:3c:d6:5f:a7:0d:87:cb:19:67:c6:30 | | name | mykey | | user_id | d36d93abe45747468fdd46430a83e169 | +-------------+-------------------------------------------------+ [root@linux-node1 ~]# openstack keypair list +-------+-------------------------------------------------+ | Name | Fingerprint | +-------+-------------------------------------------------+ | mykey | 25:5c:63:9a:61:3c:d6:5f:a7:0d:87:cb:19:67:c6:30 | +-------+-------------------------------------------------+
2、创建一个安全组,打开icmp和开放22端口
[root@linux-node1 ~]# openstack security group rule create --proto icmp default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2018-03-08T05:09:49Z | | description | | | direction | ingress | | ethertype | IPv4 | | headers | | | id | 247ef297-f765-42b7-b2fe-ca4d1d3356c9 | | port_range_max | None | | port_range_min | None | | project_id | b71d521156214c438b7024701e7e06e8 | | project_id | b71d521156214c438b7024701e7e06e8 | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 84596f26-932d-4de9-8dc4-1eb15b6ec0e1 | | updated_at | 2018-03-08T05:09:49Z | +-------------------+--------------------------------------+ [root@linux-node1 ~]# openstack security group rule create --proto tcp --dst-port 22 default +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2018-03-08T05:10:07Z | | description | | | direction | ingress | | ethertype | IPv4 | | headers | | | id | c23a41fd-e37c-4a85-ba3b-4c373a5cec14 | | port_range_max | 22 | | port_range_min | 22 | | project_id | b71d521156214c438b7024701e7e06e8 | | project_id | b71d521156214c438b7024701e7e06e8 | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 84596f26-932d-4de9-8dc4-1eb15b6ec0e1 | | updated_at | 2018-03-08T05:10:07Z | +-------------------+--------------------------------------+
3、创建虚拟机之前要进行的确认虚拟机类型flavor(相当于EC2的intance的type)、需要的镜像(EC2的AMI),需要的网络(EC2的VPC),安全组(EC2的sg)
[root@linux-node1 ~]# source admin-openrc.sh [root@linux-node1 ~]# 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 | | properties | | | ram | 64 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+---------+ [root@linux-node1 ~]# source demo-openrc.sh [root@linux-node1 ~]# openstack flavor list +----+---------+-----+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+---------+-----+------+-----------+-------+-----------+ | 0 | m1.nano | 64 | 1 | 0 | 1 | True | +----+---------+-----+------+-----------+-------+-----------+ [root@linux-node1 ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | 8f5837b4-bbec-4ef5-96f6-aba989c27206 | cirros | active | +--------------------------------------+--------+--------+ [root@linux-node1 ~]# openstack network list +-------------------------------------+------+-------------------------------------+ | ID | Name | Subnets | +-------------------------------------+------+-------------------------------------+ | 252e8345-0933-422e-a131-717747c03de | flat | afb09c29-ae05-4ea5-820b- | | 8 | | 39dabbc42c0f | +-------------------------------------+------+-------------------------------------+ [root@linux-node1 ~]# openstack security group list +-----------------------+---------+-----------------------+------------------------+ | ID | Name | Description | Project | +-----------------------+---------+-----------------------+------------------------+ | 84596f26-932d-4de9-8d | default | Default security | b71d521156214c438b7024 | | c4-1eb15b6ec0e1 | | group | 701e7e06e8 | +-----------------------+---------+-----------------------+------------------------+
4、创建一台虚拟机,类型为m1.tiny,镜像为cirros(上文wget的),网络id为neutron net-list出来的,安全组就是默认的,选择刚开的创建的key-pair,虚拟机的名字为test-instance
[root@linux-node1 ~]# openstack server create --flavor m1.nano --image cirros --nic net-id=252e8345-0933-422e-a131-717747c03de8 --security-group default --key-name mykey test-instance +--------------------------------------+-----------------------------------------------+ | Field | Value | +--------------------------------------+-----------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | OS-EXT-STS:power_state | NOSTATE | | 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 | GV8aK778PGP7 | | config_drive | | | created | 2018-03-07T14:54:21Z | | flavor | m1.nano (0) | | hostId | | | id | e6594567-62d9-452e-8bd9-709a63435ef5 | | image | cirros (8f5837b4-bbec-4ef5-96f6-aba989c27206) | | key_name | mykey | | name | test-instance | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | project_id | b71d521156214c438b7024701e7e06e8 | | properties | | | security_groups | [{u'name': u'default'}] | | status | BUILD | | updated | 2018-03-07T14:54:25Z | | user_id | d36d93abe45747468fdd46430a83e169 | +--------------------------------------+-----------------------------------------------+
5、查看虚拟机:
[root@linux-node1 ~]# openstack server list +--------------------------------------+---------------+--------+----------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+---------------+--------+----------+------------+ | 4695d193-9fb0-42aa-9aa9-043820388e4a | test-instance | BUILD | | cirros | +--------------------------------------+---------------+--------+----------+------------+ [root@linux-node1 ~]# openstack server list +--------------------------------------+---------------+--------+-------------------+------------+ | ID | Name | Status | Networks | Image Name | +--------------------------------------+---------------+--------+-------------------+------------+ | 4695d193-9fb0-42aa-9aa9-043820388e4a | test-instance | ACTIVE | flat=172.22.0.248 | cirros | +--------------------------------------+---------------+--------+-------------------+------------+
三、登录验证:
1、SSH登录:
[root@linux-node1 ~]# ssh cirros@172.22.0.248 The authenticity of host '172.22.0.248 (172.22.0.248)' can't be established. RSA key fingerprint is SHA256:wjfS+uGVtyyrGl6ZmLp4nYA+4rcz5IYZU+cGF4DVaxY. RSA key fingerprint is MD5:2f:87:4e:a0:a1:49:96:66:ae:9a:e1:ff:b2:81:db:1c. Are you sure you want to continue connecting (yes/no)? yes cirros@172.22.0.248's password: $ ifconfig eth0 Link encap:Ethernet HWaddr FA:16:3E:79:4A:E4 inet addr:172.22.0.248 Bcast:172.22.0.255 Mask:255.255.255.0 inet6 addr: fe80::f816:3eff:fe79:4ae4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14627 errors:0 dropped:7 overruns:0 frame:0 TX packets:268 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:901702 (880.5 KiB) TX bytes:32866 (32.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) $
2、VNC登录:
[root@linux-node1 ~]# openstack console url show test-instance +-------+-----------------------------------------------------------------------------------+ | Field | Value | +-------+-----------------------------------------------------------------------------------+ | type | novnc | | url | http://172.22.0.218:6080/vnc_auto.html?token=95a38c93-dbc1-4873-8c49-9778b4d41aed |
网页登录:
创建完成