openstack虚拟机迁移的操作记录

需求说明: 计算节点linux-node1.openstack:192.168.1.8   计算节点linux-node2.openstack:192.168.1.17

这两个计算节点在同一个控制节点下(192.168.1.8既是控制节点,也是其中一个计算节点),现在需要将linux-node1.openstack上的虚拟机kvm-server005迁移到liunx-node2.openstack上。

一、openstack的虚拟机线下迁移(”冷迁移“,迁移前关闭虚拟机)

操作记录如下:

linux-node1.openstack上的操作:

1)查看虚拟机

[root@linux-node1 src]# source admin-openrc.sh 
[root@linux-node1 src]# nova list
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
| ID                                   | Name                       | Status | Task State | Power State | Networks           |
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
| b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1                  | ACTIVE | -          | Running     | flat=192.168.1.151 |
| 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1              | ACTIVE | -          | Running     | flat=192.168.1.150 |
| 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup            | ACTIVE | -          | Running     | flat=192.168.1.152 |
| 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005              | ACTIVE | -          | Running     | flat=192.168.1.154 |
| 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup           | ACTIVE | -          | Running     | flat=192.168.1.155 |
| a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup           | ACTIVE | -          | Running     | flat=192.168.1.156 |
| 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup           | ACTIVE | -          | Running     | flat=192.168.1.103 |
| a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup                | ACTIVE | -          | Running     | flat=192.168.1.153 |
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+

2)停止待迁移虚拟机kvm-server005

[root@linux-node1 src]# nova stop 3483d9f1-4015-48d9-9837-b67ca82dd54d
Request to stop server 3483d9f1-4015-48d9-9837-b67ca82dd54d has been accepted.
[root@linux-node1 src]# nova list
+--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+
| ID                                   | Name                       | Status | Task State   | Power State | Networks           |
+--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+
| b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1                  | ACTIVE | -            | Running     | flat=192.168.1.151 |
| 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1              | ACTIVE | -            | Running     | flat=192.168.1.150 |
| 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup            | ACTIVE | -            | Running     | flat=192.168.1.152 |
| 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005              | SHUTOFF| -            | Shutdown    | flat=192.168.1.154 |
| 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup           | ACTIVE | -            | Running     | flat=192.168.1.155 |
| a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup           | ACTIVE | -            | Running     | flat=192.168.1.156 |
| 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup           | ACTIVE | -            | Running     | flat=192.168.1.103 |
| a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup                | ACTIVE | -            | Running     | flat=192.168.1.153 |
+--------------------------------------+----------------------------+--------+--------------+-------------+--------------------+

3)查看待迁虚拟机kvm-server005所在的宿主机

[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos'
| OS-EXT-SRV-ATTR:host                 | linux-node1.openstack 

4)登录宿主机linux-node1.openstack上,将虚拟机kvm-server005虚拟机的数据拷贝到待迁移的宿主机linux-node2.openstack上

[root@linux-node1 src]# cd /var/lib/nova/instances
[root@linux-node1 instances]# ls
30e5ba3e-3942-4119-9ba6-7523cf865b6f  5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3  a5863e46-ef75-4601-a9df-505da5db58ed  compute_nodes
3483d9f1-4015-48d9-9837-b67ca82dd54d  9acdb28b-02c2-41bb-87c4-5f3a8fa008ab  b6a4738d-7e01-4068-a09b-7008b612d126  locks
377c536e-4d27-4447-8d9d-24c2686a73f6  a2893208-3ec9-4606-ab82-d7a870206cb9  _base                                 snapshots
[root@linux-node1 instances]# rsync -e "ssh -p22" -avpgolr 3483d9f1-4015-48d9-9837-b67ca82dd54d 192.168.1.17:/var/lib/nova/instances/
sending incremental file list
3483d9f1-4015-48d9-9837-b67ca82dd54d/
3483d9f1-4015-48d9-9837-b67ca82dd54d/console.log
3483d9f1-4015-48d9-9837-b67ca82dd54d/disk
3483d9f1-4015-48d9-9837-b67ca82dd54d/disk.info
3483d9f1-4015-48d9-9837-b67ca82dd54d/disk.swap
3483d9f1-4015-48d9-9837-b67ca82dd54d/libvirt.xml

sent 381469737 bytes  received 111 bytes  69358154.18 bytes/sec
total size is 381422781  speedup is 1.00

目标节点linux-node2.openstack上的操作

1)查看虚拟机kvm-server005的数据有没有拷贝过来,修改权限

