更新:截至 2020 年 6 月 16 日可用
As per 另一个答案 https://stackoverflow.com/a/58890617/3618671作者:Matthew Lenz,其功能为创建多写入器永久磁盘 https://cloud.google.com/sdk/gcloud/reference/beta/compute/disks/create#--multi-writer可用,但仍处于 alpha 状态(尽管它被记录为处于 beta 轨道)并且需要特殊的每个项目启用。
Note: 这个 GitHub 问题 https://github.com/GoogleCloudPlatform/magic-modules/pull/3911指出该功能仍处于 alpha 阶段,尽管它被标记为 beta 版。如果您想尽早使用此功能,您可以通过 Cloud Console 提交反馈,为您的项目请求该功能,但不保证一定会启用。
假设您的项目有权使用此功能(或者该功能变为公共访问),请注意它有一些警告:
--multi-writer
以多写入器模式创建磁盘,以便可以将其附加到多个虚拟机的读写访问权限。只能与区域 SSD 永久磁盘一起使用。多写入模式下的磁盘不支持调整大小和快照操作。
您可以通过以下方式使用它:
$ gcloud beta compute disks create DISK_NAME --multi-writer [...]
请注意注意事项:
- 仅限区域 SSD 永久性磁盘
- 没有调整磁盘大小
- 没有快照
如果您不接受这些权衡,请参阅原始答案(如下),其中有一长串建议的存储替代方案,用于在多个 GCE VM 之间共享数据。
原始答案(2020-06-16之前有效)
不,这是不可能的,因为您引用的文档 https://cloud.google.com/compute/docs/disks/#flexibility在撰写本文时说(自更新后):
但是,如果您将永久磁盘附加到多个实例,则所有实例都必须以只读模式附加永久磁盘。
此后,文档已重新整理;新文档位于不同的网址 https://cloud.google.com/compute/docs/disks/add-persistent-disk#use_multi_instances但内容相同:
您可以将非根永久磁盘以只读模式附加到多个虚拟机实例,这样您就可以在多个实例之间共享静态数据。从一个永久磁盘在多个实例之间共享静态数据比将数据复制到单个实例的唯一磁盘更便宜。
如果将永久磁盘附加到多个实例,则所有这些实例都必须以只读模式附加永久磁盘。无法以读写模式将永久磁盘附加到多个实例。如果您需要在多个实例之间共享动态存储空间,请将您的实例连接到云储存 https://cloud.google.com/compute/docs/disks/gcs-buckets or 创建网络文件服务器 https://cloud.google.com/solutions/filers-on-compute-engine.
如果您有一个永久磁盘,其中包含要在多个实例之间共享的数据,请将其与任何读写实例分离,然后以只读模式将其附加到一个或多个实例。
这意味着您不能让一个实例具有写访问权限,而另一个实例具有只读访问权限。
如果您想在它们之间共享数据,则需要使用永久磁盘以外的其他工具。以下是一些可能的解决方案。
您可以使用以下任意一项托管/托管服务:
-
Google Cloud Filestore https://cloud.google.com/filestore/ — perhaps closest to what you're looking for, as it provides an NFSv3 file system
- 您还可以使用GCP 上的 Elastifile https://www.elastifile.com/google-cloud/ as a 全面管理的服务 https://www.elastifile.com/early-access-gcp/;注意GCP 于 2019 年 7 月收购了 Elastifile https://cloud.google.com/blog/topics/inside-google-cloud/expanding-our-enterprise-file-storage-offerings-to-simplify-the-management-and-scaling-of-data
- 谷歌云数据存储 https://cloud.google.com/datastore/
-
谷歌云存储 https://cloud.google.com/storage/,您可以通过 GCS API(JSON 或 XML)使用它,也可以使用gcsfuse https://github.com/googlecloudplatform/gcsfuse作为块设备
- 谷歌云大表 https://cloud.google.com/bigtable/
- 谷歌云SQL https://cloud.google.com/sql/
或者,您可以运行你自己的:
- 自行管理或第三方管理文件服务器 https://cloud.google.com/solutions/filers-on-compute-engine解决方案,包括 NetApp 和 Panzura
- 自我管理Elastifile存储部署 https://console.cloud.google.com/marketplace/details/elastifile/elastifile-storage(对于完全托管,请参阅上一节的链接)
- 数据库(无论是 SQL 还是 NoSQL)
- 分布式文件系统,例如Ceph https://en.wikipedia.org/wiki/Ceph_(software), GlusterFS https://en.wikipedia.org/wiki/GlusterFS, OrangeFS https://en.wikipedia.org/wiki/OrangeFS, ZFS https://en.wikipedia.org/wiki/ZFS, etc.
- 文件服务器,例如NFS https://help.ubuntu.com/14.04/serverguide/network-file-system.html or SAMBA https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20%28Command-line%20interface/Linux%20Terminal%29%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!
- 单个VM作为数据存储节点,并使用sshfs http://fuse.sourceforge.net/sshfs.html从想要访问该数据的其他虚拟机创建 FUSE 安装