使用GCE将GCS(云存储)用作文件系统

本文是对以下安装方法进行的中文翻译:
– Ubuntu和Debian(最新版本)
https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/docs/installing.md#ubuntu-and-debian-latest-releases

环境

    • Google Compute Engine + Ubuntu and Debian

 

    Google Cloud Storage

前提条件一项

    • GCE(Google Compute Engine)のインスタンスを作成済み。まだ作成されていない方はこちら

Cloud Storageのバケットを作成済み。まだ作成されていない方はこちら

准备前期工作

在停止GCE实例的情况下,更改实例的默认访问范围(权限)。
如果不进行此操作,则无法在GCE实例上操作Cloud Storage文件。

    1. 从VM实例的详细页面中选择“编辑”

 

    1. 将访问范围更改为“给予每个API的访问权限”

 

    将存储选项更改为“完全”(默认只有“读取”)

安装GCSFuse

通过使用GCSFuse,您可以在GCE实例上,将Cloud Storage作为共享文件夹,在GCE控制台上进行操作。与正常的文件系统一样,可以使用命令如ls、cp、mv、rm等对文件进行操作。

在上述页面中,提供了以下操作系统的安装步骤,但本文仅限于已经验证过的Ubuntu和Debian。敬请谅解。

    • ubuntu-1804-lts, ubuntu-1604-lts, and ubuntu-1404-lts

 

    • debian-8, debian-7

 

    • centos-7, centos-6

 

    • rhel-7, rhel-6

 

    • sles-12

 

    (2019年9月2日現在)

确认GCSFuse的更新信息并获取公钥。

启动GCE实例并进行SSH连接后,执行以下代码。
以下操作是为了检查当前Ubuntu和Debian版本是否有gcsfuse的更新,并设置apt-get。

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

安装GCSFuse

sudo apt-get update
sudo apt-get install gcsfuse

通过指定存储桶名称来挂载存储

指定云存储桶名称,将其挂载到新建文件夹中。
每次重新启动时,都需要执行 gcsfuse [bucket-name] [path] 操作。

mkdir mount
sudo gcsfuse [bucket-name] mount

总结

# install GCSFuse
export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update -y
sudo apt-get install gcsfuse -y

# mount bucket
mkdir mount
sudo gcsfuse [bucket-name] mount    # please set up [bucket-name]

请参考

云存储FUSE
https://cloud.google.com/storage/docs/gcs-fuse?hl=ja
GitHub – GoogleCloudPlatform/gcsfuse
https://github.com/GoogleCloudPlatform/gcsfuse

以上

广告
将在 10 秒后关闭
bannerAds