openstack中VM迁移

背景:

计算节点(compute):10.25.0.3

控制节点(controller):10.25.0.2

计划将计算节点的VM(txm-test-vm-centos6.5-rename)迁移到控制节点


前提:

节点要使用nova命令,需要编译rc文件,不然会报:You must provide a username or user id via --os-username, --os-user-id, env[OS_USERNAME] or env[OS_USER_ID]

rc文件的获取方法:

1. 进入openstack的horizon,在Compute-访问&安全-访问API 的右上角有“下载openstack RC文件”,点击下载

2. 打开.sh文件,只修改密码。密码为openstack admin登录时的密码。密码的参数:export OS_PASSWORD,如:export OS_PASSWORD="admin@3302"

3. 在计算节点和控制节点创建一个文件,文件内容为修改过的.sh文件的内容。

(命令:vi openstackRC.sh  ,i来insert文件内容,完成后wq保存退出)

4. 在节点上编译运行openstackRC.sh,命令:source openstackRC.sh,输入对应节点的登录密码

这样,前期准备工作就做好啦,开始正式迁移虚拟机~


迁移虚拟机

1. 在计算节点查看虚拟机的id

[root@computer1 ~]# nova list
+--------------------------------------+------------------------------+---------+-----+-------------+-----------------------------------------+
| ID                                   | Name                         | Status  | Tas | Power State | Networks                                |
+--------------------------------------+------------------------------+---------+-----+-------------+-----------------------------------------+
| 15a36bb8-251a-4765-b522-888e2d4127f6 | txm-test-vm-centos6.5-2      | ACTIVE  | -   | Running     | txm-test-net=192.168.10.7, 10.25.2.85   |
| cf161e88-07a8-4d67-baf2-7e42245929ea | txm-test-vm-centos6.5-rename | SHUTOFF | -   | NOSTATE     | txm-test-net=192.168.10.6, 10.25.2.74   |
| 32320381-cc9c-45cf-9b61-08ffb42626b0 | txm-test-vm-centos7-2        | ACTIVE  | -   | Running     | test-2=192.168.13.3, 10.25.2.90         |
| 807a1d37-e554-4e15-9d28-206294189633 | txm-test-vm-centos7-rename   | ACTIVE  | -   | Running     | ext-net=10.25.2.89; test-1=192.168.12.3 |
| 4eaa66b9-7d36-4057-bdd8-4c82b4445925 | txm-test-vm-windows          | ACTIVE  | -   | Running     | txm-test-net=192.168.10.5, 10.25.2.68   |
+--------------------------------------+------------------------------+---------+-----+-------------+-----------------------------------------+

要迁移的VM的id为:cf161e88-07a8-4d67-baf2-7e42245929ea


2. 关闭要迁移的虚拟机

[root@computer1 ~]# nova stop cf161e88-07a8-4d67-baf2-7e42245929ea
该VM的状态最终会变成SHUTOFF


3. 在/var/lib/nova/instances下找到对应的虚拟的的目录,目录名就是虚拟机的id,将该文件夹拷贝到目的主机下的/var/lib/nova/instances,确保权限一致。

[root@computer1 ~]# scp -r /var/lib/nova/instances/cf161e88-07a8-4d67-baf2-7e42245929ea root@10.25.0.2:/var/lib/nova/instances/
root@10.25.0.3's password: 
/var/lib/nova/instances/cf161e88-07a8-4d67-baf2-7e42245929ea: not a regular file
[root@controller instances]# scp -r /var/lib/nova/instances/cf161e88-07a8-4d67-baf2-7e42245929ea root@10.25.0.2:~/
root@10.25.0.2's password: 
console.log                                       100%   99     0.1KB/s   00:00    
disk.info                                         100%   79     0.1KB/s   00:00    
disk                                              100% 8146MB 107.2MB/s   01:16    
libvirt.xml                                       100% 2757     2.7KB/s   00:00    


4. 控制节点登录数据库更改MySQL中的host、node字段为新的物理主机名字

[root@controller ~]# mysql -p  ==》进入数据库
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 191665
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]> mysql > select host from instances where uuid='15a36bb8-251a-4765-b522-888e2d4127f6';  ==>查看VM当前所在宿主机名称
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mysql > select host from instances where uuid='15a36bb8-251a-4765-b522-888e2d412' at line 1
MariaDB [nova]> select host from instances where uuid='cf161e88-07a8-4d67-baf2-7e42245929ea';
+------------+
| host       |
+------------+
| computer1|
+------------+
1 row in set (0.00 sec)

MariaDB [nova]> update instances set host='controller', node='controller' where uuid='cf161e88-07a8-4d67-baf2-7e42245929ea';   ==>更新VM宿主机名称,宿主机名称可通过命令提示符查看:[root@机器名:~]
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [nova]> select host from instances where uuid='cf161e88-07a8-4d67-baf2-7e42245929ea';
+-----------+
| host      |
+-----------+
| controller |
+-----------+
1 row in set (0.00 sec)

MariaDB [nova]> exit
Bye


5. 在目标节点上重启compute服务,并启动虚拟机
[root@controller ~]# systemctl restart  openstack-nova-compute    ==》启动服务

[root@controller ~]# nova start cf161e88-07a8-4d67-baf2-7e42245929ea  ==》启动被迁移的VM
Request to start server cf161e88-07a8-4d67-baf2-7e42245929ea has been accepted.

至此,VM从计算节点迁移到控制节点,迁移完毕~~
可以到openstack的horizon验证查看该VM现在所在的节点是否在控制节点




            
阅读更多
个人分类: 学习日志
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