内容目录
创建服务账号和密钥
- 前往 Google Cloud Console 并登录。
- 转到 “IAM 和管理” > “服务帐号”。
- 创建服务帐号,选择两个权限owner\Storage Admin然后继续
- 选择您的服务帐号,然后生成新的密钥。
- 下载密钥文件(JSON 格式)并将其保存在安全的位置。
- 上传密钥到 /opt/key.json
- 检查账号是否在权限中
安装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
或者执行shell命令
gcsfuse --key-file /opt/key.json --implicit-dirs --allow-other bucket-name /folder
文件权限默认644 目录去权限默认755
需要权限更高
gcsfuse --key-file /opt/key.json --implicit-dirs --allow-other --file-mode 777 --dir-mode 777 bucket-name /folder
非root用户挂载去掉–allow-other
gcsfuse --key-file /opt/key.json --implicit-dirs --file-mode 777 --dir-mode 777 bucket-name /folder
English Version
Mounting google cloud storage to a server
Create a service account and key
- Go to the Google Cloud Console and log in.
- Go to IAM and administration> Service accounts ".
- Create the service account, select two permissions owner\Storage Admin and continue
- Select your service account and generate a new key.
- Download the key File (JSON format) and save it in a safe location.
- Upload key to/opt/key.json
- 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
Or execute shell command
gcsfuse --key-file /opt/key.json --implicit-dirs --allow-other bucket-name /folder
File permission defaults to 644, directory permission defaults to 755
Requires higher permission
gcsfuse --key-file /opt/key.json --implicit-dirs --allow-other --file-mode 777 --dir-mode 777 bucket-name /folder
Non-root user mount remove –allow-other
gcsfuse --key-file /opt/key.json --implicit-dirs --file-mode 777 --dir-mode 777 bucket-name /folder
Official parameter description document: https://cloud.google.com/storage/docs/gcsfuse-cli?hl=zh-cn
近期评论