Openstack Icehouse 虚拟机迁移配置

本文主要参考博客:Setting up Live Migration in Openstack Icehouse 解决bug参考:live-migration –block-migrate fails

0 理解虚拟机迁移

1 环境准备

1.1一个控制节点,三个计算节点,都使用Openstack Icehouse版本。查看每个节点的/etc/hosts里面是否内容一致,参考如下。

Controller 192.168.100.20
compute-0 192.168.100.30
compute-1 192.168.100.31
compute-2 192.168.100.32

1.2 确保四个节点网络连通

2 控制节点配置

2.1修改nova配置文档 vi /etc/nova/nova.conf 修改

vncserver_listen=0.0.0.0

添加

live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE

重启nova组件各服务

service nova-api restart
service nova-cert restart
service nova-consoleauth restart
service nova-scheduler restart
service nova-conductor restart
service nova-novncproxy restart

3 计算节点配置

3.1添加iptables

//允许libvirt监听TCP的16509端口
iptables -A INPUT -p tcp -m multiport –ports 16509 -m comment –comment “libvirt” -j ACCEPT
//允许kvm使用tcp的49152到49216端口
iptables -A INPUT -p tcp -m multiport –ports 49152:49216 -m comment –comment “migration” -j ACCEPT

3.2修改libvirt配置 vi /etc/libvirt/libvirtd.conf

listen_tls = 0
listen_tcp = 1
auth_tcp = “none”

vi /etc/init/libvirt-bin.conf

改前 : exec /usr/sbin/libvirtd $libvirtd_opts
改后 : exec /usr/sbin/libvirtd -d -l

vi /etc/default/libvirt-bin

改前 :libvirtd_opts=” -d”
改后 :libvirtd_opts=” -d -l”

重启libvirt

stop libvirt-bin && start libvirt-bin

3.3修改nova配置 vi /etc/nova/nova.conf 添加

live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE

重启nova

service nova-compute restart

4 验证迁移

在控制节点: 查看已启动的虚拟机: nova list 迁移:

//nova live-migration –block_migrate
nova live-migration –block_migrate 4a5e2e83-b824-4417-8092-5c20a35131c2 compute-1

这时候就出现HTTP400报错,进去计算节点nova文档查看错误,/var/log/nova/nova-compute,发现报错:

XML error: CPU feature ‘pdpe1gb’ specified more than once

Google了一下发现这是I版本的一个bug,在修复bug之前,只好在计算节点修改nova源码 vi /usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py 进到4353行,把

for f in info[‘features’]:
cpu.add_feature(vconfig.LibvirtConfigCPUFeature(f))
//换成
test = []
for f in info[‘features’]:
if f not in test:
test.append(f)
cpu.add_feature(vconfig.LibvirtConfigCPUFeature(f))

重新编译nova 创建一个.sh文件,我这里叫a.sh,里面添加以下内容:

(echo ‘import py_compile’; echo ‘py_compile.compile(r”/usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py”)’) | python

运行这个脚本文件

sh a.sh

此时就编译成功 重启nova

service nova-compute restart

大功告成!