openstack nova 实验笔记

创建flavor

(openstack) flavor create test1.tiny --vcpu 1 --ram 512 --disk 1 --id 100
+----------------------------+------------+
| Field | Value |
+----------------------------+------------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | 0 |
| disk | 1 |
| id | 100 |
| name | test1.tiny |
| os-flavor-access:is_public | True |
| properties | |
| ram | 512 |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | 1 |
+----------------------------+------------+
(openstack)

列出虚拟机规格


(openstack) flavor list
+--------------------------------------+------------+------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+------------+------+------+-----------+-------+-----------+
| 01e5f6fc-adbb-440a-817b-71ccbf2b9296 | gao-tiny-1 | 2048 | 8 | 0 | 2 | True |
| 100 | test1.tiny | 512 | 1 | 0 | 1 | True |
| be0f474d-1474-4b42-adaa-6d29da1346ea | lisa-1 | 2048 | 10 | 0 | 2 | True |
+--------------------------------------+------------+------+------+-----------+-------+-----------+
(openstack)

创建密钥对

root@controller:/home/coa# openstack keypair create demo-kp2 > demo-keypair2.pem
root@controller:/home/coa# chmod 600 demo-keypair2.pem
root@controller:/home/coa# openstack keypair list
+----------+-------------------------------------------------+
| Name | Fingerprint |
+----------+-------------------------------------------------+
| demo-kp2 | 84:5e:29:bc:38:1d:89:7f:98:7b:92:00:c4:e4:46:1f |
| testkpr1 | ab:bd:18:3b:d3:ee:cb:07:3a:b4:82:4c:31:5c:68:27 |
+----------+-------------------------------------------------+
root@controller:/home/coa# openstack keypair show demo-kp2 --public-key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEJ4Lsv9UmjDYWSHy/UbUj8zzIovCzoZGFfRvGlQyZTUKItUBQkDuL4cCQ/i9Q2vQpxOPO6HR9V6yRSNbzkJp9rANjBHmgbbbVSA6TFiEWM2+gYUIcL1RIcgD8Kq2ESi2fainlZlyslBpJeRxCuDS4EiJc3TINGKZljJfFX1R5M5QdYIK68H/fOxNOM7Jj0YoOonPD02yi9qd/ijlNs78NR7cE3KvikrwpP42r+k7Q9PpGnszM1ku1pHQqlDn5C5/c8FJwG56IVkTCSvM5EoBXx9ly4nspfCSIBuLeCfnm2SyHnpDybY4SDjZTZtIdWJ1G0iLTcaz9YZ7vxRn9vhnV Generated-by-Nova
root@controller:/home/coa# more demo-openrc
export OS_USERNAME=demo
export OS_PASSWORD=openstack
export OS_PROJECT_NAME=demo
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://controller:35357/v3
export OS_IDENTITY_API_VERSION=3
root@controller:/home/coa#

创建虚拟机

root@controller:/home/coa# openstack server create demo-vm1 --image cirros --flavor test1.tiny --security-group ssh-sg --key-name demo-kp2 --network provider1
+-----------------------------+-----------------------------------------------+
| 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 | dAZaAP7J7fKh |
| config_drive | |
| created | 2023-03-29T23:21:07Z |
| flavor | test1.tiny (100) |
| hostId | |
| id | d9e68130-38e5-4e1e-93e0-6f5b3c586622 |
| image | cirros (6ce19470-788e-489a-86ce-eb4653b150c6) |
| key_name | demo-kp2 |
| name | demo-vm1 |
| progress | 0 |
| project_id | 9b3921e153764a7f8dcdcf9f2866f440 |
| properties | |
| security_groups | name='813e2699-027f-4112-a888-dda789b78c6c' |
| status | BUILD |
| updated | 2023-03-29T23:21:07Z |
| user_id | 9fc44367471747f2b1bca71b2095c4e3 |
| volumes_attached | |
+-----------------------------+-----------------------------------------------+
root@controller:/home/coa#

获取vnc的url,登信息录后查看公钥

