使用 goofys 挂载 S3 bucket 为文件系统

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 goofys 挂载 S3 bucket 为文件系统相关的知识,希望对你有一定的参考价值。

背景

公司的 gitlab 目前都是直接存储在物理盘上,为了确保数据不会丢失,需要重复多次备份到不同的地方,备份的过程中会有多次 IO,影响机器的性能,且随着数据量的增长,备份所需的时间也越来越长,因此需要寻找合适的存储方案。最先尝试 gitlab 推荐的 Minio,经过查阅官方文档,Minio 和 S3 类似,于是想到通过 goofys 将 S3 bucket 挂载到本地,当做文件系统来用,同时也尝试了 s3fs。

goofys 介绍

官方文档的介绍如下:

Goofys allows you to mount an S3 bucket as a filey system.

Its a Filey System instead of a File System because goofys strives for performance first and POSIX second. Particularly things that are difficult to support on S3 or would translate into more than one round-trip would either fail (random writes) or faked (no per-file permission). Goofys does not have an on disk data cache (checkout ​​catfs​​), and consistency model is close-to-open.

goofys 与 s3fs 的性能对比如下(github 上的性能对比图):

使用

goofys与s3fs性能对比

我们可以看到,在读写文件等各方面,goofys 的性能均优越于 s3fs,因此采用 goofys 将 s3 bucket 挂载到本地,当做本地文件系统来使用。


goofys 安装

本文使用 Go 从源代码构建安装 goofys

一、go 安装

yum install go

安装的 go 版本为:go1.10.3 linux/amd64,由于后续在安装的过程中,因为 go 的版本过低,导致安装失败,因此将 go 的版本升级为 go1.16.4 linux/amd64,操作步骤如下:

1、登录 ​​Go国内下载网址​​ ,当前为 centos 系统,下载 ​​go1.16.4.linux-amd64.tar.gz​

使用

2、找到之前 go 版本存放路径,使用命令 whereis go;

3、升级为新版本

# 将旧版本备份
cd /usr/local
mv go go.1.10.3


# 将新版本go压缩包解开当前目录
tar zxf go1.16.4.linux-amd64.tar.gz


# 目录下会释放出go目录
ls -l go


# 将 /usr/local/go/bin 目录添加至PATH环境变量
export PATH=$PATH:/usr/local/go/bin

4、检查 go 版本,go version

使用


二、goofys 从源代码构建

$ export GOPATH=$HOME/work
$ go get github.com/kahing/goofys
$ go install github.com/kahing/goofys


goofys 挂载 s3 bucket

1、将 s3 认证的 key 等信息设置为环境变量

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=us-west-2

2、新建挂载点 /mnt

mkdir /mnt

3、挂载

/usr/local/bin/goofys --debug_fuse --debug_s3 --region beijing --endpoint endpoint bucket /mnt

4、查看挂载是否成功 df -h 命令


参考文档

1、goofys github 地址: ​​https://github.com/kahing/goofys​

2、aws cli 设置环境变量:​​https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html​


以上是关于使用 goofys 挂载 S3 bucket 为文件系统的主要内容,如果未能解决你的问题,请参考以下文章

无法在goofys挂载的文件夹中生成zip文件

如何使用开源小工具goofys实现自动挂载对象存储桶到Linux?

goofys基本用法

goofys基本用法

【ceph】s3cmd 创建bucket名称大小写问题

Oss挂载Nextcloud存储网盘