云计算OpenStack---创建实例(11)
阅读原文时间:2023年07月11日阅读:4

创建实例时,需要先创建网络及实例类型等其它配置:

一、创建虚拟网络(Self-service network)

网络概述图:

网络连接图:

1、创建self-service网络

(1)加载系统变量:

[root@ren3 ~]# source openrc

(2)创建网络:

[root@ren3 ~]# openstack network list

[root@ren3 ~]# openstack network create my_network
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2019-10-17T07:33:52Z |
| description | |
| dns_domain | None |
| id | 062d2b07-339e-4d54-aaca-6b9169d17f6c |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | None |
| mtu | 1450 |
| name | my_network |
| port_security_enabled | True |
| project_id | 640da7a471524d35a3efca2692b9555a |
| provider:network_type | vxlan |
| provider:physical_network | None |
| provider:segmentation_id | 85 |
| qos_policy_id | None |
| revision_number | 3 |
| router:external | Internal |
| segments | None |
| shared | False |
| status | ACTIVE |
| subnets | |
| updated_at | 2019-10-17T07:33:52Z |
+---------------------------+--------------------------------------+
[root@ren3 ~]# openstack network list
+--------------------------------------+------------+---------+
| ID | Name | Subnets |
+--------------------------------------+------------+---------+
| 062d2b07-339e-4d54-aaca-6b9169d17f6c | my_network | |
+--------------------------------------+------------+---------+

(3)在网络上创建子网

[root@ren3 ~]# openstack subnet create --network my_network --dns-nameserver 8.8.8.8 --gateway 12.12.12.1 --subnet-range 12.12.12.0/24 --allocation-pool start=12.12.12.10,end=12.12.12.20 my_network.subnet
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| allocation_pools | 12.12.12.10-12.12.12.20 |
| cidr | 12.12.12.0/24 |
| created_at | 2019-10-17T07:40:38Z |
| description | |
| dns_nameservers | 8.8.8.8 |
| enable_dhcp | True |
| gateway_ip | 12.12.12.1 |
| host_routes | |
| id | 54175b19-fada-4875-b00c-20e556433bdf |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | my_network.subnet |
| network_id | 062d2b07-339e-4d54-aaca-6b9169d17f6c |
| project_id | 640da7a471524d35a3efca2692b9555a |
| revision_number | 2 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| updated_at | 2019-10-17T07:40:38Z |
+-------------------+--------------------------------------+
[root@ren3 ~]# openstack subnet list
+-----------------+-----------------+------------------+---------------+
| ID | Name | Network | Subnet |
+-----------------+-----------------+------------------+---------------+
| 54175b19-fada-4 | my_network.subn | 062d2b07-339e- | 12.12.12.0/24 |
| 875-b00c- | et | 4d54-aaca- | |
| 20e556433bdf | | 6b9169d17f6c | |
+-----------------+-----------------+------------------+---------------+

2、创建一个路由器

(1)创建路由

[root@ren3 ~]# openstack router list

[root@ren3 ~]# openstack router create router
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2019-10-17T07:41:55Z |
| description | |
| distributed | False |
| external_gateway_info | None |
| flavor_id | None |
| ha | False |
| id | 84d406c2-3923-4a52-9368-9e310a40edb9 |
| name | router |
| project_id | 640da7a471524d35a3efca2692b9555a |
| revision_number | None |
| routes | |
| status | ACTIVE |
| updated_at | 2019-10-17T07:41:55Z |
+-------------------------+--------------------------------------+
[root@ren3 ~]# openstack router list
+-----------+--------+--------+-------+-------------+-------+------------+
| ID | Name | Status | State | Distributed | HA | Project |
+-----------+--------+--------+-------+-------------+-------+------------+
| 84d406c2- | router | ACTIVE | UP | False | False | 640da7a471 |
| 3923-4a52 | | | | | | 524d35a3ef |
| -9368-9e3 | | | | | | ca2692b955 |
| 10a40edb9 | | | | | | 5a |
+-----------+--------+--------+-------+-------------+-------+------------+

