dashboard中虚拟机冷迁移失败后虚拟机回退到正常状态流程、openstack数据库中修改虚拟机信息流程

文章目录

说明

  • 冷迁移是什么应该不需要我说了吧
  • 什么迁移失败的场景可以回退虚拟机? 你失败后不能正常处理虚拟机,使虚拟机正常开机,都可以使用下面的方法来回退。
  • 当然,也不止是迁移失败的场景可以使用该方法,因为其他原因导致虚拟机数据库中的数据异常都可以使用该方法来实现。 简单来说就是,下面的方法就是修改虚拟机数据库的内容的。

虚拟机回退流程

信息核实【计算节点】

  • 回退之前,要确定虚拟机在哪个主机上
    很简单,virsh list --all看到在哪个主机上,就去数据库中将host和node信息设置为该主机,如我这虚拟机在computer07上
bash 复制代码
[root@computer07 instances]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 4     instance-000006a6              running
 -     instance-000006a9              shut off

[root@computer07 instances]#

数据库修改信息流程【控制节点执行】

首先获取nova数据库的密码

控制节点执行:grep mysql /etc/nova/nova.conf ,如下,Changeme_123就是密码

bash 复制代码
[root@controller01 nova]# grep mysql /etc/nova/nova.conf 
connection = mysql+pymysql://nova:Changeme_123@controller01/nova_api
#connection=mysql://nova:nova@localhost/nova
# by the server configuration, set this to no value. Example: mysql_sql_mode=
#mysql_sql_mode=TRADITIONAL
connection = mysql+pymysql://nova:Changeme_123@controller01/nova
# by the server configuration, set this to no value. Example: mysql_sql_mode=
#mysql_sql_mode=TRADITIONAL
# by the server configuration, set this to no value. Example: mysql_sql_mode=
#mysql_sql_mode=TRADITIONAL
  • 登录数据库并进入nova表
    • mysql -unova -p
    • use nova;
bash 复制代码
[root@controller01 ~]# mysql -unova -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4286927
Server version: 10.1.20-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)]> 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]>
  • 回退其实就是将错误的数据库信息修改过来而已,需要修改 host和node,修改为源宿主机就可以了
    • 查看信息select * from instances where uuid='8c1fb8d2-d90d-4250-b64f-b18e2df0465c'\G
    • 修改信息update instances set host='computer07',node='computer07' where uuid='8c1fb8d2-d90d-4250-b64f-b18e2df0465c'\G
bash 复制代码
MariaDB [nova]> select * from instances where uuid='8c1fb8d2-d90d-4250-b64f-b18e2df0465c'\G
*************************** 1. row ***************************
              created_at: 2023-09-12 16:14:21
              updated_at: 2023-09-12 22:41:34
              deleted_at: NULL
                      id: 1705
             internal_id: NULL
                 user_id: 5357091ec61b472bb75668dfe3e2b7e5
              project_id: 8d71dc6fb0f244c0875717774b66a8c2
               image_ref: 47c2723b-f479-4a58-977c-e102c2b1d4ef
               kernel_id: 
              ramdisk_id: 
            launch_index: 0
                key_name: NULL
                key_data: NULL
             power_state: 0
                vm_state: error
               memory_mb: 8192
                   vcpus: 8
                hostname: hegui-test-linux7.2-4
                    host: computer03
               user_data: IyEvYmluL2Jhc2gKcGFzc3dkIHJvb3Q8PEVPRgpyb290CnJvb3QKRU9G
          reservation_id: r-2mz46wcx
            scheduled_at: NULL
             launched_at: 2023-09-12 16:14:42
           terminated_at: NULL
            display_name: hegui-test-linux7.2-4
     display_description: hegui-test-linux7.2-4
       availability_zone: test001
                  locked: 0
                 os_type: NULL
             launched_on: computer07
        instance_type_id: 247
                 vm_mode: NULL
                    uuid: 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
            architecture: NULL
        root_device_name: /dev/vda
            access_ip_v4: NULL
            access_ip_v6: NULL
            config_drive: 
              task_state: NULL
