简体   繁体   English

在 Google Compute Engine 虚拟机之间共享一个永久性磁盘

[英]Share a persistent disk between Google Compute Engine VMs

From Google's documentation:来自谷歌的文档:

It is possible to attach a persistent disk to more than one instance.可以将一个永久性磁盘附加到多个实例。 However, if you attach a persistent disk to multiple instances, all instances must attach the persistent disk in read-only mode.但是,如果您将一个永久性磁盘附加到多个实例,则所有实例都必须以只读模式附加永久性磁盘。 It is not possible to attach the persistent disk to multiple instances in read-write mode.无法以读写模式将永久性磁盘附加到多个实例。

If you attach a persistent disk in read-write mode and then try to attach the disk to subsequent instances, Google Compute Engine returns an error.如果您以读写模式附加永久性磁盘,然后尝试将该磁盘附加到后续实例,Google Compute Engine 将返回错误。

So, I need to have a share persistent-disk as frontend for all my compute engine, good, how can you write on this shared disk?所以,我需要有一个共享持久磁盘作为我所有计算引擎的前端,很好,你怎么能在这个共享磁盘上写?

My guess (I hope) is a read/write persistent-disk can be attached only with 1 compute engine but this same disk can be share in read only to others VMs, is thats right?我的猜测(我希望)是一个读/写持久磁盘只能连接 1 个计算引擎,但同一个磁盘可以只读共享给其他VM,是吗?

Lets say I have 2 Compute Engine VMs and 2 persistent disks, is this flow is possible?假设我有 2 个 Compute Engine 虚拟机和 2 个永久性磁盘,这个流程是否可行?

  • compute1 read/write disk1 and read only disk2计算 1 读/写磁盘 1 和只读磁盘 2
  • compute2 read/write disk2 and read only disk1计算 2 读/写磁盘 2 和只读磁盘 1

Update: this is available as of 2020-06-16更新:自 2020-06-16 起可用

As per another answer by Matthew Lenz, the functionality for creating multi-writer persistent disks is available, but it's still in alpha status (even though it's documented as being in the beta track) and requires special per-project enablement.根据 Matthew Lenz 的另一个答案创建多写入器永久性磁盘的功能可用,但它仍处于 alpha 状态(即使它被记录为处于 beta 轨道中)并且需要特殊的每个项目启用。

Note: This GitHub issue notes that the functionality is still in alpha, even though it's labelled as beta.注意: 此 GitHub 问题指出该功能仍处于 alpha 阶段,即使它被标记为 beta。 You can submit feedback via Cloud Console to request it for your project if you'd like to get early access to this functionality, but it's not guaranteed to be enabled.如果您想抢先体验此功能,您可以通过 Cloud Console 提交反馈以请求为您的项目提供反馈,但不保证会启用该功能。


Assuming your project has the permissions to use this feature (or the feature becomes public-access), note that it comes with some caveats:假设您的项目有权使用此功能(或该功能成为公共访问权限),请注意它带有一些警告:

--multi-writer

Create the disk in multi-writer mode so that it can be attached with read-write access to multiple VMs.在多写入器模式下创建磁盘,以便它可以通过读写访问连接到多个 VM。 Can only be used with zonal SSD persistent disks.只能与地区性 SSD 永久性磁盘一起使用。 Disks in multi-writer mode do not support resize and snapshot operations.多写入模式的磁盘不支持调整大小和快照操作。

You can use this via:您可以通过以下方式使用它:

$ gcloud beta compute disks create DISK_NAME --multi-writer [...]

Note the caveats:注意注意事项:

  • zonal SSD persistent disks only仅限区域 SSD 永久性磁盘
  • no disk resizing没有磁盘调整大小
  • no snapshots没有快照

If these trade-offs are not acceptable to you, see the original answer (below) which has a long list of recommended storage alternatives for sharing data between multiple GCE VMs.如果您不能接受这些权衡,请参阅原始答案(如下),其中有一长串推荐的存储替代方案,用于在多个 GCE 虚拟机之间共享数据。


