OpenStack(1) - create an instance

Table of contents

1. Upload the image

1.1 Create a new directory

1.2 Upload to glance

1.3 View mirror image

2. Create a new instance

2.1 Get the secret key

2.2 Create a new instance

2.3 Create a new instance admin-vm

2.4 Get the url of VNC instance

2.5 nova common commands


1. Upload the image

1.1 Create a new directory

Upload the Linux test image named cirros-0.3.4-x86_64-disk.img. The cirros image is usually used for testing, and the size is only 12M, which is convenient for testing.

Create a new directory for storing images. Here, if wget fails, you need to use xftp to transfer to the virtual machine /opt/images directory after the host computer downloads.

source /root/keystonerc_admin

mkdir /opt/images
cd /opt/images
wget https://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

1.2 Upload to glance

 Upload to the glance service, glance image-create --name cirros-0.3.4-x86_64 --disk-format qcow2 --container-format bare --file /opt/images/cirros-0.3.4-x86_64-disk.img --visibility public --progress

 Command explanation:

--name image name

--disk-format mirror disk format, support: ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso format

--container-format image container format, support: ami, ari, aki, bare, ovf format

--file mirror path

--visibility Whether the image can be accessed by the public, set it as a public image here

--progress show upload progress bar

[root@openstack images(keystone_admin)]# glance image-create --name cirros-0.3.4-x86_64 --disk-format qcow2 --container-format bare --file /opt/images/cirros-0.3.4-x86_64-disk.img  --visibility public --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2023-06-07T13:38:26Z                 |
| disk_format      | qcow2                                |
| id               | 041c0a42-adc2-4694-b932-7f01ae198919 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros-0.3.4-x86_64                  |
| owner            | 5de5c5079f4147a69f330e9ce20c7f1b     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2023-06-07T13:38:26Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+

1.3 View mirror image

Use glance image-list to view the image list or view it through the dashboard, and the upload of glance is successful. Do not use nova image-list, this command is deprecated.

[root@openstack ~(keystone_admin)]# glance image-list
+--------------------------------------+---------------------+
| ID                                   | Name                |
+--------------------------------------+---------------------+
| 5955b3dc-00b3-4dec-b21a-a9605275faf2 | cirros              |
| 041c0a42-adc2-4694-b932-7f01ae198919 | cirros-0.3.4-x86_64 |
+--------------------------------------+---------------------+

Before creating an instance, you must specify the instance type, image name, network, security group, key, and instance name

View the available instance types nova flavor-list , there are five types by default

[root@openstack ~(keystone_admin)]# nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public | Description |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+
| 1  | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      | -           |
| 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      | -           |
| 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      | -           |
| 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      | -           |
| 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      | -           |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+-------------+

View the available network neutron net-list, the default is a public network, an internal network, and an external network means sharing the network with other projects.

[root@openstack ~(keystone_admin)]# neutron net-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+
| id                                   | name    | tenant_id                        | subnets                                            |
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+
| 39bf56a4-68a8-4f9c-af56-b7bf788a5c45 | public  | 5de5c5079f4147a69f330e9ce20c7f1b | 4bdac25f-a68e-4ef5-b638-c7f9500957ce 172.24.4.0/24 |
| 639cf33e-3ced-45a7-9d1e-542cd5aec015 | private | 2e506aef614242ee8f5fe824fdf74226 | 2034ab92-5372-47f5-89b0-88d17f9b26d2 10.0.0.0/24   |
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+

Check the security group openstack security group list, do not use nova secgroup-list, this command is deprecated.

[root@openstack images(keystone_admin)]# openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID                                   | Name    | Description            | Project                          |
+--------------------------------------+---------+------------------------+----------------------------------+
| 18102e48-6a05-4901-ae9e-a0d43647a9f3 | default | Default security group |                                  |
| ec20a954-0572-428f-87a3-4916318fcadc | default | Default security group | 2e506aef614242ee8f5fe824fdf74226 |
| f18bcb15-5573-4dd1-8de5-c201b5472ceb | default | Default security group | 5de5c5079f4147a69f330e9ce20c7f1b |
+--------------------------------------+---------+------------------------+----------------------------------+