root@controller:/home/coa# openstack console url show demo-vm1
+-------+---------------------------------------------------------------------------------+
| Field | Value |
+-------+---------------------------------------------------------------------------------+
| type | novnc |
| url | http://controller:6080/vnc_auto.html?token=c747a0eb-fda0-47eb-b908-bed76d4d1190 |
+-------+---------------------------------------------------------------------------------+
root@controller:/home/coa#

ls -al #查看是否存在.ssh目录
cat .ssh/authorized_keys #查看公钥信息


root@controller:/home/coa# openstack network list
+--------------------------------------+-----------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+-----------+--------------------------------------+
| 65a6c126-7da1-4f8f-b584-b86eb8ac9d5f | provider1 | d4190362-65a2-45ae-a959-bd072fbfdeeb |
| df2aba20-e6b7-47f0-a8fe-c548a46c1d2e | gao-net0 | 4827ce2a-aedd-483a-bdbe-5d134690c85c |
+--------------------------------------+-----------+--------------------------------------+
root@controller:/home/coa# ip netns
qdhcp-fdd8e609-894c-4b4f-9d3a-2e8f6212db74
qdhcp-fd2db93a-43eb-45d3-bb38-c270b674f79b
qdhcp-df2aba20-e6b7-47f0-a8fe-c548a46c1d2e
qdhcp-d8d1e237-4847-42b7-8539-1c113f5ead68
qdhcp-adbc3993-bb5f-45ad-b285-675300f196b8
qdhcp-80965a97-f254-42e2-aaa6-a00db081654d
qdhcp-6d784bc2-a867-429d-bb9d-2858426769a4
qdhcp-58e9c3e7-e536-42a5-b75c-0566e50137aa
qdhcp-65a6c126-7da1-4f8f-b584-b86eb8ac9d5f ***** 与 provider1的id一致
qdhcp-2e4a1ff7-2044-41a6-8883-8124301177f9
qdhcp-1166a203-aeea-4984-91fd-f5215ac119d5
qrouter-dcdff98a-3c63-4700-aa64-eff7d17199d3
qrouter-e4eca3ac-d8bf-4084-bbc0-04b4896220ab
qrouter-babfd713-f2ac-4410-bb01-f4b6f754681c
qrouter-c1d13cb0-f0fb-4af3-a811-0c1a401a8d60
qrouter-aa7ecaac-f5d1-4745-8ddc-46d59c447bf4
qrouter-7ee72b89-7c51-47eb-8311-3e3d5b71ad60
qrouter-321e9357-1ca9-473e-8f68-1f9da863d667
qrouter-aa70cb88-d65f-4017-942e-8d9c14a7ca7c
root@controller:/home/coa#


利用秘钥文件登录虚拟机

root@controller:/home/coa# sudo ip netns exec qdhcp-65a6c126-7da1-4f8f-b584-b86eb8ac9d5f bash
root@controller:/home/coa# su - coa
coa@controller:~$ ssh -i demo-keypair2.pem cirros@x.x.x.x
coa@controller:~$

创建快照

coa@controller:~$ . demo-openrc
coa@controller:~$ openstack server image create demo-vm1 --name demo-snap1
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | None |
| container_format | None |
| created_at | 2023-03-29T23:41:37Z |
| disk_format | None |
| file | /v2/images/2ddb87bf-6f22-498f-93da-04429bea7f9d/file |
| id | 2ddb87bf-6f22-498f-93da-04429bea7f9d |
| min_disk | 1 |
| min_ram | 0 |
| name | demo-snap1 |
| owner | 9b3921e153764a7f8dcdcf9f2866f440 |
| properties | base_image_ref='6ce19470-788e-489a-86ce-eb4653b150c6', boot_roles='user,heat_stack_owner', image_type='snapshot', instance_uuid='d9e68130-38e5-4e1e-93e0-6f5b3c586622', owner_project_name='demo', owner_user_name='demo', user_id='9fc44367471747f2b1bca71b2095c4e3' |
| protected | False |
| schema | /v2/schemas/image |
| size | None |
| status | queued |
| tags | |
| updated_at | 2023-03-29T23:41:37Z |
| virtual_size | None |
| visibility | private |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
coa@controller:~$ openstack image list
+--------------------------------------+---------------+--------+
| ID | Name | Status |
+--------------------------------------+---------------+--------+
| 6ce19470-788e-489a-86ce-eb4653b150c6 | cirros | active |
| a2111fe2-db3a-490a-9fb3-69195025a60a | dbserver-3.50 | active |
| 2ddb87bf-6f22-498f-93da-04429bea7f9d | demo-snap1 | active | ***创建的快照
| 7b88591b-93e7-451c-a66f-3b955d16041c | gao-db3.5 | active |
| c38f4015-230f-4a39-ac91-0f8ef34c88d2 | gao-glance | active |
| 6c00a4a2-ae5e-45f9-9ac9-104738ec51b8 | webserver-3.6 | active |
+--------------------------------------+---------------+--------+
coa@controller:~$


