【OpenStack】Nova中的migrate/resize/live-migration

2013年10月22日 综合 共 3906字 字号 小 中 大 评论关闭

声明:

本博客欢迎转发,但请保留原作者信息!

新浪微博:@孔令贤HW

博客地址:http://blog.csdn.net/lynn_kong

内容系本人学习、研究和总结,如有雷同,实属荣幸!

更新记录:

2013.07.04  增加在线迁移虚拟机Postman请求样例

版本:master分支 2013.06.25

hypervisor:KVM
共享存储:无

1、migrate/resize

在虚拟机active和stopped状态下可以进行migrate/resize,resize与migrate的区别是在迁移的同时,改变虚拟机的flavor。
配置项allow_resize_to_same_host表示是否允许迁移到本机,默认是False。

迁移前:

root@controller231:~# nova show rebuild-test2
+-------------------------------------+-------------------------------------------------------------------+
| Property                            | Value                                                             |
+-------------------------------------+-------------------------------------------------------------------+
| status                              | ACTIVE                                                     |
| updated                             | 2013-06-24T09:23:53Z                                              |
| OS-EXT-STS:task_state               | None                                                              |
| OS-EXT-SRV-ATTR:host                | controller231                                                     |
| key_name                            | mykey                                                             |
| p_w_picpath                               | Ubuntu 12.04 cloudimg i386 (1f7f5763-33a1-4282-92b3-53366bf7c695) |
| hostId                              | 083729f2f8f664fffd4cffb8c3e76615d7abc1e11efc993528dd88b9          |
| OS-EXT-STS:vm_state                 | resized                                                           |
| OS-EXT-SRV-ATTR:instance_name       | instance-0000000e                                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | controller231.openstack.org                                       |
| flavor                              | m1.small (2)                                                      |
| id                                  | 03774415-d9ce-4b34-b012-6891d248b767                              |
| security_groups                     | [{u'name': u'default'}]                                           |
| user_id                             | f882feb345064e7d9392440a0f397c25                                  |
| name                                | rebuild-test2                                                     |
| created                             | 2013-06-24T08:14:38Z                                              |
| tenant_id                           | 6fbe9263116a4b68818cf1edce16bc4f                                  |
| OS-DCF:diskConfig                   | MANUAL                                                            |
| metadata                            | {}                                                                |
| accessIPv4                          |                                                                   |
| accessIPv6                          |                                                                   |
| testnet01 network                   | 10.1.1.20, 192.150.73.3                                           |
| progress                            | 0                                                                 |
| OS-EXT-STS:power_state              | 1                                                                 |
| OS-EXT-AZ:availability_zone         | nova                                                              |
| config_drive                        |                                                                   |
+-------------------------------------+-------------------------------------------------------------------+

迁移:

root@controller231:/etc/init.d# nova migrate rebuild-test2

迁移后:

root@controller231:/etc/init.d# nova show rebuild-test2
+-------------------------------------+-------------------------------------------------------------------+
| Property                            | Value                                                             |
+-------------------------------------+-------------------------------------------------------------------+
| status                              | VERIFY_RESIZE                                                     |
| updated                             | 2013-06-25T03:34:43Z                                              |
| OS-EXT-STS:task_state               | None                                                              |
| OS-EXT-SRV-ATTR:host                | compute233                                                        |
| key_name                            | mykey                                                             |
| p_w_picpath                               | Ubuntu 12.04 cloudimg i386 (1f7f5763-33a1-4282-92b3-53366bf7c695) |
| hostId                              | cb0c6e82948e76d2bc0c0a6bb906cdd2d2bcc6e99f0741e2ae05b7cc          |
| OS-EXT-STS:vm_state                 | resized                                                           |
| OS-EXT-SRV-ATTR:instance_name       | instance-0000000e                                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | compute233.openstack.org                                          |
| flavor                              | m1.small (2)                                                      |
| id                                  | 03774415-d9ce-4b34-b012-6891d248b767                              |
| security_groups                     | [{u'name': u'default'}]                                           |
| user_id                             | f882feb345064e7d9392440a0f397c25                                  |
| name                                | rebuild-test2                                                     |
| created                             | 2013-06-24T08:14:38Z                                              |
| tenant_id                           | 6fbe9263116a4b68818cf1edce16bc4f                                  |
| OS-DCF:diskConfig                   | MANUAL                                                            |
| metadata                            | {}                                                                |
| accessIPv4                          |                                                                   |
| accessIPv6                          |                                                                   |
| testnet01 network                   | 10.1.1.20, 192.150.73.3                                           |
| progress                            | 0                                                                 |
| OS-EXT-STS:power_state              | 1                                                                 |
| OS-EXT-AZ:availability_zone         | nova                                                              |
| config_drive                        |                                                                   |
+-------------------------------------+-------------------------------------------------------------------+

迁移之后,会在数据库中新增migration表记录,同时会增加instance_system_metadata表记录,记录老的flavor和新的flavor,如果是resize,也会更新instances表中虚拟机的flavor信息。

对于resize,还有两个相关操作:confirm_resize和revert_resize,两个操作都是在虚拟机状态为resized下的操作。前者是resize的确认,后者是回退。也就是说,在做完migrate/resize操作后,给用户提供了后悔的机会,比如用户可能对新规格的虚拟机性能不满意,不愿意花冤枉钱,于是可以调用revert_resize,是虚拟机回退到之前的状态(包括虚拟机所在的主机和虚拟机的规格)。还需要注意,会有这样的情况,用户做完了resize/migrate,然后没有确认也没有回退(因为可能resize操作并不收费,所以用户想着能体验多长时间就用多长时间)。此时,OpenStack提供了循环任务的机制处理这种情况,当系统中配置项resize_confirm_window大于0时,计算节点会自动将在本机中状态为resized,时间超过resize_confirm_window的虚拟机进行确认。

在做migrate/resize前还应注意,计算节点间是需要配置nova用户无密码访问的;同时,migrate/resize操作支持共享存储。

2、os-migrateLive

migrate操作会先将虚拟机停掉,也就是所谓的“冷迁移”,而os-migrateLive是“热迁移”,虚拟机不会停机。
live-migration是在虚拟机active状态下的操作,且不允许热迁移到本机。

live-migration允许用户指定block_migration参数,表示是否进行块迁移。有几种情况:
1、block_migration=True,但系统使用了共享存储,抛异常;
2、block_migration=False,但系统没有使用共享存储且虚拟机没有使用后端系统卷,抛异常;

注意事项:
1、需要配置计算节点的/etc/hosts文件,使相互之间能够用主机名访问。
2、如果在virt driver层失败,虚拟机状态会重置为active,所以当调用live-migration后,但查询虚拟机发现没有发生迁移,且状态仍是active,则很有可能是在计算节点出现异常。

迁移流程手绘图:

我的环境中,ssh登录虚拟机,在虚拟机内不停的发送ping请求,在线迁移过程中,会有10s左右的停顿现象,然后恢复正常,与虚拟机的ssh连接没有中断。迁移虚拟机: