OpenStack手动迁移虚拟机

Posted 人间忽晚,山河以秋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack手动迁移虚拟机相关的知识,希望对你有一定的参考价值。

基于OpenStack平台搭建完成后
迁移的步骤:
1、将关于虚拟机的数据移到目标主机(移动之前需要关闭虚拟机)
在OpenStack里云主机的数据存放目录是/var/lib/nova/instances/
2、修改数据库文件
在nova数据库的instances 表里有记录虚拟机的宿主机的名字,所以需要进入数据库修改该字段为controller

实战;
一、首先创建一个虚拟机
在这里插入图片描述
在管理员的虚拟机管理器界面可以看到虚拟机的主机是compute(我们要把虚拟机从compute节点迁移到controller节点)

在这里插入图片描述
点击云主机的名字可以进入查看云主机的详细信息,可以看到一开始他的主机是compute
在这里插入图片描述

二、开始把数据迁移到controller
云主机关上
在这里插入图片描述
在/var/lib/nova/instances/里,存放着云主机的数据,下面的b5f1929f-e51c-443d-be02-1854e26443cb目录就是我们测试的云主机的id
compute节点:

[root@compute instances]# cd /var/lib/nova/instances/
[root@compute instances]# ll
total 4
drwxr-xr-x. 2 nova nova 69 Jul 16 03:30 b5f1929f-e51c-443d-be02-1854e26443cb
drwxr-xr-x. 2 nova nova 53 Jul 11 18:43 _base
-rw-r--r--. 1 nova nova 30 Jul 16 02:50 compute_nodes
drwxr-xr-x. 2 nova nova 91 Jul 11 18:50 locks

把它复制到controller节点,把本主机的删除

[root@compute instances]# scp -r b5f1929f-e51c-443d-be02-1854e26443cb root@10.30.59.218:/var/lib/nova/instances
root@10.30.59.218's password: 
console.log                                                                                100%   37KB  37.2KB/s   00:00    
disk.info                                                                                  100%   79     0.1KB/s   00:00    
disk                                                                                       100%   14MB  14.0MB/s   00:01    
libvirt.xml 
[root@compute instances]# rm -rf  b5f1929f-e51c-443d-be02-1854e26443cb

controller节点:
把它的用户和用户组修改成nova

[root@controller instances]# ll
total 0
drwxr-xr-x. 2 root root 69 Jul 16 03:35 b5f1929f-e51c-443d-be02-1854e26443cb
[root@controller instances]# chown -R nova:nova b5f1929f-e51c-443d-be02-1854e26443cb/
[root@controller instances]# ll
total 0
drwxr-xr-x. 2 nova nova 69 Jul 16 03:35 b5f1929f-e51c-443d-be02-1854e26443cb

然后修改数据库文件

[root@controller instances]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \\g.
Your MariaDB connection id is 2151
Server version: 10.1.17-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| cinder             |
| glance             |
| information_schema |
| keystone           |
| mysql              |
| neutron            |
| nova               |
| nova_api           |
| performance_schema |
+--------------------+
9 rows in set (0.00 sec)

