***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************
转载自:http://www.cnblogs.com/kevingrace/p/6018676.html 散尽浮华
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
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
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
[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
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