利用快照创建虚拟机
coa@controller:~$ openstack server create demo-snap-vm1 --image demo-snap1 --flavor test1.tiny --security-group ssh-sg --key-name demo-kp2 --network provider1
+-----------------------------+---------------------------------------------------+
| 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 | CekvoK7kDcvU |
| config_drive | |
| created | 2023-03-29T23:46:50Z |
| flavor | test1.tiny (100) |
| hostId | |
| id | 39adfc7e-18b3-46a2-9711-decb839bdf11 |
| image | demo-snap1 (2ddb87bf-6f22-498f-93da-04429bea7f9d) |
| key_name | demo-kp2 |
| name | demo-snap-vm1 |
| progress | 0 |
| project_id | 9b3921e153764a7f8dcdcf9f2866f440 |
| properties | |
| security_groups | name='813e2699-027f-4112-a888-dda789b78c6c' |
| status | BUILD |
| updated | 2023-03-29T23:46:50Z |
| user_id | 9fc44367471747f2b1bca71b2095c4e3 |
| volumes_attached | |
+-----------------------------+---------------------------------------------------+
coa@controller:~$
以上创建快照提示error Error: Failed to perform requested operation on instance "demo-snap-vm1", the instance has an error status: Please try again later [Error: No valid host was found. ].
一般[Error: No valid host was found. ].是资源不足造成,需要删除垃圾数据腾空资源

修改缺省的资源

root@controller:/home/coa# . admin-openrc
root@controller:/home/coa# openstack quota show --default
+-----------------------+-------+
| Field | Value |
+-----------------------+-------+
| backup-gigabytes | 1000 |
| backups | 10 |
| cores | 16 |
| fixed-ips | -1 |
| floating-ips | 50 |
| gigabytes | 1000 |
| gigabytes_epc-lvm-1 | -1 |
| gigabytes_gao-volumes | -1 |
| gigabytes_luks | -1 |
| gigabytes_luks-cli | -1 |
| gigabytes_lvm | -1 |
| gigabytes_testLUKS | -1 |
| groups | 10 |
| health_monitors | None |
| injected-file-size | 10240 |
| injected-files | 5 |
| injected-path-size | 255 |
| instances | 10 |
| key-pairs | 100 |
| l7_policies | None |
| listeners | None |
| load_balancers | None |
| location | None |
| name | None |
| networks | 100 |
| per-volume-gigabytes | -1 |
| pools | None |
| ports | 500 |
| project | None |
| project_name | admin |
| properties | 128 |
| ram | 40960 |
| rbac_policies | 10 |
| routers | 10 |
| secgroup-rules | 100 |
| secgroups | 10 |
| server-group-members | 10 |
| server-groups | 10 |
| snapshots | 20 |
| snapshots_epc-lvm-1 | -1 |
| snapshots_gao-volumes | -1 |
| snapshots_luks | -1 |
| snapshots_luks-cli | -1 |
| snapshots_lvm | -1 |
| snapshots_testLUKS | -1 |
| subnet_pools | -1 |
| subnets | 100 |
| volumes | 10 |
| volumes_epc-lvm-1 | -1 |
| volumes_gao-volumes | -1 |
| volumes_luks | -1 |
| volumes_luks-cli | -1 |
| volumes_lvm | -1 |
| volumes_testLUKS | -1 |
+-----------------------+-------+
root@controller:/home/coa#
root@controller:/home/coa# openstack quota set default --class --instance 20 --volumes 20 --cores 20
root@controller:/home/coa#

 

posted @ 2023-04-03 17:53  Ratooner  阅读(79)  评论(0编辑  收藏  举报