openstack创建实例测试步骤

时间:2022-09-16 19:41:40

source admin-openrc.sh
keystone user-create --name=demo --pass=123456
keystone tenant-create --name=demo --description="Demo Tenant"
keystone user-role-add --user=demo --role=_member_ --tenant=demo

source demo-openrc.sh
ssh-keygen
nova keypair-add --pub-key ~/.ssh/id_rsa.pub demo-key
neutron net-create demo-net
(若指定VLAN,需管理员,且设置为共享,命令为:)
neutron net-create VLAN550 --router:external False --provider:network_type vlan --provider:physical_network physnet2 --provider:segmentation_id 550 --shared
neutron subnet-create demo-net --name demo-subnet --gateway 192.168.1.1 192.168.1.0/24
neutron router-create demo-router
neutron router-interface-add demo-router demo-subnet
neutron net-list
+--------------------------------------+-----------+-----------------------------------------------------+
| id                                   | name      | subnets                                             |
+--------------------------------------+-----------+-----------------------------------------------------+
| fd39c0bb-f3f5-45dc-8f61-0b516114731f | demo-net  | fb8687e8-1d64-4ed1-afc3-955454090682 192.168.1.0/24 |
| f3376efe-2024-4fa8-9cd5-0c10f2174655 | net04_ext | b39c4183-fe7e-4c71-b934-539a469691f2                |
+--------------------------------------+-----------+-----------------------------------------------------+
neutron router-gateway-set demo-router net04_ext
nova boot --flavor m1.tiny --image cirros-0.3.0-x86_64-disk --nic net-id=fd39c0bb-f3f5-45dc-8f61-0b516114731f --security-group default --key-name demo-key demo-instance1
nova list
+--------------------------------------+----------------+--------+------------+-------------+----------+
| ID                                   | Name           | Status | Task State | Power State | Networks |
+--------------------------------------+----------------+--------+------------+-------------+----------+
| 8423000d-56be-41ff-8a5b-bcf5c5472cf6 | demo-instance1 | BUILD  | spawning   | NOSTATE     |          |
+--------------------------------------+----------------+--------+------------+-------------+----------+

nova show 8423000d-56be-41ff-8a5b-bcf5c5472cf6
+--------------------------------------+-----------------------------------------------------------------+
| Property                             | Value                                                           |
+--------------------------------------+-----------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                          |
| OS-EXT-AZ:availability_zone          | nova                                                            |
| OS-EXT-STS:power_state               | 1                                                               |
| OS-EXT-STS:task_state                | -                                                               |
| OS-EXT-STS:vm_state                  | active                                                          |
| OS-SRV-USG:launched_at               | 2015-12-30T09:57:16.000000                                      |
| OS-SRV-USG:terminated_at             | -                                                               |
| accessIPv4                           |                                                                 |
| accessIPv6                           |                                                                 |
| config_drive                         |                                                                 |
| created                              | 2015-12-30T09:56:01Z                                            |
| demo-net network                     | 192.168.1.2                                                     |
| flavor                               | m1.tiny (1)                                                     |
| hostId                               | 8bfc62fe3673abca838ee2a0f1eab68b771c1469709a7408c4ff98dd        |
| id                                   | 8423000d-56be-41ff-8a5b-bcf5c5472cf6                            |
| image                                | cirros-0.3.0-x86_64-disk (bafeb4c4-781a-49f7-8c9d-9b9db7604db1) |
| key_name                             | demo-key                                                        |
| metadata                             | {}                                                              |
| name                                 | demo-instance1                                                  |
| os-extended-volumes:volumes_attached | []                                                              |
| progress                             | 0                                                               |
| security_groups                      | default                                                         |
| status                               | ACTIVE                                                          |
| tenant_id                            | e234241403d744dfba9ce21f6371fc0e                                |
| updated                              | 2015-12-30T09:57:17Z                                            |
| user_id                              | db35fe5dcc3049dd9c297a6d37ff5b0d                                |
+--------------------------------------+-----------------------------------------------------------------+

nova get-vnc-console demo-instance1 novnc
+-------+----------------------------------------------------------------------------------+
| Type  | Url                                                                              |
+-------+----------------------------------------------------------------------------------+
| novnc | http://168.1.22.30:6080/vnc_auto.html?token=ba5ee3f7-56d2-4113-8b66-b356201dbef6 |
+-------+----------------------------------------------------------------------------------+

ping 192.168.1.1

ping 218.85.157.99

openstack创建实例测试步骤

测试分配浮动IP:

nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range  | Source Group |
+-------------+-----------+---------+-----------+--------------+
| icmp        | -1        | -1      | 0.0.0.0/0 |              |
+-------------+-----------+---------+-----------+--------------+

nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
+-------------+-----------+---------+-----------+--------------+
| IP Protocol | From Port | To Port | IP Range  | Source Group |
+-------------+-----------+---------+-----------+--------------+
| tcp         | 22        | 22      | 0.0.0.0/0 |              |
+-------------+-----------+---------+-----------+--------------+

neutron floatingip-create net04_ext
Created a new floatingip:
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    |                                      |
| floating_ip_address | 168.1.22.42                          |
| floating_network_id | f3376efe-2024-4fa8-9cd5-0c10f2174655 |
| id                  | 8a11d12c-50be-4f61-9721-b9aacf92f496 |
| port_id             |                                      |
| router_id           |                                      |
| status              | DOWN                                 |
| tenant_id           | e234241403d744dfba9ce21f6371fc0e     |
+---------------------+--------------------------------------+

nova floating-ip-associate demo-instance1 168.1.22.42
nova list
+--------------------------------------+----------------+--------+------------+-------------+-----------------------------------+
| ID                                   | Name           | Status | Task State | Power State | Networks                          |
+--------------------------------------+----------------+--------+------------+-------------+-----------------------------------+
| 8423000d-56be-41ff-8a5b-bcf5c5472cf6 | demo-instance1 | ACTIVE | -          | Running     | demo-net=192.168.1.2, 168.1.22.42 |
+--------------------------------------+----------------+--------+------------+-------------+-----------------------------------+

C:\>ping 168.1.22.42

正在 Ping 168.1.22.42 具有 32 字节的数据:
来自 168.1.22.42 的回复: 字节=32 时间=3ms TTL=62
来自 168.1.22.42 的回复: 字节=32 时间=1ms TTL=62

ssh 168.1.22.42

创建卷并分配卷:
cinder create --display-name demo-volume1 1
nova volume-list
+--------------------------------------+-----------+--------------+------+-------------+-------------+
| ID                                   | Status    | Display Name | Size | Volume Type | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+-------------+
| ae0fe7e4-8db6-4b95-b2ae-f98c7ebca920 | available | demo-volume1 | 1    | None        |             |
+--------------------------------------+-----------+--------------+------+-------------+-------------+
nova volume-attach demo-instance1 ae0fe7e4-8db6-4b95-b2ae-f98c7ebca920

ssh 168.1.22.42
login as: root
root@168.1.22.42's password:
# fdisk -l

Disk /dev/vda: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *       16065     2088449     1036192+  83  Linux

Disk /dev/vdb: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table

nova volume-detach demo-instance1 ae0fe7e4-8db6-4b95-b2ae-f98c7ebca920

# fdisk -l

Disk /dev/vda: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *       16065     2088449     1036192+  83  Linux