云计算OpenStack---创建实例
Posted renyz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云计算OpenStack---创建实例相关的知识,希望对你有一定的参考价值。
一、创建虚拟网络(Self-service network)
网络概述图:
网络连接图:
1、创建self-service网络
(1)加载系统变量:
[root@ren3 ~]# source openrc
(2)创建网络:
[root@ren3 ~]# openstack network list [root@ren3 ~]# openstack network create selfservice +---------------------------+--------------------------------------+ | Field | Value | +---------------------------+--------------------------------------+ | admin_state_up | UP | | availability_zone_hints | | | availability_zones | | | created_at | 2019-10-15T06:41:10Z | | description | | | dns_domain | None | | id | c13ba919-6fb8-44f3-94f2-2f637c16db50 | | ipv4_address_scope | None | | ipv6_address_scope | None | | is_default | None | | mtu | 1450 | | name | selfservice | | port_security_enabled | True | | project_id | 640da7a471524d35a3efca2692b9555a | | provider:network_type | vxlan | | provider:physical_network | None | | provider:segmentation_id | 8 | | qos_policy_id | None | | revision_number | 3 | | router:external | Internal | | segments | None | | shared | False | | status | ACTIVE | | subnets | | | updated_at | 2019-10-15T06:41:10Z | +---------------------------+--------------------------------------+ [root@ren3 ~]# openstack network list +--------------------------------------+-------------+---------+ | ID | Name | Subnets | +--------------------------------------+-------------+---------+ | c13ba919-6fb8-44f3-94f2-2f637c16db50 | selfservice | | +--------------------------------------+-------------+---------+
(3)在网络上创建子网
[root@ren3 ml2]# openstack subnet create --network selfservice --dns-nameserver 114.114.114.114 --gateway 12.12.12.1 --subnet-range 12.12.12.0/24 selfservice +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | allocation_pools | 12.12.12.2-12.12.12.254 | | cidr | 12.12.12.0/24 | | created_at | 2019-10-15T06:47:24Z | | description | | | dns_nameservers | 114.114.114.114 | | enable_dhcp | True | | gateway_ip | 12.12.12.1 | | host_routes | | | id | e749bea9-0672-465d-84b2-0a1ea0a33321 | | ip_version | 4 | | ipv6_address_mode | None | | ipv6_ra_mode | None | | name | selfservice | | network_id | c13ba919-6fb8-44f3-94f2-2f637c16db50 | | project_id | 640da7a471524d35a3efca2692b9555a | | revision_number | 2 | | segment_id | None | | service_types | | | subnetpool_id | None | | updated_at | 2019-10-15T06:47:24Z | +-------------------+--------------------------------------+ [root@ren3 ~]# openstack network list +---------------------------+-------------+----------------------------+ | ID | Name | Subnets | +---------------------------+-------------+----------------------------+ | c13ba919-6fb8-44f3-94f2-2 | selfservice | e749bea9-0672-465d- | | f637c16db50 | | 84b2-0a1ea0a33321 | +---------------------------+-------------+----------------------------+
2、创建一个路由器
(1)创建路由
[root@ren3 ~]# openstack router create my_router
Created a new router: +-------------------------+--------------------------------------+ | Field | Value | +-------------------------+--------------------------------------+ | admin_state_up | UP | | availability_zone_hints | | | availability_zones | | | created_at | 2016-11-04T18:32:56Z | | description | | | external_gateway_info | null | | flavor_id | None | | headers | | | id | 67324374-396a-4db6-9443-c70be167a42b | | name | my_router | | project_id | 3828e7c22c5546e585f27b9eb5453788 | | project_id | 3828e7c22c5546e585f27b9eb5453788 | | revision_number | 2 | | routes | | | status | ACTIVE | | updated_at | 2016-11-04T18:32:56Z | +-------------------------+--------------------------------------+
(2)在路由器上添加自助网络子网作为接口:
[root@ren3 ~]# neutron router-interface-add router selfservice
Added interface bff6605d-824c-41f9-b744-21d128fc86e1 to router router.
(3)在路由器上的提供者网络上设置网关:
[root@ren3 ~]# openstack network create my_network --external +---------------------------+--------------------------------------+ | Field | Value | +---------------------------+--------------------------------------+ | admin_state_up | UP | | availability_zone_hints | | | availability_zones | | | created_at | 2019-10-15T10:02:00Z | | description | | | dns_domain | None | | id | a012f253-b330-4d44-bb41-15b643ab4a43 | | ipv4_address_scope | None | | ipv6_address_scope | None | | is_default | False | | mtu | 1450 | | name | my_network | | port_security_enabled | True | | project_id | 640da7a471524d35a3efca2692b9555a | | provider:network_type | vxlan | | provider:physical_network | None | | provider:segmentation_id | 98 | | qos_policy_id | None | | revision_number | 4 | | router:external | External | | segments | None | | shared | False | | status | ACTIVE | | subnets | | | updated_at | 2019-10-15T10:02:00Z | +---------------------------+--------------------------------------+ [root@ren3 ~]# neutron router-gateway-set my_router my_network neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead. Set gateway for router my_router
[root@ren3 ~]# openstack router list +----------+----------+--------+-------+-------------+-------+------------+ | ID | Name | Status | State | Distributed | HA | Project | +----------+----------+--------+-------+-------------+-------+------------+ | 83057365 | my_route | ACTIVE | UP | False | False | 640da7a471 | | -c772 | r | | | | | 524d35a3ef | | -455c- | | | | | | ca2692b955 | | 8e1d-2e1 | | | | | | 5a | | 4634e8ab | | | | | | | | 8 | | | | | | | +----------+----------+--------+-------+-------------+-------+------------+
3、验证
[root@ren3 ~]# ip netns qdhcp-a012f253-b330-4d44-bb41-15b643ab4a43 (id: 2) qrouter-83057365-c772-455c-8e1d-2e14634e8ab8 (id: 1) qdhcp-c13ba919-6fb8-44f3-94f2-2f637c16db50 (id: 0) [root@ren3 ~]# ip netns list qdhcp-a012f253-b330-4d44-bb41-15b643ab4a43 (id: 2) qrouter-83057365-c772-455c-8e1d-2e14634e8ab8 (id: 1) qdhcp-c13ba919-6fb8-44f3-94f2-2f637c16db50 (id: 0) [root@ren3 ~]# neutron router-port-list my_router neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead. +---------------+------+---------------+---------------+---------------+ | id | name | tenant_id | mac_address | fixed_ips | +---------------+------+---------------+---------------+---------------+ | 50fa88f7-904f | | | fa:16:3e:3c:7 | {"subnet_id": | | -4803-91c2-41 | | | 7:97 | "7d6d71b3-f2f | | 7566c035f8 | | | | 3-4f84-8b83-7 | | | | | | 91a1ad0262d", | | | | | | "ip_address": | | | | | | "192.168.12.1 | | | | | | 2"} | | 7f9b30e2 | | 640da7a471524 | fa:16:3e:3f:5 | {"subnet_id": | | -459f-407e-a3 | | d35a3efca2692 | 4:1a | "e749bea9-067 | | e2-e8aaa1c72d | | b9555a | | 2-465d-84b2-0 | | aa | | | | a1ea0a33321", | | | | | | "ip_address": | | | | | | "12.12.12.1"} | +---------------+------+---------------+---------------+---------------+
4、图形化界面创建
二、创建m1.nano flavor
创建最小的实例类型,每个实例64 MB内存,1G的磁盘容量。
[root@ren3 ~]# openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 low_level +----------------------------+-----------+ | Field | Value | +----------------------------+-----------+ | OS-FLV-DISABLED:disabled | False | | OS-FLV-EXT-DATA:ephemeral | 0 | | disk | 1 | | id | 0 | | name | low_level | | os-flavor-access:is_public | True | | properties | | | ram | 64 | | rxtx_factor | 1.0 | | swap | | | vcpus | 1 | +----------------------------+-----------+
三、创建一个密钥对
[root@ren3 ~]# cd /root/.ssh/ [root@ren3 .ssh]# ls authorized_keys id_rsa id_rsa.pub known_hosts [root@ren3 .ssh]# openstack keypair create --public-key /root/.ssh/id_rsa.pub my_key +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint | cf:5f:37:a6:e3:e3:fd:1c:6b:94:94:dd:4a:e8:db:78 | | name | my_key | | user_id | 372fccfd264c4edfb600af3f56052ec7 | +-------------+-------------------------------------------------+ [root@ren3 .ssh]# openstack keypair list +--------+-------------------------------------------------+ | Name | Fingerprint | +--------+-------------------------------------------------+ | my_key | cf:5f:37:a6:e3:e3:fd:1c:6b:94:94:dd:4a:e8:db:78 | +--------+-------------------------------------------------+
四、添加安全组规则
创建一个lamp架构的安全规则(icmp,ssh,http)
[root@ren3 ~]# openstack security group create lamp +-----------------+----------------------------------------------------+ | Field | Value | +-----------------+----------------------------------------------------+ | created_at | 2019-10-15T11:21:42Z | | description | lamp | | id | 70ebb338-8392-4dfe-8633-4d7595519975 | | name | lamp | | project_id | 640da7a471524d35a3efca2692b9555a | | revision_number | 1 | | rules | created_at=‘2019-10-15T11:21:42Z‘, | | | direction=‘egress‘, ethertype=‘IPv4‘, id=‘bf033551 | | | -45ad-4e79-8fa6-786f45b09f8a‘, | | | revision_number=‘1‘, | | | updated_at=‘2019-10-15T11:21:42Z‘ | | | created_at=‘2019-10-15T11:21:42Z‘, | | | direction=‘egress‘, ethertype=‘IPv6‘, id | | | =‘1bdb3f9f-a5cf-4149-9d3e-3f23b9b7f7db‘, | | | revision_number=‘1‘, | | | updated_at=‘2019-10-15T11:21:42Z‘ | | updated_at | 2019-10-15T11:21:42Z | +-----------------+----------------------------------------------------+ [root@ren3 ~]# openstack security group rule create --proto icmp lamp +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2019-10-15T11:22:52Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | 8e3b5c81-cb95-495a-8aeb-834ea592195e | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 640da7a471524d35a3efca2692b9555a | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 70ebb338-8392-4dfe-8633-4d7595519975 | | updated_at | 2019-10-15T11:22:52Z | +-------------------+--------------------------------------+ [root@ren3 ~]# openstack security group rule create --proto tcp --dst-port 22 lamp +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2019-10-15T11:24:12Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | cc92bbd4-f0f5-4691-859c-e83987e2eff0 | | name | None | | port_range_max | 22 | | port_range_min | 22 | | project_id | 640da7a471524d35a3efca2692b9555a | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 70ebb338-8392-4dfe-8633-4d7595519975 | | updated_at | 2019-10-15T11:24:12Z | +-------------------+--------------------------------------+ [root@ren3 ~]# openstack security group rule create --proto tcp --dst-port 80 lamp +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2019-10-15T11:24:22Z | | description | | | direction | ingress | | ether_type | IPv4 | | id | c3e449ae-1125-4ca3-8c82-f28be356ce0a | | name | None | | port_range_max | 80 | | port_range_min | 80 | | project_id | 640da7a471524d35a3efca2692b9555a | | protocol | tcp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id | 70ebb338-8392-4dfe-8633-4d7595519975 | | updated_at | 2019-10-15T11:24:22Z | +-------------------+--------------------------------------+ [root@ren3 ~]# openstack security group rule list lamp +---------------+-------------+-----------+------------+-----------------------+ | ID | IP Protocol | IP Range | Port Range | Remote Security Group | +---------------+-------------+-----------+------------+-----------------------+ | 1bdb3f9f- | None | None | | None | | a5cf-4149 | | | | | | -9d3e- | | | | | | 3f23b9b7f7db | | | | | | 8e3b5c81-cb95 | icmp | 0.0.0.0/0 | | None | | -495a-8aeb- | | | | | | 834ea592195e | | | | | | bf033551 | None | None | | None | | -45ad-4e79-8f | | | | | | a6-786f45b09f | | | | | | 8a | | | | | | c3e449ae-1125 | tcp | 0.0.0.0/0 | 80:80 | None | | -4ca3-8c82-f2 | | | | | | 8be356ce0a | | | | | | cc92bbd4-f0f5 | tcp | 0.0.0.0/0 | 22:22 | None | | -4691-859c- | | | | | | e83987e2eff0 | | | | | +---------------+-------------+-----------+------------+-----------------------+
五、创建一个实例
1、选择实例类型并创建实例
[root@ren3 ~]# openstack flavor list +----+-----------+-----+------+-----------+-------+-----------+ | ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public | +----+-----------+-----+------+-----------+-------+-----------+ | 0 | low_level | 64 | 1 | 0 | 1 | True | +----+-----------+-----+------+-----------+-------+-----------+ [root@ren3 ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | d8e9a113-edef-41a6-9778-622edf76de39 | cirros | active | +--------------------------------------+--------+--------+ [root@ren3 ~]# openstack network list +---------------------------+-------------+----------------------------+ | ID | Name | Subnets | +---------------------------+-------------+----------------------------+ | a012f253-b330-4d44-bb41-1 | my_network | 7d6d71b3-f2f3-4f84-8b83-79 | | 5b643ab4a43 | | 1a1ad0262d | | c13ba919-6fb8-44f3-94f2-2 | selfservice | e749bea9-0672-465d- | | f637c16db50 | | 84b2-0a1ea0a33321 | +---------------------------+-------------+----------------------------+ [root@ren3 ~]# openstack security group list +----------------------+---------+-------------+-----------------------+ | ID | Name | Description | Project | +----------------------+---------+-------------+-----------------------+ | 2b76303a-b94f-4be8 | default | 缺省安全组 | | | -b00f-68114afac2dc | | | | | 70ebb338-8392-4dfe-8 | lamp | lamp | 640da7a471524d35a3efc | | 633-4d7595519975 | | | a2692b9555a | | 9dbc76d7-310f-4405-a | default | 缺省安全组 | 640da7a471524d35a3efc | | dd3-8f2b915d8436 | | | a2692b9555a | +----------------------+---------+-------------+-----------------------+
[root@ren3 ~]# openstack server create --flavor low_level --image cirros --nic net-id=a012f253-b330-4d44-bb41-15b643ab4a43 --security-group lamp --key-name my_key lamp_instance +----------------------------------+-----------------------------------+ | Field | Value | +----------------------------------+-----------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV- | None | | ATTR:hypervisor_hostname | | | OS-EXT-SRV-ATTR:instance_name | | | 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 | cwN4nLL5KAhF | | config_drive | | | created | 2019-10-15T11:50:06Z | | flavor | low_level (0) | | hostId | | | id | b37c0fd3-b9e0-4487-8991-2ea783fb2 | | | f8c | | image | cirros (d8e9a113-edef- | | | 41a6-9778-622edf76de39) | | key_name | my_key | | name | lamp_instance | | progress | 0 | | project_id | 640da7a471524d35a3efca2692b9555a | | properties | | | security_groups | name=‘lamp‘ | | status | BUILD | | updated | 2019-10-15T11:50:06Z | | user_id | 372fccfd264c4edfb600af3f56052ec7 | | volumes_attached | | +----------------------------------+-----------------------------------+ [root@ren3 ~]# openstack server list +---------------+---------------+--------+----------------+------------+ | ID | Name | Status | Networks | Image Name | +---------------+---------------+--------+----------------+------------+ | b37c0fd3-b9e0 | lamp_instance | ACTIVE | my_network=192 | cirros | | -4487-8991-2e | | | .168.12.18 | | | a783fb2f8c | | | | | +---------------+---------------+--------+----------------+------------+
2、使用虚拟控制台访问实例
[root@ren3 ~]# openstack console url show lamp_instance +-------+--------------------------------------------------------------+ | Field | Value | +-------+--------------------------------------------------------------+ | type | novnc | | url | http://192.168.11.3:6080/vnc_auto.html?token=ad8fe16d- | | | ec49-4169-a8a2-75e6b3a35b74 | +-------+--------------------------------------------------------------+
3、远程访问实例(创建浮点ip)
[root@ren3 ~]# openstack floating ip create my_network +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | created_at | 2019-10-15T12:05:36Z | | description | | | fixed_ip_address | None | | floating_ip_address | 192.168.12.16 | | floating_network_id | a012f253-b330-4d44-bb41-15b643ab4a43 | | id | c16f34c0-1b2c-4ba0-ac76-f10b3287f7b2 | | name | None | | port_id | None | | project_id | 640da7a471524d35a3efca2692b9555a | | revision_number | 1 | | router_id | None | | status | DOWN | | updated_at | 2019-10-15T12:05:36Z | +---------------------+--------------------------------------+ [root@ren3 ~]# openstack server add floating ip lamp_instance 192.168.12.16
六、创建块存储
1、创建卷
[root@ren3 ~]# openstack volume create --size 1 volume1 +---------------------+--------------------------------------+ | Field | Value | +---------------------+--------------------------------------+ | attachments | [] | | availability_zone | nova | | bootable | false | | consistencygroup_id | None | | created_at | 2019-10-15T12:18:08.989388 | | description | None | | encrypted | False | | id | 2d9b34ec-d564-41ad-8ce7-cf8c2777954a | | migration_status | None | | multiattach | False | | name | volume1 | | properties | | | replication_status | None | | size | 1 | | snapshot_id | None | | source_volid | None | | status | creating | | type | None | | updated_at | None | | user_id | 372fccfd264c4edfb600af3f56052ec7 | +---------------------+--------------------------------------+ [root@ren3 ~]# openstack volume list +------------------+--------------+-----------+------+-------------+ | ID | Display Name | Status | Size | Attached to | +------------------+--------------+-----------+------+-------------+ | 2d9b34ec-d564 | volume1 | available | 1 | | | -41ad-8ce7-cf8c2 | | | | | | 777954a | | | | | +------------------+--------------+-----------+------+-------------+
2、将该卷添加到一个实例
[root@ren3 ~]# openstack server add volume lamp_instance volume1 [root@ren3 ~]# openstack volume list +------------------+--------------+-----------+------+-------------+ | ID | Display Name | Status | Size | Attached to | +------------------+--------------+-----------+------+-------------+ | 2d9b34ec-d564 | volume1 | attaching | 1 | | | -41ad-8ce7-cf8c2 | | | | | | 777954a | | | | | +------------------+--------------+-----------+------+-------------+
以上是关于云计算OpenStack---创建实例的主要内容,如果未能解决你的问题,请参考以下文章