[root@linux-node2 instances]# pwd
/var/lib/nova/instances
[root@linux-node2 instances]# ll
total 12
drwxr-xr-x. 2 nova nova   85 Oct 31 14:54 0944254c-1c75-4523-9751-2389d677d59c
drwxr-xr-x. 2 nova nova   85 Sep  6 12:59 3483d9f1-4015-48d9-9837-b67ca82dd54d
drwxr-xr-x. 2 nova nova   85 Oct 31 17:29 946b340a-28bc-492d-8b3a-59d2fea1b464
drwxr-xr-x. 2 nova nova 4096 Oct 31 17:17 _base
-rw-r--r--. 1 nova nova   44 Nov  1 10:53 compute_nodes
drwxr-xr-x. 2 nova nova   85 Oct 31 17:23 f6be1cb3-a694-4492-b2db-55ff9f09d843
drwxr-xr-x. 2 nova nova 4096 Oct 31 17:14 locks
[root@linux-node2 instances]# chown -R nova.nova 3483d9f1-4015-48d9-9837-b67ca82dd54d/
[root@linux-node2 instances]# ll 3483d9f1-4015-48d9-9837-b67ca82dd54d/
total 372492
-rw-rw----. 1 nova nova     65214 Sep  8 13:58 console.log
-rw-r--r--. 1 nova nova 381157376 Nov  1 10:59 disk
-rw-r--r--. 1 nova nova       162 Sep  6 12:59 disk.info
-rw-r--r--. 1 nova nova    197120 Sep  6 12:59 disk.swap
-rw-r--r--. 1 nova nova      2909 Sep  6 12:59 libvirt.xml

2)登录数据库更改MySQL中的host、node字段为新的物理主机名字

[root@linux-node2 instances]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4063
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)]> use nova;                                                                                                                    
Database changed
MariaDB [nova]> update instances set host='linux-node2.openstack', node='linux-node2.openstack' where uuid='3483d9f1-4015-48d9-9837-b67ca82dd54d';
Query OK, 1 rows affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [nova]> 

3)在目标节点linux-node2.openstack上启动虚拟机,启动前重启一下该计算节点的compute服务

[root@linux-node2 instances]# systemctl restart  openstack-nova-compute
[root@linux-node2 instances]# nova start 3483d9f1-4015-48d9-9837-b67ca82dd54d

4)验证虚拟机所在的宿主机

[root@linux-node2 src]# nova list
+--------------------------------------+--------------+--------+------------+-------------+--------------------+
| ID                                   | Name         | Status | Task State | Power State | Networks           |
+--------------------------------------+--------------+--------+------------+-------------+--------------------+
| 946b340a-28bc-492d-8b3a-59d2fea1b464 | centos03     | ACTIVE | -          | Running     | flat=192.168.1.104 |
| 0944254c-1c75-4523-9751-2389d677d59c | kvm-centos01 | ACTIVE | -          | Running     | flat=192.168.1.121 |
| f6be1cb3-a694-4492-b2db-55ff9f09d843 | kvm-centos02 | ACTIVE | -          | Running     | flat=192.168.1.122 |
| 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005| ACTIVE | -          | Running     | flat=192.168.1.154 |
+--------------------------------------+--------------+--------+------------+-------------+--------------------+
[root@linux-node2 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos'
| OS-EXT-SRV-ATTR:host                 | linux-node2.openstack 

二、openstack的虚拟机在线迁移(”热迁移“,虚拟机在运行中迁移)

直接在控制节点上操作

1)查看虚拟机

[root@linux-node1 src]# source admin-openrc.sh
[root@linux-node1 src]# nova list
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
| ID                                   | Name                       | Status | Task State | Power State | Networks           |
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+
| b6a4738d-7e01-4068-a09b-7008b612d126 | beta-new1                  | ACTIVE | -          | Running     | flat=192.168.1.151 |
| 9acdb28b-02c2-41bb-87c4-5f3a8fa008ab | dev-new-test1              | ACTIVE | -          | Running     | flat=192.168.1.150 |
| 30e5ba3e-3942-4119-9ba6-7523cf865b6f | fangfull-backup            | ACTIVE | -          | Running     | flat=192.168.1.152 |
| 3483d9f1-4015-48d9-9837-b67ca82dd54d | kvm-server005              | ACTIVE | -          | Running     | flat=192.168.1.154 |
| 5ec50ae5-a1f9-4425-b509-cfeb5ef62ca3 | memcache1-backup           | ACTIVE | -          | Running     | flat=192.168.1.155 |
| a5863e46-ef75-4601-a9df-505da5db58ed | memcache2-backup           | ACTIVE | -          | Running     | flat=192.168.1.156 |
| 377c536e-4d27-4447-8d9d-24c2686a73f6 | memcache3-backup           | ACTIVE | -          | Running     | flat=192.168.1.103 |
| a2893208-3ec9-4606-ab82-d7a870206cb9 | xqsj-backup                | ACTIVE | -          | Running     | flat=192.168.1.153 |
+--------------------------------------+----------------------------+--------+------------+-------------+--------------------+