(2)在路由器上添加自助网络子网作为接口:

[root@ren3 ~]# neutron router-interface-add router my_network
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Unable to find subnet with name or id 'my_network'
[root@ren3 ~]# neutron router-interface-add router my_network.subnet
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Added interface 9c86abfa-c5d5-44c7-9aea-bd254c64781c to router router.

(3)在路由器上设置网关:(先创建一个外网)

[root@ren3 ~]# openstack network create external_network --external --share
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2019-10-17T07:46:38Z |
| description | |
| dns_domain | None |
| id | d97c8576-1990-4920-adea-98589cc816ab |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | False |
| mtu | 1450 |
| name | external_network |
| port_security_enabled | True |
| project_id | 640da7a471524d35a3efca2692b9555a |
| provider:network_type | vxlan |
| provider:physical_network | None |
| provider:segmentation_id | 67 |
| qos_policy_id | None |
| revision_number | 4 |
| router:external | External |
| segments | None |
| shared | True |
| status | ACTIVE |
| subnets | |
| updated_at | 2019-10-17T07:46:38Z |
+---------------------------+--------------------------------------+
[root@ren3 ~]# openstack subnet create --network external_network --dns-nameserver 8.8.8.8 --gateway 192.168.11.1 --subnet-range 192.168.11.0/24 --allocation-pool start=192.168.11.100,end=192.168.11.200 external_network.subnet
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| allocation_pools | 192.168.11.100-192.168.11.200 |
| cidr | 192.168.11.0/24 |
| created_at | 2019-10-17T07:49:11Z |
| description | |
| dns_nameservers | 8.8.8.8 |
| enable_dhcp | True |
| gateway_ip | 192.168.11.1 |
| host_routes | |
| id | 206ce64b-bd9b-4fc0-af2c-24ddb44fd9cc |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | external_network.subnet |
| network_id | d97c8576-1990-4920-adea-98589cc816ab |
| project_id | 640da7a471524d35a3efca2692b9555a |
| revision_number | 2 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| updated_at | 2019-10-17T07:49:11Z |
+-------------------+--------------------------------------+
[root@ren3 ~]# openstack subnet list
+----------------+----------------+----------------+-----------------+
| ID | Name | Network | Subnet |
+----------------+----------------+----------------+-----------------+
| 206ce64b-bd9b- | external_netwo | d97c8576-1990- | 192.168.11.0/24 |
| 4fc0-af2c- | rk.subnet | 4920-adea- | |
| 24ddb44fd9cc | | 98589cc816ab | |
| 54175b19-fada- | my_network.sub | 062d2b07-339e- | 12.12.12.0/24 |
| 4875-b00c- | net | 4d54-aaca- | |
| 20e556433bdf | | 6b9169d17f6c | |
+----------------+----------------+----------------+-----------------+

[root@ren3 ~]# neutron router-gateway-set router external_network
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Set gateway for router router

3、验证

[root@ren3 ~]# ip netns
qdhcp-d97c8576-1990-4920-adea-98589cc816ab (id: 2)
qrouter-84d406c2-3923-4a52-9368-9e310a40edb9 (id: 1)
qdhcp-062d2b07-339e-4d54-aaca-6b9169d17f6c (id: 0)
[root@ren3 ~]# neutron router-port-list router
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+---------------+------+---------------+---------------+---------------+
| id | name | tenant_id | mac_address | fixed_ips |
+---------------+------+---------------+---------------+---------------+
| 9c86abfa- | | 640da7a471524 | fa:16:3e:4b:7 | {"subnet_id": |
| c5d5-44c7 | | d35a3efca2692 | c:ba | "54175b19-fad |
| -9aea- | | b9555a | | a-4875-b00c-2 |
| bd254c64781c | | | | 0e556433bdf", |
| | | | | "ip_address": |
| | | | | "12.12.12.1"} |
| f801c87d- | | | fa:16:3e:f0:c | {"subnet_id": |
| 7f77-4046 | | | 5:09 | "206ce64b- |
| -a5ec- | | | | bd9b-4fc0 |
| a8037296650b | | | | -af2c-24ddb44 |
| | | | | fd9cc", |
| | | | | "ip_address": |
| | | | | "192.168.11.1 |
| | | | | 10"} |
+---------------+------+---------------+---------------+---------------+

[root@ren3 ~]# ping -c 4 192.168.11.110
PING 192.168.11.110 (192.168.11.110) 56(84) bytes of data.
64 bytes from 192.168.11.110: icmp_seq=1 ttl=64 time=0.834 ms
64 bytes from 192.168.11.110: icmp_seq=2 ttl=64 time=0.265 ms
64 bytes from 192.168.11.110: icmp_seq=3 ttl=64 time=0.584 ms
64 bytes from 192.168.11.110: icmp_seq=4 ttl=64 time=0.371 ms

--- 192.168.11.110 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 0.265/0.513/0.834/0.218 ms

4、图形化界面创建

二、创建m1.nano flavor

  创建最小的实例类型,每个实例512 MB内存,1G的磁盘容量。

[root@ren3 ~]# openstack flavor create --id 0 --vcpus 1 --ram 512 --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 | 512 |
| 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 | 512 | 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 |
+-------------------------+------------------+-------------------------+
| 062d2b07-339e-4d54 | my_network | 54175b19-fada-4875 |
| -aaca-6b9169d17f6c | | -b00c-20e556433bdf |
| d97c8576-1990-4920 | external_network | 206ce64b-bd9b-4fc0 |
| -adea-98589cc816ab | | -af2c-24ddb44fd9cc |
+-------------------------+------------------+-------------------------+
[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=062d2b07-339e-4d54-aaca-6b9169d17f6c --security-group lamp --key-name my_key lamp_instance1
+----------------------------------+-----------------------------------+
| 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 | o7orb7LwP2sC |
| config_drive | |
| created | 2019-10-17T08:04:47Z |
| flavor | low_level (0) |
| hostId | |
| id | ce360d28-28e2-4344-a9f2-4dd228ead |
| | d4a |
| image | cirros (d8e9a113-edef- |
| | 41a6-9778-622edf76de39) |
| key_name | my_key |
| name | lamp_instance1 |
| progress | 0 |
| project_id | 640da7a471524d35a3efca2692b9555a |
| properties | |
| security_groups | name='lamp' |
| status | BUILD |
| updated | 2019-10-17T08:04:47Z |
| user_id | 372fccfd264c4edfb600af3f56052ec7 |
| volumes_attached | |
+----------------------------------+-----------------------------------+
[root@ren3 ~]# openstack server list
+---------------+---------------+--------+----------------+------------+
| ID | Name | Status | Networks | Image Name |
+---------------+---------------+--------+----------------+------------+
| ce360d28-28e2 | lamp_instance | ACTIVE | my_network=12. | cirros |
| -4344-a9f2-4d | 1 | | 12.12.14 | |
| d228eadd4a | | | | |
+---------------+---------------+--------+----------------+------------+

通过实例控制台登录实例虚拟机中,测试网关是否能ping通:

在图像化界面创建实例有两种方式:

(1)不创建新卷(虚机的disk文件保存在计算节点的/var/lib/nova/instances/INSTANCE_ID/)

[root@ren4 instances]# pwd
/var/lib/nova/instances
[root@ren4 instances]# ls
ae4ac65d-8708-4589-8b1c-24b67a533495 compute_nodes
_base locks
ce360d28-28e2-4344-a9f2-4dd228eadd4a
[root@ren4 instances]# cd ce360d28-28e2-4344-a9f2-4dd228eadd4a/
[root@ren4 ce360d28-28e2-4344-a9f2-4dd228eadd4a]# ls
console.log disk disk.info
[root@ren4 ce360d28-28e2-4344-a9f2-4dd228eadd4a]# cd ../ae4ac65d-8708-4589-8b1c-24b67a533495/
[root@ren4 ae4ac65d-8708-4589-8b1c-24b67a533495]# ls
console.log

(2)创建新卷(虚机的disk文件保存在存储节点的/dev/cinder-volumes/)

[root@ren5 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─cinder--volumes-volume--644b94e9--416b--4c2c--9606--06dba5f474cc
253:2 0 1G 0 lvm
└─cinder--volumes-volume--c7c70c30--fab3--424f--be37--70b71e5feb73
253:3 0 1G 0 lvm
sr0 11:0 1 4.3G 0 rom
[root@ren5 ~]# cd /dev/cinder-volumes/
[root@ren5 cinder-volumes]# ls
volume-644b94e9-416b-4c2c-9606-06dba5f474cc
volume-c7c70c30-fab3-424f-be37-70b71e5feb73

查看创建好的虚机的命令:

[root@ren3 ~]# nova list
+--------------------------------------+----------------+--------+------------+-------------+----------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+----------------------------------------+
| ae4ac65d-8708-4589-8b1c-24b67a533495 | VM1 | ACTIVE | - | Running | my_network=12.12.12.17 |
| ce360d28-28e2-4344-a9f2-4dd228eadd4a | lamp_instance1 | ACTIVE | - | Running | my_network=12.12.12.14, 192.168.11.109 |
+--------------------------------------+----------------+--------+------------+-------------+----------------------------------------+
[root@ren3 ~]# nova list --all-t +--------------------------------------+----------------+----------------------------------+--------+------------+-------------+----------------------------------------+
| ID | Name | Tenant ID | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+----------------------------------+--------+------------+-------------+----------------------------------------+
| ae4ac65d-8708-4589-8b1c-24b67a533495 | VM1 | 640da7a471524d35a3efca2692b9555a | ACTIVE | - | Running | my_network=12.12.12.17 |
| ce360d28-28e2-4344-a9f2-4dd228eadd4a | lamp_instance1 | 640da7a471524d35a3efca2692b9555a | ACTIVE | - | Running | my_network=12.12.12.14, 192.168.11.109 |
+--------------------------------------+----------------+----------------------------------+--------+------------+-------------+----------------------------------------+
[root@ren3 ~]# nova show VM1
+--------------------------------------+---------------------------------------------------------------------------------+
| Property | Value |
+--------------------------------------+---------------------------------------------------------------------------------+
| OS-DCF:diskConfig | AUTO |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | ren4 |
| OS-EXT-SRV-ATTR:hostname | vm1 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | ren4 |
| OS-EXT-SRV-ATTR:instance_name | instance-00000004 |
| OS-EXT-SRV-ATTR:kernel_id | |
| OS-EXT-SRV-ATTR:launch_index | 0 |
| OS-EXT-SRV-ATTR:ramdisk_id | |
| OS-EXT-SRV-ATTR:reservation_id | r-yxe062h3 |
| OS-EXT-SRV-ATTR:root_device_name | /dev/vda |
| OS-EXT-SRV-ATTR:user_data | - |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | - |
| OS-EXT-STS:vm_state | active |
| OS-SRV-USG:launched_at | 2019-10-18T07:06:16.000000 |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2019-10-18T07:05:37Z |
| description | VM1 |
| flavor | low_level (0) |
| hostId | 09214e8bcdc8938ab43f6fa21e94c12b547bba66fe6d6a08780d5914 |
| host_status | UP |
| id | ae4ac65d-8708-4589-8b1c-24b67a533495 |
| image | Attempt to boot from volume - no image supplied |
| key_name | - |
| locked | False |
| metadata | {} |
| my_network network | 12.12.12.17 |
| name | VM1 |
| os-extended-volumes:volumes_attached | [{"id": "c7c70c30-fab3-424f-be37-70b71e5feb73", "delete_on_termination": true}] |
| progress | 0 |
| security_groups | lamp |
| status | ACTIVE |
| tags | [] |
| tenant_id | 640da7a471524d35a3efca2692b9555a |
| updated | 2019-10-18T07:29:36Z |
| user_id | 372fccfd264c4edfb600af3f56052ec7 |
+--------------------------------------+---------------------------------------------------------------------------------+

2、使用虚拟控制台访问实例

[root@ren3 ~]# openstack console url show lamp_instance1
+-------+--------------------------------------------------------------+
| Field | Value |
+-------+--------------------------------------------------------------+
| type | novnc |
| url | http://192.168.11.3:6080/vnc_auto.html?token=e2b3be5b-ae4d- |
| | 48e8-be86-400c1bb467ef |
+-------+--------------------------------------------------------------+

3、远程访问实例(创建浮点ip并添加至实例1)

[root@ren3 ~]# openstack floating ip create external_network
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| created_at | 2019-10-17T11:44:40Z |
| description | |
| fixed_ip_address | None |
| floating_ip_address | 192.168.11.109 |
| floating_network_id | d97c8576-1990-4920-adea-98589cc816ab |
| id | 4407b6d6-ae73-46b6-8aec-8fdf65be5035 |
| name | None |
| port_id | None |
| project_id | 640da7a471524d35a3efca2692b9555a |
| revision_number | 1 |
| router_id | None |
| status | DOWN |
| updated_at | 2019-10-17T11:44:40Z |
+---------------------+--------------------------------------+
[root@ren3 ~]# openstack server add floating ip lamp_instance1 192.168.11.109

查看是否添加了浮点ip:

[root@ren3 ~]# openstack server list
+---------------+---------------+--------+----------------+------------+
| ID | Name | Status | Networks | Image Name |
+---------------+---------------+--------+----------------+------------+
| ce360d28-28e2 | lamp_instance | ACTIVE | my_network=12. | cirros |
| -4344-a9f2-4d | 1 | | 12.12.14, | |
| d228eadd4a | | | 192.168.11.109 | |
+---------------+---------------+--------+----------------+------------+

测试浮点ip是否通:

[root@ren3 ~]# ping -c 4 192.168.11.109
PING 192.168.11.109 (192.168.11.109) 56(84) bytes of data.
64 bytes from 192.168.11.109: icmp_seq=1 ttl=63 time=6.52 ms
64 bytes from 192.168.11.109: icmp_seq=2 ttl=63 time=1.65 ms
64 bytes from 192.168.11.109: icmp_seq=3 ttl=63 time=2.70 ms
64 bytes from 192.168.11.109: icmp_seq=4 ttl=63 time=2.50 ms

--- 192.168.11.109 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3008ms
rtt min/avg/max/mdev = 1.656/3.348/6.529/1.878 ms

通过ssh远程连接实例1:

[root@ren3 ~]# ssh cirros@192.168.11.109
The authenticity of host '192.168.11.109 (192.168.11.109)' can't be established.
RSA key fingerprint is SHA256:JK9leF3dSxiLvAdDFStoiEuJ9yQ5A0lAoHx1O4rznoM.
RSA key fingerprint is MD5:41:a8:1f:31:04:c6:24:c4:b0:35:c1:a7:4b:59:35:b9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.11.109' (RSA) to the list of known hosts.
$
$ ip a
1: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1450 qdisc pfifo_fast qlen 1000
link/ether fa:16:3e:34:6a:2d brd ff:ff:ff:ff:ff:ff
inet 12.12.12.14/24 brd 12.12.12.255 scope global eth0
inet6 fe80::f816:3eff:fe34:6a2d/64 scope link
valid_lft forever preferred_lft forever
$ exit
Connection to 192.168.11.109 closed.

如果创建了多台虚机,可使用一台有浮动ip的虚机作为其他虚机的跳板机,来远程控制(虚机之间可以互相通信,就不用再给其它虚机添加浮动ip,可以节省外网ip资源)

[root@ren3 ~]# ssh cirros@192.168.11.109
$
$ ip a
1: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1450 qdisc pfifo_fast qlen 1000
link/ether fa:16:3e:34:6a:2d brd ff:ff:ff:ff:ff:ff
inet 12.12.12.14/24 brd 12.12.12.255 scope global eth0
inet6 fe80::f816:3eff:fe34:6a2d/64 scope link
valid_lft forever preferred_lft forever
$
$ ping 12.12.12.17
PING 12.12.12.17 (12.12.12.17): 56 data bytes
64 bytes from 12.12.12.17: seq=0 ttl=64 time=8.151 ms
64 bytes from 12.12.12.17: seq=1 ttl=64 time=3.266 ms
^C
--- 12.12.12.17 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 3.266/5.708/8.151 ms
$
$ ssh cirros@12.12.12.17

Host '12.12.12.17' is not in the trusted hosts file.
(fingerprint md5 0f:fe:c4:7d:95:a3:25:af:29:ac:33:c7:a2:d5:1b:87)
Do you want to continue connecting? (y/n) y
cirros@12.12.12.17's password:
$
$ ip a
1: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1450 qdisc pfifo_fast qlen 1000
link/ether fa:16:3e:5b:6f:93 brd ff:ff:ff:ff:ff:ff
inet 12.12.12.17/24 brd 12.12.12.255 scope global eth0
inet6 fe80::f816:3eff:fe5b:6f93/64 scope link
valid_lft forever preferred_lft forever
$ exit
$ exit
Connection to 192.168.11.109 closed.

六、创建块存储

1、创建卷

[root@ren3 ~]# . openrc
[root@ren3 ~]# openstack volume list

[root@ren3 ~]# openstack volume create --size 1 volume1
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2019-10-18T06:42:28.402838 |
| description | None |
| encrypted | False |
| id | 644b94e9-416b-4c2c-9606-06dba5f474cc |
| 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 |
+------------------+--------------+-----------+------+-------------+
| 644b94e9-416b-4c | volume1 | available | 1 | |
| 2c-9606-06dba5f4 | | | | |
| 74cc | | | | |
+------------------+--------------+-----------+------+-------------+

2、将该卷添加到一个实例

[root@ren3 ~]# openstack server list
+---------------+---------------+--------+----------------+------------+
| ID | Name | Status | Networks | Image Name |
+---------------+---------------+--------+----------------+------------+
| ce360d28-28e2 | lamp_instance | ACTIVE | my_network=12. | cirros |
| -4344-a9f2-4d | 1 | | 12.12.14, | |
| d228eadd4a | | | 192.168.11.109 | |
+---------------+---------------+--------+----------------+------------+
[root@ren3 ~]# openstack server add volume lamp_instance1 volume1
[root@ren3 ~]# openstack volume list
+------------------+--------------+-----------+------+-------------+
| ID | Display Name | Status | Size | Attached to |
+------------------+--------------+-----------+------+-------------+
| 644b94e9-416b-4c | volume1 | attaching | 1 | |
| 2c-9606-06dba5f4 | | | | |
| 74cc | | | | |
+------------------+--------------+-----------+------+-------------+

[root@ren3 ~]# openstack volume list
+-----------------+--------------+--------+------+------------------+
| ID | Display Name | Status | Size | Attached to |
+-----------------+--------------+--------+------+------------------+
| 644b94e9-416b-4 | volume1 | in-use | 1 | Attached to |
| c2c-9606-06dba5 | | | | lamp_instance1 |
| f474cc | | | | on /dev/vdb |
+-----------------+--------------+--------+------+------------------+