Search Posts

挂载google cloud storage到服务器

内容纲要

创建服务账号和密钥

  1. 前往 Google Cloud Console 并登录。
  2. 转到 “IAM 和管理” > “服务帐号”。
  3. 创建服务帐号,选择两个权限owner\Storage Admin然后继续
  4. 选择您的服务帐号,然后生成新的密钥。
  5. 下载密钥文件(JSON 格式)并将其保存在安全的位置。
  6. 上传密钥到 /opt/key.json
  7. 检查账号是否在权限中

安装Cloud Storage FUSE

官方文档 https://cloud.google.com/storage/docs/gcsfuse-install

sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
      https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

sudo yum install fuse
sudo yum install gcsfuse

挂载

官方文档:https://cloud.google.com/storage/docs/gcsfuse-mount

# 创建一个名为 /folder 的新目录,用作将 Google Cloud Storage bucket 挂载的目标位置
mkdir /folder

# 使用 Vim 编辑器打开 /etc/fstab 文件,这个文件用于配置系统引导时自动挂载的文件系统列表
vim /etc/fstab

# 在 /etc/fstab 文件中添加以下行,配置将 Google Cloud Storage 存储桶挂载到 /folder 目录
# bucket-name 是您的 Google Cloud Storage 存储桶的名称
# /folder 是您要将存储桶挂载到的本地目录
# gcsfuse 是文件系统类型
# rw 表示挂载的权限为读写
# allow_other 表示允许其他用户访问挂载的文件系统
# implicit_dirs 表示允许隐式创建目录
# key_file=/opt/key.json 指定了密钥文件的位置
# 0 0 是挂载选项,用于确定是否应备份或检查此文件系统
bucket-name /folder gcsfuse rw,allow_other,implicit_dirs,key_file=/opt/key.json 0 0

# 运行 mount -a 命令以重新加载 /etc/fstab 文件,并将其中列出的所有文件系统都挂载到系统中
mount -a

English Version

Mounting google cloud storage to a server

Create a service account and key

  1. Go to the Google Cloud Console and log in.
  2. Go to IAM and administration> Service accounts ".
  3. Create the service account, select two permissions owner\Storage Admin and continue
  4. Select your service account and generate a new key.
  5. Download the key File (JSON format) and save it in a safe location.
  6. Upload key to/opt/key.json
  7. Check whether the account is in the permission

Install Cloud Storage FUSE

Official Document https://cloud.google.com/storage/docs/gcsfuse-install

sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck = 0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
      https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

sudo yum install fuse
sudo yum install gcsfuse

Mount

Official Document: https://cloud.google.com/storage/docs/gcsfuse-mount

# Create a new directory called/folder to use as the destination for mounting the Google Cloud Storage bucket
mkdir /folder

# Use the Vim editor to open the/etc/fstab file, which is used to configure the list of file systems that are automatically mounted during system boot.
vim /etc/fstab

# Add the following line to the/etc/fstab file and configure to mount the Google Cloud Storage bucket to the/folder directory
# bucket-name is the name of your Google Cloud Storage bucket
# /folder is the local directory where you want to mount the bucket
# gcsfuse is the file system type
# rw indicates that the Mount permission is read and write
# allow_other means to allow other users to access the mounted file system
# implicit_dirs to allow implicit creation of directories
# key_file =/opt/key.json specifies the location of the key file
#0 0 is the mount option to determine if this file system should be backed up or checked
bucket-name /folder gcsfuse rw,allow_other,implicit_dirs,key_file=/opt/key.json 0 0

# Run the mount -a command to reload the/etc/fstab file and mount all the file systems listed in it to the system
mount -a

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注