2. Create a new instance

2.1 Get the secret key

 Obtain the key admin-key, and restart the virtual machine after obtaining the key. The key still exists, and the key is bound to the account.

source /root/keystonerc_admin
nova keypair-add admin-key
openstack keypair list

[root@openstack images(keystone_admin)]# openstack keypair list
+-----------+-------------------------------------------------+
| Name      | Fingerprint                                     |
+-----------+-------------------------------------------------+
| admin-key | c0:83:d6:02:35:39:a9:6e:a0:4e:46:5a:52:af:3d:ec |
+-----------+-------------------------------------------------+

Check the nove list, nova list, there are no examples at this time.

[root@openstack ~(keystone_admin)]# nova list
+----+------+--------+------------+-------------+----------+
| ID | Name | Status | Task State | Power State | Networks |
+----+------+--------+------------+-------------+----------+
+----+------+--------+------------+-------------+----------+

2.2 Create a new instance

Check the network id, here I am using the public network, copy the id number 39bf56a4-68a8-4f9c-af56-b7bf788a5c45 in advance.

[root@openstack ~(keystone_admin)]# neutron net-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+
| id                                   | name    | tenant_id                        | subnets                                            |
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+
| 39bf56a4-68a8-4f9c-af56-b7bf788a5c45 | public  | 5de5c5079f4147a69f330e9ce20c7f1b | 4bdac25f-a68e-4ef5-b638-c7f9500957ce 172.24.4.0/24 |
| 639cf33e-3ced-45a7-9d1e-542cd5aec015 | private | 2e506aef614242ee8f5fe824fdf74226 | 2034ab92-5372-47f5-89b0-88d17f9b26d2 10.0.0.0/24   |
+--------------------------------------+---------+----------------------------------+----------------------------------------------------+

2.3 Create a new instance admin-vm

nova boot --flavor m1.tiny --image cirros-0.3.4-x86_64 --nic net-id=39bf56a4-68a8-4f9c-af56-b7bf788a5c45 --security-group default --key-name admin-key admin-vm

Command explanation:

--flavor instance type

--image image name, must be uploaded to the glance service first, view the image list through glance image-list

--nic use the network, net-id= fill in the network id number

-security-group security group

--key-name select key

admin-vm instance name, can be chosen at will

[root@openstack images(keystone_admin)]# nova boot --flavor m1.tiny --image cirros-0.3.4-x86_64 --nic net-id=39bf56a4-68a8-4f9c-af56-b7bf788a5c45 --security-group default --key-name admin-key admin-vm
+--------------------------------------+------------------------------------------------------------+
| Property                             | Value                                                      |
+--------------------------------------+------------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                                     |
| OS-EXT-AZ:availability_zone          |                                                            |
| OS-EXT-SRV-ATTR:host                 | -                                                          |
| OS-EXT-SRV-ATTR:hostname             | admin-vm                                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                          |
| OS-EXT-SRV-ATTR:instance_name        |                                                            |
| 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-1x8lssuk                                                 |
| OS-EXT-SRV-ATTR:root_device_name     | -                                                          |
| OS-EXT-SRV-ATTR:user_data            | -                                                          |
| OS-EXT-STS:power_state               | 0                                                          |
| OS-EXT-STS:task_state                | scheduling                                                 |
| OS-EXT-STS:vm_state                  | building                                                   |
| OS-SRV-USG:launched_at               | -                                                          |
| OS-SRV-USG:terminated_at             | -                                                          |
| accessIPv4                           |                                                            |
| accessIPv6                           |                                                            |
| adminPass                            | uirGY9o8kaL6                                               |
| config_drive                         |                                                            |
| created                              | 2023-06-07T15:54:32Z                                       |
| description                          | -                                                          |
| flavor:disk                          | 1                                                          |
| flavor:ephemeral                     | 0                                                          |
| flavor:extra_specs                   | {}                                                         |
| flavor:original_name                 | m1.tiny                                                    |
| flavor:ram                           | 512                                                        |
| flavor:swap                          | 0                                                          |
| flavor:vcpus                         | 1                                                          |
| hostId                               |                                                            |
| host_status                          |                                                            |
| id                                   | b5f47588-196a-40d6-a52b-7f2cd371f417                       |
| image                                | cirros-0.3.4-x86_64 (041c0a42-adc2-4694-b932-7f01ae198919) |
| key_name                             | admin-key                                                  |
| locked                               | False                                                      |
| metadata                             | {}                                                         |
| name                                 | admin-vm                                                   |
| os-extended-volumes:volumes_attached | []                                                         |
| progress                             | 0                                                          |
| security_groups                      | default                                                    |
| status                               | BUILD                                                      |
| tags                                 | []                                                         |
| tenant_id                            | 5de5c5079f4147a69f330e9ce20c7f1b                           |
| updated                              | 2023-06-07T15:54:32Z                                       |
| user_id                              | a6ecc9dfabd04180947bfad72c67e5d4                           |
+--------------------------------------+------------------------------------------------------------+

 View the instance list nova list

