OpenStack's multiattach Feature (by quqi99)

来源:互联网 发布:flux电磁场仿真软件 编辑:程序博客网 时间:2024/05/16 18:51

**作者:张华 发表于:2017-12-22
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明**

什么是multiattach特性

OpenStack’s multiattach Feature允许一个read only volume经iscsi/FC被attached到多个VM。

代码实现原理

  • 用户首先通过cinder定义一个shareable标志的volume.
  • 在attach的时候,nova需要修改即使在in-use状态下仍然可以attach, nova为每一个attachment指定read-write或者read-only, cinder端修改在available和in-use状态下仍然可attach,multiattach标志设置可以被attach多次。attach之后将volume和instance的关系记录到attachment表中。libvirt端需要将这个volume设置shareable标, 这样hypervisor将不会在volume上设置独占锁及相关针对vm的SELinux隔离设置。
  • 在detach的时候,nova需要传递attachment_id到clinderclient告诉cinder哪个attahment需要detach, 然后cinder结合instance_id与attachment_id做detach。如果cinder设置了multiattach标志又没有传attachment_id(os-detach->attachment_id)过来应该失败。

数据表设计:
volume_attachment(id, volume_id, attached_host, instance_uuid, mountpoint, attach_time, attach_mode, sttach_status, time)

代码实现:
1, cinder side
https://review.openstack.org/#/c/85847/
2, cinderclient side
https://review.openstack.org/#/c/85856/
3, nova side
https://review.openstack.org/#/c/526182/
https://review.openstack.org/#/c/525787/
https://review.openstack.org/#/c/330285/
https://review.openstack.org/#/c/527468/

CLI如何使用:
openstack volume create –size 1 –multi-attach multi_attach_test

已知问题

RDB驱动不支持multiattach - https://review.openstack.org/#/c/283695/, 关于它的讨论 - https://openstack.nimeyo.com/103230/openstack-dev-multi-attach-volume-for-rbd,但根据这个说法(https://bugs.launchpad.net/cinder/+bug/1535815/comments/6)似乎用这个特性是安全的。

容器虚机通过multiattach特性使用同一个存储卷

我们知道Docker容器本身是无状态的,意味着容器退出后不会保存任何数据。但实际使用场景,肯定是需要保存业务数据的,Docker通过volume实现数据的持久化存储以及共享。Docker有很多种使用OpenStack Cinder的驱动:

  • Docker Cinder Driver - https://github.com/j-griffith/cinder-docker-driver, 如何使用见http://superuser.openstack.org/articles/how-to-use-openstack-cinder-for-docker/与http://superuser.openstack.org/articles/how-to-use-cinder-with-swarm/
  • OpenStack Fuxi - 华为主导的OpenStack官方工程,让Docker容器使用Cinder和Manila - https://docs.openstack.org/fuxi/latest/readme.html
  • Flocker - 是一款针对容器的存储方案
  • REX-Ray - 也是一款进一步封装之后针对容器的存储方案 - rexray/cinder驱动(https://rexray.readthedocs.io/en/stable/user-guide/schedulers/docker/plug-ins/)实现了Docker的provider.Provider存储Plugin接口,rexray/cinder最终通过rexray的cinder驱动去挂载cinder volume (https://github.com/thecodeteam/rexray/blob/master/libstorage/drivers/storage/cinder/storage/cinder_storage.go)。

什么是REX-Ray:

  • REX-Ray是一个开源的存储编排引擎(http://blog.daocloud.io/swarm-emc/), 进一步封装整合了不同的存储如Ceph, Cinder, EBS等,来主要为Docker, Mesos等容器来提供持续的存储访问, 似乎没有看到REX-Ray下挂到OpenStack Cinder的驱动(见: https://rexray.readthedocs.io/en/stable/)。
  • REX-Ray下可以直接挂ceph驱动, 见:http://www.stillhq.com/docker/000001.html和https://blog.thecodeteam.com/2017/01/27/rexray-ceph/
  • REX-Ray下也可以挂cinder驱动,然后通过cinder ceph驱动来支持ceph。见:https://github.com/thecodeteam/rexray/blob/master/libstorage/drivers/storage/cinder/storage/cinder_storage.go

Cinder不仅是给nova用的,也可以绕开nova单独使用,见https://specs.openstack.org/openstack/cinder-specs/specs/mitaka/use-cinder-without-nova.html :

cinder local-attach [--mountpoint /mnt/disk] [--multipath True] [--enforce-multipath True] [--mode rw] <volume_id>

如果通过rexray/cinder让Docker容器使用了cinder ceph volume的话,如果这个volume是有状态需要需要在容器和虚机间共享的话,这个volume也可以通过上面说的nova multiattach特性给nova instance使用的, 还可以使用这个特性’cinder local-attach’特性给non-nova instance使用。

备份网址

https://zhhuabj.github.io/2017/12/22/OpenStack-s-multiattach-Feature/

原创粉丝点击