default_ephemeral_device: NULL
     default_swap_device: NULL
                progress: 0
        auto_disk_config: 1
      shutdown_terminate: 0
       disable_terminate: 0
                 root_gb: 200
            ephemeral_gb: 0
               cell_name: NULL
                    node: computer03
                 deleted: 0
               locked_by: NULL
                 cleaned: 1
      ephemeral_key_uuid: NULL
1 row in set (0.00 sec)

MariaDB [nova]> update instances set host='computer07',node='computer07' where uuid='8c1fb8d2-d90d-4250-b64f-b18e2df0465c'\G
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [nova]> select * from instances where uuid='8c1fb8d2-d90d-4250-b64f-b18e2df0465c'\G                                 
*************************** 1. row ***************************
              created_at: 2023-09-12 16:14:21
              updated_at: 2023-09-12 22:41:34
              deleted_at: NULL
                      id: 1705
             internal_id: NULL
                 user_id: 5357091ec61b472bb75668dfe3e2b7e5
              project_id: 8d71dc6fb0f244c0875717774b66a8c2
               image_ref: 47c2723b-f479-4a58-977c-e102c2b1d4ef
               kernel_id: 
              ramdisk_id: 
            launch_index: 0
                key_name: NULL
                key_data: NULL
             power_state: 0
                vm_state: error
               memory_mb: 8192
                   vcpus: 8
                hostname: hegui-test-linux7.2-4
                    host: computer07
               user_data: IyEvYmluL2Jhc2gKcGFzc3dkIHJvb3Q8PEVPRgpyb290CnJvb3QKRU9G
          reservation_id: r-2mz46wcx
            scheduled_at: NULL
             launched_at: 2023-09-12 16:14:42
           terminated_at: NULL
            display_name: hegui-test-linux7.2-4
     display_description: hegui-test-linux7.2-4
       availability_zone: test001
                  locked: 0
                 os_type: NULL
             launched_on: computer07
        instance_type_id: 247
                 vm_mode: NULL
                    uuid: 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
            architecture: NULL
        root_device_name: /dev/vda
            access_ip_v4: NULL
            access_ip_v6: NULL
            config_drive: 
              task_state: NULL
default_ephemeral_device: NULL
     default_swap_device: NULL
                progress: 0
        auto_disk_config: 1
      shutdown_terminate: 0
       disable_terminate: 0
                 root_gb: 200
            ephemeral_gb: 0
               cell_name: NULL
                    node: computer07
                 deleted: 0
               locked_by: NULL
                 cleaned: 1
      ephemeral_key_uuid: NULL
1 row in set (0.00 sec)

MariaDB [nova]> 
MariaDB [nova]> exit
Bye
[root@controller01 neutron]#

重置虚拟机状态【控制节点】

  • 查看状态:nova show 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
  • 修复状态为active:nova reset-state --active 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
  • 关机:nova stop 8c1fb8d2-d90d-4250-b64f-b18e2df0465c【因为要去冷迁移,所以直接关机】