[root@openstack images(keystone_admin)]# nova list
+--------------------------------------+----------+--------+------------+-------------+--------------------+
| ID                                   | Name     | Status | Task State | Power State | Networks           |
+--------------------------------------+----------+--------+------------+-------------+--------------------+
| b5f47588-196a-40d6-a52b-7f2cd371f417 | admin-vm | ACTIVE | -          | Running     | public=172.24.4.17 |
+--------------------------------------+----------+--------+------------+-------------+--------------------+

 You can also view it through the virsh list

[root@localhost images(keystone_admin)]# virsh list
 Id    Name                           State
----------------------------------------------------
 1     instance-00000001              running

You can also view it through the dashboard 


 

2.4 Get the url of VNC instance

The instance is created successfully, so how to enter the newly created instance? You need to get the url of the VNC of the instance, nova get-vnc-console admin-vm novnc, the url will be refreshed every time you use this command, the old url will become invalid after the url is refreshed, and you need to get the url again after the instance is restarted.

[root@openstack images(keystone_admin)]# nova get-vnc-console admin-vm novnc
+-------+-------------------------------------------------------------------------------------+
| Type  | Url                                                                                 |
+-------+-------------------------------------------------------------------------------------+
| novnc | http://192.168.136.56:6080/vnc_auto.html?token=6d463d80-8e49-4100-8cdf-f10d5fc94af2 |
+-------+-------------------------------------------------------------------------------------+

After getting the url, enter it in the browser to enter a terminal of the instance. After entering, you need to wait for about 5 minutes before "cirrors login:" appears, indicating that the instance has officially started successfully. According to the cirros image, the account name is cirros, and the password is cubswin:).

If there is a Failed connect to server (code: 1006) error

Check to see if the instance is started. The instance status must be ACTIVE. I have encountered the situation that the instance shuts down automatically twice, and finally found that it is caused by insufficient memory. It is recommended that the memory be at least 10G.

If the instance still does not work, add hosts and restart the nova service

vi /etc/hosts
192.168.136.56 openstack  #添加,注意是主机名,如果你的主机名不是openstack,自行更改,保证可以ping通主机名就可以
source /etc/hosts
systemctl restart openstack-nova-compute.service

[root@openstack ~(keystone_admin)]# ping openstack
PING openstack (192.168.136.56) 56(84) bytes of data.
64 bytes from openstack (192.168.136.56): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from openstack (192.168.136.56): icmp_seq=2 ttl=64 time=0.035 ms

In addition to using url to log in, you can also directly control the instance through the "console" of the dashboard .

2.5 nova common commands

nova list #查看虚拟机

nova show [vm-name]或[vm-id]     #查看虚拟机详细信息
nova reboot (--hard) [vm-name]或[vm-id]    #硬重启实例,失败可以添加属性--hard,强制硬重启

nova start [vm-name]或[vm-id]    #启动虚拟机
nova stop [vm-name]或[vm-id]     #关闭虚拟机
nova suspend [vm-name]或[vm-id]  #暂停虚拟机
nova resume [vm-name]或[vm-id]   #启动暂停的虚拟机
nova delete [vm-name]或[vm-id]   #删除虚拟机

openstack compute service list   #查看nova相关服务

Guess you like

Origin blog.csdn.net/weixin_48878440/article/details/131096234