Original answer (valid prior to 2020-06-16)原答案(2020-06-16 之前有效)

No, this is not possible, as the documentation that you cited at the time of writing said (since updated):不,这是不可能的,正如在撰写本文时引用文档所说(自更新后):

However, if you attach a persistent disk to multiple instances, all instances must attach the persistent disk in read-only mode.但是,如果您将一个永久性磁盘附加到多个实例,则所有实例都必须以只读模式附加永久性磁盘。

The documentation has been re-arranged since then;从那时起,文档已重新整理; the new docs are at a different URL but with the same content:新文档位于不同的 URL但具有相同的内容:

You can attach a non-root persistent disk to more than one virtual machine instance in read-only mode, which allows you to share static data between multiple instances.您可以在只读模式下将非根永久性磁盘附加到多个虚拟机实例,这允许您在多个实例之间共享静态数据。 Sharing static data between multiple instances from one persistent disk is cheaper than replicating your data to unique disks for individual instances.从一个永久性磁盘在多个实例之间共享静态数据比将数据复制到单个实例的唯一磁盘更便宜。

If you attach a persistent disk to multiple instances, all of those instances must attach the persistent disk in read-only mode.如果您将一个永久性磁盘附加到多个实例,则所有这些实例都必须以只读模式附加永久性磁盘。 It is not possible to attach the persistent disk to multiple instances in read-write mode.无法以读写模式将永久性磁盘附加到多个实例。 If you need to share dynamic storage space between multiple instances, connect your instances to Cloud Storage or create a network file server .如果您需要在多个实例之间共享动态存储空间,请将您的实例连接到Cloud Storage创建网络文件服务器

If you have a persistent disk with data that you want to share between multiple instances, detach it from any read-write instances and attach it to one or more instances in read-only mode.如果您有一个包含要在多个实例之间共享数据的永久性磁盘,请将其与任何读写实例分离,并以只读模式将其附加到一个或多个实例。

which means you cannot have one instance have write access while another has read-only access.这意味着您不能让一个实例具有写访问权限,而另一个实例具有只读访问权限。

If you want to share data between them, you need to use something other than Persistent Disk.如果要在它们之间共享数据,则需要使用 Persistent Disk 以外的其他东西。 Below are some possible solutions.下面是一些可能的解决方案。

You can use any of the following hosted/managed services :您可以使用以下任何托管/托管服务

Alternatively, you can run your own :或者,您可以运行自己的

  • self-managed or third-party managed file servers solutions, including NetApp and Panzura自我管理或第三方管理的文件服务器解决方案,包括 NetApp 和 Panzura
  • self-managed Elastifile storage deployment (for fully-managed, see previous section for the link)自我管理的Elastifile 存储部署(对于完全管理,请参阅上一节的链接)
  • database (whether SQL or NoSQL)数据库(无论是 SQL 还是 NoSQL)
  • distributed filesystem such as Ceph , GlusterFS , OrangeFS , ZFS , etc.分布式文件系统,如CephGlusterFSOrangeFSZFS等。
  • file server such as NFS or SAMBA文件服务器,如NFSSAMBA
  • single VM as a data storage node, and use sshfs to create a FUSE mount from other VMs that want to access that data单个虚拟机作为数据存储节点,并使用sshfs从想要访问该数据的其他虚拟机创建 FUSE 挂载

GCP has alpha functionality for 'multi-write' persistent disks. GCP 具有用于“多写入”永久性磁盘的 Alpha 功能。 It's been in alpha for quite a long time so who knows if it'll make it to beta or ga any time soon.它已经处于 alpha 阶段很长时间了,所以谁知道它是否会很快进入 beta 或 ga。 Here is a link to the documentation.这是文档的链接。 https://cloud.google.com/sdk/gcloud/reference/beta/compute/disks/create#--multi-writer EDIT: 2020-06-16. https://cloud.google.com/sdk/gcloud/reference/beta/compute/disks/create#--multi-writer编辑:2020-06-16。 This has been promoted to beta.这已升级为测试版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM