作者:【吴业亮】云计算开发工程师
博客:http://blog.csdn.net/wylfengyujiancheng
openstack虚拟机动态迁移有两个方式,块迁移和共享存储迁移。
前提条件:
目标物理服务器是有足够的内存,虚拟CPU,磁盘。cpu同类型
说明:
本文用nfs用作共享存储演示,共有四个节点controller、 computer1、computer2、block。其中block是cinder块存储同时用作nfs服务器。虚拟机从computer1动态迁移到computer2上
controller : 192.168.5.161
computer1 : 192.168.5.162
computer2: 192.168.5.163
block:192.168.5.164
一、配置nfs服务器
1、安装nfs软件
# yum install nfs* -y
2、创建共享目录,并赋予权限,其中id162为nova用户ID
# mkdir /data
# chown 162:162 /data
# chmod 777 data/
# echo '/data 192.168.5.0/24(rw,sync,all_squash,anonuid=162,anongid=162)' >/etc/exports
3、启动nfs服务,注意nfs在centos7中需要先启动rpcbind才能启动nfs
# service rpcbind start
# service nfs-server start
# chkconfig rpcbind on
# chkconfig nfs-server on
二、各个计算节点配置
1、配置nfs
# mkdir /nova_data
# yum install nfs* -y
# mount -t nfs 192.168.5.164:/data /nova_dat
2、配置启动文件,_netdev参数为nfs没启动情况下系统可正常启动。
# echo '192.168.5.164:/data /nova_data nfs _netdev,defaults,user,auto,noatime,intr 0 0' >>/etc/f
3、配置nova.conf
instances_path=/nova_data
live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER, VIR_MIGRATE_LIVE, VIR_MIGRATE_TUNNELLED,VIR_MIGRATE_UNSAFE
[vnc]
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = 192.168.8.71
novncproxy_base_url = http://192.168.8.71:6080/vnc_auto.html
enabled = True
4、配置/etc/libvirt/qemu.conf
vnc_listen = "0.0.0.0"
user = "root"
group = "root"
dynamic_ownership = 1
5、配置/etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
auth_tcp="none"
listen_addr = "0.0.0.0"
tcp_port = "16509"
6、配置/etc/sysconfig/libvirtd
LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf
LIBVIRTD_ARGS="--listen"
7、重启服务
#重启服务
# service libvirtd restart
# service openstack-nova-compute restart
8、测试
virsh -c qemu+tcp://服务器IP/system #请在服务器IP处填写你的各个计算节点IP或主机名
[root@wuyeliang /]# virsh -c qemu+tcp://wuyeliang/system
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
四、动态迁移
1、创建虚拟机(通过cinder创建虚拟机和本地共享存储两种)
略过
2、查看实例
# source admin-openrc.sh
# nova list --all-te +--------------------------------------+--------+----------------------------------+--------+------------+-------------+----------------------+
| ID | Name | Tenant ID | Status | Task State | Power State | Networks | +--------------------------------------+--------+----------------------------------+--------+------------+-------------+----------------------+
| f3d749ba-98e1-4624-9782-6da729ad164c | demo-1 | 6aa0d6b0992042d8b116eeb40dd570d0 | ACTIVE | - | Running | public=216.168.10.15 |
| 8da00f69-05f6-4425-9a8a-df56b79a474f | demo-2 | 6aa0d6b0992042d8b116eeb40dd570d0 | ACTIVE | - | Running | public=216.168.10.14 | +--------------------------------------+--------+----------------------------------+--------+------------+-------------+----------------------+
3、查看需要迁移虚拟机实例
# nova show f3d749ba-98e1-4624-9782-6da729ad164c
4、查看可用的计算节点
[root@wuyeliang ~]# nova-manage service list
No handlers could be found for logger "oslo_config.cfg"
Binary Host Zone Status State Updated_At
nova-cert wuyeliang internal enabled :-) 2016-03-08 00:55:09
nova-scheduler wuyeliang internal enabled :-) 2016-03-08 00:55:10
nova-consoleauth wuyeliang internal enabled :-) 2016-03-08 00:55:09
nova-conductor wuyeliang internal enabled :-) 2016-03-08 00:55:09
nova-compute wuyeliang nova enabled :-) 2016-03-08 00:55:01
nova-compute computer1 nova enabled :-) 2016-03-08 00:55:08
nova-compute computer2 nova enabled :-) 2016-03-08 00:55:08
5、查看目标节点资源
[root@wuyeliang ~]# nova-manage service describe_resource computer1
HOST PROJECT cpu mem(mb) hdd
computer1 (total) 2 1840 17 computer1 (used_now) 1 1024 1 computer1 (used_max) 1 512 1 computer1 6aa0d6b0992042d8b116eeb40dd570d0 1 512 1
6、开始迁移,正常无任何回显
#nova live-migration 8da00f69-05f6-4425-9a8a-df56b79a474f computer1