bash 复制代码
[root@controller01 neutron]# nova show 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
+--------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Property                             | Value                                                                                                                                                                                                                           |
+--------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                                                                                                                                                                                            |
| OS-EXT-AZ:availability_zone          | test001                                                                                                                                                                                                                         |
| OS-EXT-SRV-ATTR:host                 | computer07                                                                                                                                                                                                                      |
| OS-EXT-SRV-ATTR:hostname             | hegui-test-linux7.2-4                                                                                                                                                                                                           |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | computer07                                                                                                                                                                                                                      |
| OS-EXT-SRV-ATTR:instance_name        | instance-000006a9                                                                                                                                                                                                               |
| 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-2mz46wcx                                                                                                                                                                                                                      |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                                                                                                                                                                                        |
| OS-EXT-SRV-ATTR:user_data            | IyEvYmluL2Jhc2gKcGFzc3dkIHJvb3Q8PEVPRgpyb290CnJvb3QKRU9G                                                                                                                                                                        |
| OS-EXT-STS:power_state               | 0                                                                                                                                                                                                                               |
| OS-EXT-STS:task_state                | -                                                                                                                                                                                                                               |
| OS-EXT-STS:vm_state                  | error                                                                                                                                                                                                                           |
| OS-SRV-USG:launched_at               | 2023-09-12T16:14:42.000000                                                                                                                                                                                                      |
| OS-SRV-USG:terminated_at             | -                                                                                                                                                                                                                               |
| accessIPv4                           |                                                                                                                                                                                                                                 |
| accessIPv6                           |                                                                                                                                                                                                                                 |
| config_drive                         |                                                                                                                                                                                                                                 |
| created                              | 2023-09-12T16:14:21Z                                                                                                                                                                                                            |
| description                          | hegui-test-linux7.2-4                                                                                                                                                                                                           |
| fault                                | {"message": "error creating snapshot nova-resize from 8c1fb8d2-d90d-4250-b64f-b18e2df0465c_disk", "code": 500, "details": "  File \"/usr/lib/python2.7/site-packages/nova/compute/manager.py\", line 375, in decorated_function |
|                                      |     return function(self, context, *args, **kwargs)                                                                                                                                                                             |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/compute/manager.py\", line 4054, in finish_resize                                                                                                                                |
|                                      |     self._set_instance_obj_error_state(context, instance)                                                                                                                                                                       |
|                                      |   File \"/usr/lib/python2.7/site-packages/oslo_utils/excutils.py\", line 220, in __exit__                                                                                                                                       |
|                                      |     self.force_reraise()                                                                                                                                                                                                        |
|                                      |   File \"/usr/lib/python2.7/site-packages/oslo_utils/excutils.py\", line 196, in force_reraise                                                                                                                                  |
|                                      |     six.reraise(self.type_, self.value, self.tb)                                                                                                                                                                                |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/compute/manager.py\", line 4042, in finish_resize                                                                                                                                |
|                                      |     disk_info, image_meta)                                                                                                                                                                                                      |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/compute/manager.py\", line 4007, in _finish_resize                                                                                                                               |
|                                      |     old_instance_type)                                                                                                                                                                                                          |
|                                      |   File \"/usr/lib/python2.7/site-packages/oslo_utils/excutils.py\", line 220, in __exit__                                                                                                                                       |
|                                      |     self.force_reraise()                                                                                                                                                                                                        |
|                                      |   File \"/usr/lib/python2.7/site-packages/oslo_utils/excutils.py\", line 196, in force_reraise                                                                                                                                  |
|                                      |     six.reraise(self.type_, self.value, self.tb)                                                                                                                                                                                |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/compute/manager.py\", line 4002, in _finish_resize                                                                                                                               |
|                                      |     block_device_info, power_on)                                                                                                                                                                                                |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py\", line 7363, in finish_migration                                                                                                                         |
|                                      |     fallback_from_host=migration.source_compute)                                                                                                                                                                                |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py\", line 3179, in _create_image                                                                                                                            |
|                                      |     backend.create_snap(libvirt_utils.RESIZE_SNAPSHOT_NAME)                                                                                                                                                                     |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/virt/libvirt/imagebackend.py\", line 938, in create_snap                                                                                                                         |
|                                      |     return self.driver.create_snap(self.rbd_name, name)                                                                                                                                                                         |
|                                      |   File \"/usr/lib/python2.7/site-packages/nova/virt/libvirt/storage/rbd_utils.py\", line 382, in create_snap                                                                                                                    |
|                                      |     tpool.execute(vol.create_snap, name)                                                                                                                                                                                        |
|                                      |   File \"/usr/lib/python2.7/site-packages/eventlet/tpool.py\", line 125, in execute                                                                                                                                             |
|                                      |     six.reraise(c, e, tb)                                                                                                                                                                                                       |
|                                      |   File \"/usr/lib/python2.7/site-packages/eventlet/tpool.py\", line 83, in tworker                                                                                                                                              |
|                                      |     rv = meth(*args, **kwargs)                                                                                                                                                                                                  |
|                                      |   File \"/usr/lib/python2.7/site-packages/rbd.py\", line 594, in create_snap                                                                                                                                                    |
|                                      |     raise make_ex(ret, 'error creating snapshot %s from %s' % (name, self.name))                                                                                                                                                |
|                                      | ", "created": "2023-09-12T22:36:17Z"}                                                                                                                                                                                           |
| flavor                               | 8c-8g-200G (f3463d6d-5d5c-45b7-b371-29e84c8a49e9)                                                                                                                                                                               |
| hostId                               | a6531d2353b9eb7730d1cee93db522b51442cf6b2df6ef58026a39fb                                                                                                                                                                        |
| host_status                          | UP                                                                                                                                                                                                                              |
| id                                   | 8c1fb8d2-d90d-4250-b64f-b18e2df0465c                                                                                                                                                                                            |
| image                                | centos7.4 (47c2723b-f479-4a58-977c-e102c2b1d4ef)                                                                                                                                                                                |
| key_name                             | -                                                                                                                                                                                                                               |
| locked                               | False                                                                                                                                                                                                                           |
| metadata                             | {}                                                                                                                                                                                                                              |
| name                                 | hegui-test-linux7.2-4                                                                                                                                                                                                           |
| os-extended-volumes:volumes_attached | []                                                                                                                                                                                                                              |
| out-network network                  | 111.11.199.77                                                                                                                                                                                                                   |
| own-network network                  | 10.233.61.44                                                                                                                                                                                                                    |
| security_groups                      | default                                                                                                                                                                                                                         |
| status                               | ERROR                                                                                                                                                                                                                           |
| tenant_id                            | 8d71dc6fb0f244c0875717774b66a8c2                                                                                                                                                                                                |
| updated                              | 2023-09-12T22:41:34Z                                                                                                                                                                                                            |
| user_id                              | 5357091ec61b472bb75668dfe3e2b7e5                                                                                                                                                                                                |
+--------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller01 neutron]# 
[root@controller01 neutron]# nova reset-state --active 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
Reset state for server 8c1fb8d2-d90d-4250-b64f-b18e2df0465c succeeded; new state is active
[root@controller01 neutron]# 
[root@controller01 neutron]# nova show 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
+--------------------------------------+----------------------------------------------------------+
| Property                             | Value                                                    |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                    | AUTO                                                     |
| OS-EXT-AZ:availability_zone          | test001                                                  |
| OS-EXT-SRV-ATTR:host                 | computer07                                               |
| OS-EXT-SRV-ATTR:hostname             | hegui-test-linux7.2-4                                    |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | computer07                                               |
| OS-EXT-SRV-ATTR:instance_name        | instance-000006a9                                        |
| 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-2mz46wcx                                               |
| OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                 |
| OS-EXT-SRV-ATTR:user_data            | IyEvYmluL2Jhc2gKcGFzc3dkIHJvb3Q8PEVPRgpyb290CnJvb3QKRU9G |
| OS-EXT-STS:power_state               | 0                                                        |
| OS-EXT-STS:task_state                | -                                                        |
| OS-EXT-STS:vm_state                  | active                                                   |
| OS-SRV-USG:launched_at               | 2023-09-12T16:14:42.000000                               |
| OS-SRV-USG:terminated_at             | -                                                        |
| accessIPv4                           |                                                          |
| accessIPv6                           |                                                          |
| config_drive                         |                                                          |
| created                              | 2023-09-12T16:14:21Z                                     |
| description                          | hegui-test-linux7.2-4                                    |
| flavor                               | 8c-8g-200G (f3463d6d-5d5c-45b7-b371-29e84c8a49e9)        |
| hostId                               | a6531d2353b9eb7730d1cee93db522b51442cf6b2df6ef58026a39fb |
| host_status                          | UP                                                       |
| id                                   | 8c1fb8d2-d90d-4250-b64f-b18e2df0465c                     |
| image                                | centos7.4 (47c2723b-f479-4a58-977c-e102c2b1d4ef)         |
| key_name                             | -                                                        |
| locked                               | False                                                    |
| metadata                             | {}                                                       |
| name                                 | hegui-test-linux7.2-4                                    |
| os-extended-volumes:volumes_attached | []                                                       |
| out-network network                  | 111.11.199.77                                            |
| own-network network                  | 10.233.61.44                                             |
| progress                             | 0                                                        |
| security_groups                      | default                                                  |
| status                               | ACTIVE                                                   |
| tenant_id                            | 8d71dc6fb0f244c0875717774b66a8c2                         |
| updated                              | 2023-09-12T23:28:25Z                                     |
| user_id                              | 5357091ec61b472bb75668dfe3e2b7e5                         |
+--------------------------------------+----------------------------------------------------------+
[root@controller01 neutron]# 
[root@controller01 neutron]# nova stop 8c1fb8d2-d90d-4250-b64f-b18e2df0465c 

恢复instance的信息【源计算节点】源宿主机上操作

  • 我这虚拟机是在computer07上的,所以登录上该宿主机,进入/var/lib/nova/instances/目录【存放实例信息的目录】
bash 复制代码
[root@computer07 ~]# cd /var/lib/nova/instances/
[root@computer07 instances]# ls
154f17ab-d37b-4162-a870-4016c107312a  6e5783f1-e12c-494d-bcdc-60389105b658         9bdb337a-f247-4d45-8a89-f9288b54d5dd  compute_nodes
2cec04ce-5ca2-4910-ae7d-d782b8a2c23c  7e10aa19-3caa-4e95-b4e0-2df5de633023         b39a8ac9-2c20-4d4e-b820-fedc59b0385c  e2e90bec-0d3a-4185-80da-0e2cf6218ed5
5b4f6012-d48a-444a-bf8b-b3acb48b054a  8c1fb8d2-d90d-4250-b64f-b18e2df0465c_resize  _base                                 locks
[root@computer07 instances]#
  • 可以看到迁移的虚拟机id后面多了个_resize,我们mv重命名将_resize去掉【也可以去目的主机上的instance目录下删除该虚拟机的uuid,也可以不用去删除】
bash 复制代码
[root@computer07 instances]# mv 8c1fb8d2-d90d-4250-b64f-b18e2df0465c_resize 8c1fb8d2-d90d-4250-b64f-b18e2df0465c
[root@computer07 instances]# 
[root@computer07 instances]# ls
154f17ab-d37b-4162-a870-4016c107312a  6e5783f1-e12c-494d-bcdc-60389105b658  9bdb337a-f247-4d45-8a89-f9288b54d5dd  compute_nodes
2cec04ce-5ca2-4910-ae7d-d782b8a2c23c  7e10aa19-3caa-4e95-b4e0-2df5de633023  b39a8ac9-2c20-4d4e-b820-fedc59b0385c  e2e90bec-0d3a-4185-80da-0e2cf6218ed5
5b4f6012-d48a-444a-bf8b-b3acb48b054a  8c1fb8d2-d90d-4250-b64f-b18e2df0465c  _base                                 locks
[root@computer07 instances]# 

测试

此时虚拟机就已经回退完成了,可以正常开机了。

相关推荐
喵叔哟3 分钟前
重构代码之移动字段
java·数据库·重构
念白4436 分钟前
智能病历xml提取
数据库·sql·oracle
qingy_204610 分钟前
【JavaWeb】JavaWeb入门之XML详解
数据库·oracle
大数据面试宝典14 分钟前
用AI来写SQL:让ChatGPT成为你的数据库助手
数据库·人工智能·chatgpt
努力的小雨19 分钟前
快速上手 KSQL:轻松与数据库交互的利器
数据库·经验分享
Gentle58622 分钟前
labview中连接sql server数据库查询语句
数据库·labview
Gentle58623 分钟前
labview用sql server数据库存取数据到一个单元格
数据库·labview
2401_8576363925 分钟前
共享汽车管理新纪元:SpringBoot框架应用
数据库·spring boot·汽车
菲兹园长26 分钟前
表的设计(MYSQL)
数据库·mysql
Java Fans41 分钟前
MySQL数据库常用命令大全(完整版——表格形式)
数据库·mysql