前面我们介绍了有关OpenStack的热迁移包括块迁移和共享存储迁移,对于快迁移可能有一个致命的缺点,就是他相当于一个物理对象的迁移,如果虚拟机实例比较大或者网络带宽有所限制,这可能会让用户感觉不是非常友好,虽然他也是一个不宕机的迁移。
今天就给大家介绍另一种方式,也就是共享存储迁移。
前面的文章已经说明的很清楚了,就是将所有计算节点的实例文件放在一个共享存储上,那么所谓的迁移其实就是这个实例运行在哪一个物理计算节点的问题,可能就是一个数据库行的修改而已。(也曾经看有限用户之间修改数据库nova里面的instances表来进行操作,但是不建议这样改)
关于设置共享存储,请参考:http://blog.csdn.net/chinagissoft/article/details/45605539
因为每个计算节点默认的实例存储路径为:/var/lib/nova/instances,当然,用户也可以修改nova.conf配置文件来自定义这个默认存储,这里我们就不再进行修改了。
本机的测试环境如下:
OpenStack icehouse
控制节点:controller 192.168.3.180
计算节点:computer 192.168.3.181
计算节点:computer2 192.168.3.182
计算节点:computer3 192.168.3.183
前面我已经解释了为什么我有增加了两个计算节点,因为在同步的时候,系统会要求每个计算节点的nova的用户ID必须保持一致,所以我在以前做实验的环境只包含180和181节点老是不成功,所以就新添加了182和183,这两个机器由于是clone出来的,所以所有配置都一样。
配置libvirt,注意:每个compute节点都是同样的配置,
修改/etc/libvirt/libvirtd.conf文件:
listen_tls = 0
listen_tcp = 1
auth_tcp = "none" 修改这个也就是通过tcp 无密码登录
修改/etc/init/libvirt-bin.conf文件:
改前 : env libvirtd_opts="-d "
改后 :env libvirtd_opts="-d -l" 添加-l 也就是添加tcp连接
修改/etc/default/libvirt-bin:
改前 :libvirtd_opts=" -d"
改后 :libvirtd_opts=" -d -l" 添加-l 也就是添加tcp连接
重新启动libvirt-bin服务:
sudo service libvirt-bin restart
重新启动nova-compute服务
sudo servicenova-compute restart
1、我在182机器上,创建一个/home/sm/share文件夹,作为存储虚拟机实例的共享文件夹,然后进行共享
sm@computer2:~$ sudo cat /etc/exports
[sudo] password for sm:
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/home/sm/share *(insecure,rw,sync,no_root_squash)
2、在182机器上进行mount
root@computer2:~# mount 192.168.3.182:/home/sm/share /var/lib/nova/instances/
root@computer2:~# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu)
cgroup on /sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,relatime,devices)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name= systemd)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.3.182:/home/sm/share on /var/lib/nova/instances type nfs (rw,vers=4,addr =192.168.3.182,clientaddr=192.168.3.182)
3、在183机器上进行mount
sm@computer3:~$ sudo mount 192.168.3.182:/home/sm/share /var/lib/nova/instances/
sm@computer3:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu)
cgroup on /sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,relatime,hugetlb)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
192.168.3.182:/home/sm/share on /var/lib/nova/instances type nfs (rw,vers=4,addr=192.168.3.182,clientaddr=192.168.3.183)
4、直接在computer2机器上创建虚拟机实例
sm@controller:~$ nova boot --availability-zone nova:computer2 --flavor m1.tiny - -image cirros-0.3.2-x86_64 --nic net-id=1dfa9da1-43fd-4128-b9a0-2ca76a664933 --security-group default --key-name sm-key v4
5、查看v4实例信息
sm@computer2:~$ nova show v4
+--------------------------------------+------------------------------------------------------------+
| Property | Value |
+--------------------------------------+------------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | computer2 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | computer2 |
| OS-EXT-SRV-ATTR:instance_name | instance-0000003d |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | - |
| OS-EXT-STS:vm_state | active |
| OS-SRV-USG:launched_at | 2015-05-14T14:00:04.000000 |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2015-05-11T22:17:59Z |
| flavor | m1.tiny (1) |
| hostId | 890c461c5a827fb0e8465b3410acc939fb2804876ff9a30300dd3f90 |
| id | a03ff111-7d0d-4fd3-9081-16bbab99e2d0 |
| image | cirros-0.3.2-x86_64 (f2b0f15b-bd5e-4766-973c-24547c1faf03) |
| key_name | sm-key |
| metadata | {} |
| name | v4 |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | default |
| sharednet1 network | 192.168.3.118 |
| status | ACTIVE |
| tenant_id | b500268a41e34752aba847c7ea464870 |
| updated | 2015-05-11T22:18:13Z |
| user_id | 9b1cdfc2b5614eb39f042317f54a286c |
+--------------------------------------+------------------------------------------------------------+
我们可以看到v4默认在计算节点computer2运行
6、进行迁移
sm@computer2:~$ nova live-migration v4 computer3
我们可以看到,与块迁移相比,其实就没有添加--block-migration参数,其他与快迁移都是一样的。如果执行不报错,就没有问题,如果有错误,查看/var/log/nova/nova-compute.log日志.
与快迁移对比,明显感觉这个速度更快,当然理解原理也不难有这个效果了。
7、查看v4迁移后的信息
sm@computer2:~$ nova show v4
+--------------------------------------+------------------------------------------------------------+
| Property | Value |
+--------------------------------------+------------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | computer3 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | computer3 |
| OS-EXT-SRV-ATTR:instance_name | instance-0000003d |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | - |
| OS-EXT-STS:vm_state | active |
| OS-SRV-USG:launched_at | 2015-05-14T14:00:04.000000 |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2015-05-11T22:17:59Z |
| flavor | m1.tiny (1) |
| hostId | c9741df1176a21c74117b5a53e1576195f4970e3c6d3448bda323b1e |
| id | a03ff111-7d0d-4fd3-9081-16bbab99e2d0 |
| image | cirros-0.3.2-x86_64 (f2b0f15b-bd5e-4766-973c-24547c1faf03) |
| key_name | sm-key |
| metadata | {} |
| name | v4 |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | default |
| sharednet1 network | 192.168.3.118 |
| status | ACTIVE |
| tenant_id | b500268a41e34752aba847c7ea464870 |
| updated | 2015-05-11T22:19:47Z |
| user_id | 9b1cdfc2b5614eb39f042317f54a286c |
+--------------------------------------+------------------------------------------------------------+