MariaDB [(none)]> use nova
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [nova]> show tables;
+--------------------------------------------+
| Tables_in_nova                             |
+--------------------------------------------+
| agent_builds                               |
| aggregate_hosts                            |
| aggregate_metadata                         |
| aggregates                                 |
| allocations                                |
| block_device_mapping                       |
| bw_usage_cache                             |
| cells                                      |
| certificates                               |
| compute_nodes                              |
| console_pools                              |
| consoles                                   |
| dns_domains                                |
| fixed_ips                                  |
| floating_ips                               |
| instance_actions                           |
| instance_actions_events                    |
| instance_extra                             |
| instance_faults                            |
| instance_group_member                      |
| instance_group_policy                      |
| instance_groups                            |
| instance_id_mappings                       |
| instance_info_caches                       |
| instance_metadata                          |
| instance_system_metadata                   |
| instance_type_extra_specs                  |
| instance_type_projects                     |
| instance_types                             |
| instances                                  |
| inventories                                |
| key_pairs                                  |
| migrate_version                            |
| migrations                                 |
| networks                                   |
| pci_devices                                |
| project_user_quotas                        |
| provider_fw_rules                          |
| quota_classes                              |
| quota_usages                               |
| quotas                                     |
| reservations                               |
| resource_provider_aggregates               |
| resource_providers                         |
| s3_images                                  |
| security_group_default_rules               |
| security_group_instance_association        |
| security_group_rules                       |
| security_groups                            |
| services                                   |
| shadow_agent_builds                        |
| shadow_aggregate_hosts                     |
| shadow_aggregate_metadata                  |
| shadow_aggregates                          |
| shadow_block_device_mapping                |
| shadow_bw_usage_cache                      |
| shadow_cells                               |
| shadow_certificates                        |
| shadow_compute_nodes                       |
| shadow_console_pools                       |
| shadow_consoles                            |
| shadow_dns_domains                         |
| shadow_fixed_ips                           |
| shadow_floating_ips                        |
| shadow_instance_actions                    |
| shadow_instance_actions_events             |
| shadow_instance_extra                      |
| shadow_instance_faults                     |
| shadow_instance_group_member               |
| shadow_instance_group_policy               |
| shadow_instance_groups                     |
| shadow_instance_id_mappings                |
| shadow_instance_info_caches                |
| shadow_instance_metadata                   |
| shadow_instance_system_metadata            |
| shadow_instance_type_extra_specs           |
| shadow_instance_type_projects              |
| shadow_instance_types                      |
| shadow_instances                           |
| shadow_key_pairs                           |
| shadow_migrate_version                     |
| shadow_migrations                          |
| shadow_networks                            |
| shadow_pci_devices                         |
| shadow_project_user_quotas                 |
| shadow_provider_fw_rules                   |
| shadow_quota_classes                       |
| shadow_quota_usages                        |
| shadow_quotas                              |
| shadow_reservations                        |
| shadow_s3_images                           |
| shadow_security_group_default_rules        |
| shadow_security_group_instance_association |
| shadow_security_group_rules                |
| shadow_security_groups                     |
| shadow_services                            |
| shadow_snapshot_id_mappings                |
| shadow_snapshots                           |
| shadow_task_log                            |
| shadow_virtual_interfaces                  |
| shadow_volume_id_mappings                  |
| shadow_volume_usage_cache                  |
| snapshot_id_mappings                       |
| snapshots                                  |
| tags                                       |
| task_log                                   |
| virtual_interfaces                         |
| volume_id_mappings                         |
| volume_usage_cache                         |
+--------------------------------------------+
109 rows in set (0.00 sec)
MariaDB [nova]> select host,node,uuid from instances;
+------------+------------+--------------------------------------+
| host       | node       | uuid                                 |
+------------+------------+--------------------------------------+
| compute    | compute    | 52aae669-86a9-4122-a1e4-dee2c4841456 |
| controller | controller | e6c4070f-3dd9-475c-9676-3c5108161fb9 |
| compute    | compute    | b5f1929f-e51c-443d-be02-1854e26443cb |            ## 这时候看它的主机是compute
+------------+------------+--------------------------------------+
3 rows in set (0.00 sec)
MariaDB [nova]> update instances set host='controller',node='controller' where uuid='b5f1929f-e51c-443d-be02-1854e26443cb';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [nova]> select host,node,uuid from instances;
+------------+------------+--------------------------------------+
| host       | node       | uuid                                 |
+------------+------------+--------------------------------------+
| compute    | compute    | 52aae669-86a9-4122-a1e4-dee2c4841456 |
| controller | controller | e6c4070f-3dd9-475c-9676-3c5108161fb9 |
| controller | controller | b5f1929f-e51c-443d-be02-1854e26443cb |          ## 修改完成后
+------------+------------+--------------------------------------+
3 rows in set (0.00 sec)

MariaDB [nova]> exit

重启nova服务

[root@controller instances]# systemctl restart openstack-nova-compute

开启虚拟机

[root@controller instances]# nova start b5f1929f-e51c-443d-be02-1854e26443cb
Request to start server b5f1929f-e51c-443d-be02-1854e26443cb has been accepted.
[root@controller instances]# nova show b5f1929f-e51c-443d-be02-1854e26443cb
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                     |
| OS-EXT-AZ:availability_zone          | nova                                                     |
| OS-EXT-SRV-ATTR:host                 | controller                                               |
| OS-EXT-SRV-ATTR:hostname             | test                                                     |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | controller                                               |
| OS-EXT-SRV-ATTR:instance_name        | instance-00000003                                        |
| 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-vmbh21l4                                               |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                 |
| OS-EXT-SRV-ATTR:user_data            | -                                                        |
| OS-EXT-STS:power_state               | 4                                                        |
| OS-EXT-STS:task_state                | powering-on                                              |
| OS-EXT-STS:vm_state                  | stopped                                                  |
| OS-SRV-USG:launched_at               | 2021-07-15T19:30:25.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2021-07-15T19:30:19Z                                     |
| description                          | test                                                     |
| flavor                               | m1.small (2)                                             |
| hostId                               | b4d8e7c2f999c39aa116d311d30396839ddd46175cb62be11c48faf5 |
| host_status                          |                                                          |
| id                                   | b5f1929f-e51c-443d-be02-1854e26443cb                     |
| image                                | centos7 (d108a3da-a0ed-48dd-9e1f-ec40b92c06b2)           |
| int-net network                      | 10.10.10.103                                             |
| key_name                             | -                                                        |
| locked                               | False                                                    |
| metadata                             | {}                                                       |
| name                                 | test                                                     |
| os-extended-volumes:volumes_attached | []                                                       |
| security_groups                      | default                                                  |
| status                               | SHUTOFF                                                  |
| tenant_id                            | f9d44679d8da4276b113fe99fe3b26c6                         |
| updated                              | 2021-07-15T19:40:01Z                                     |
| user_id                              | 1a81b852a6104c8d874d700cbfb1c705                         |
+--------------------------------------+----------------------------------------------------------+
[root@controller instances]# 

在图形界面里查看
在这里插入图片描述

以上是关于OpenStack手动迁移虚拟机的主要内容,如果未能解决你的问题,请参考以下文章

Openstack上虚拟机迁移

OpenStack迁移虚拟机流程分析

VMware虚拟机迁移到openstack平台

8手动创建Openstack Centos虚拟机

一次OpenStack虚拟机热迁移的排错经历

openstack中手动修改虚拟机IP后不能通信