2)查看待迁虚拟机kvm-server005所在的宿主机

[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos'
| OS-EXT-SRV-ATTR:host                 | linux-node1.openstack

3)查看可用的计算节点

[root@linux-node1 src]# nova-manage service list
No handlers could be found for logger "oslo_config.cfg"
Binary           Host                                 Zone             Status     State Updated_At
.........
nova-compute     linux-node1.openstack                nova             enabled    :-)   2016-11-01 05:12:56
nova-compute     linux-node2.openstack                nova             enabled    XXX   2016-10-31 05:55:24

4)查看目标计算节点linux-node2.openstack资源

[root@linux-node1 src]# nova-manage service describe_resource linux-node2.openstack
No handlers could be found for logger "oslo_config.cfg"
HOST                              PROJECT     cpu mem(mb)     hdd
linux-node2.openstack(total)                        32   64211     149
linux-node2.openstack(used_now)                      6   14848      75
linux-node2.openstack(used_max)                      6   14336      75
linux-node2.openstack    0cd3632df93d48d6b2c24c67f70e56b8       6   14336      75

5)执行虚拟机的在线迁移,迁移到计算节点linux-node2.openstack上

[root@linux-node1 src]# nova live-migration 3483d9f1-4015-48d9-9837-b67ca82dd54d linux-node2.openstack

6)查看迁移后虚拟机kvm-server005所在的宿主机是否已发生改变

[root@linux-node1 src]# nova show 3483d9f1-4015-48d9-9837-b67ca82dd54d | grep 'OS-EXT-SRV-ATTR:hos'
| OS-EXT-SRV-ATTR:host                 | linux-node2.openstack

注意:

1)/etc/hosts文件提前做好主机映射,确定节点之间能互相ping通主机名。 2)利用id nova命令查看下控制节点nova的uid和gid,并记录,保证两个计算节点的id和gid是否和控制节点保持一致 如果不一致,则利用 usermod -u “控制节点的nova的uid” gropumod -g “控制节点的nova的gid” 两条命令进行修改,同时在所有计算节点运行该命令,保证所有nova相关文件使用新的uid和gid

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏刘君君

docker部署基于nodejs的vue应用

5834
来自专栏码代码的陈同学

15min运维之Docker运行Jenkins从开始到放弃

某新环境需要Jenkins,准备用docker "一条run命令搞定"。其他工具用docker屡试不爽,这次Jenkins是从开始到放弃。

2173
来自专栏CodingToDie

天才第一步 Docker 纸尿裤

Docker Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。 Docker 可以让开发者打包他们的应用以及依赖包到...

3263
来自专栏康怀帅的专栏

在开发环境使用 Docker

本文是对官方文档的总结与备注。 官方文档:https://docs.docker.com/develop/ 根据官方文档的层次,分为 容器 (Container...

7234
来自专栏Python、Flask、Django

精简Python项目的Dockerfile

2484
来自专栏容器云生态

Docker初探(一)-有关docker的介绍和简单使用

先分享一下构建好的image(源码部署的Nginx)    https://hub.docker.com/r/xxbandy123/centos/ 本地do...

3309
来自专栏我的博客

ThinkPHP3.2使用cli模式

php if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); ...

4916
来自专栏圣杰的专栏

.NET Core+MySql+Nginx 容器化部署

1. 引言 上两节我们通过简单的demo学习了docker的基本操作。这一节我们来一个进阶学习,完成ASP.NET Core + MySql + Nginx的容...

4388
来自专栏搜云库

Docker Image 解决镜像无法删除的问题

Error response from daemon: conflict: unable to delete 4ac2d12f10cd (must be for...

47810
来自专栏FreeBuf

使用Docker构建Web渗透测试工具容器

? Docker是世界领先的软件集装化平台,针对不同的渗透测试类型,我们完全可以使用Docker创建相应的环境。有了Docker容器,你可以把测试环境放到U盘...

3059

扫码关注云+社区

领取腾讯云代金券