Goofys 是一个用 Go 语言编写的高性能云存储挂载工具,能够将云对象存储(如 AWS S3、Azure Blob、Google Cloud Storage 等)挂载为本地文件系统。
| 特性 | 说明 |
|---|---|
| 高性能 | 针对云存储特性优化,比传统 S3 文件系统(s3fs)快数倍 |
| 多后端支持 | 支持 AWS S3、Azure Blob、Azure Data Lake、Google Cloud Storage、MinIO 等 |
| 配置驱动 | 支持通过配置文件定义多个挂载点,实现一键部署 |
| 服务模式 | 支持注册为系统服务,开机自动启动 |
| 类 POSIX | 兼容大部分 POSIX 文件操作 |
Goofys 追求性能优先,而非完全的 POSIX 兼容。这是因为云对象存储与本地文件系统存在本质差异:
如需本地缓存加速,可配合 catfs 使用。
fuse,macOS 需要安装 osxfuse)# Linux x86_64
curl -L https://github.com/kahing/goofys/releases/latest/download/goofys -o /usr/local/bin/goofys
chmod +x /usr/local/bin/goofys
# macOS (需要先安装 osxfuse)
brew install goofys
brew cask install osxfuse brew install goofys
export GOPATH=$HOME/work
go install github.com/kahing/goofys@latest
创建 AWS 凭证文件 ~/.aws/credentials:
[default]
aws_access_key_id = AKID1234567890
aws_secret_access_key = MY-SECRET-KEY
提示:也支持通过环境变量
AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY配置。
# 基础挂载
goofys bucket-name /mnt/s3
# 挂载带前缀的路径
goofys bucket-name:prefix /mnt/s3
# 后台运行
goofys bucket-name /mnt/s3 &
对于生产环境,推荐使用配置文件管理多个挂载点。
Goofys 会按以下顺序查找配置文件:
--config /path/to/config.toml~/.config/goofys/config.toml~/.goofys.toml/etc/goofys/config.toml# example/config.toml
# 日志级别: debug, info, warn, error
debug = false
# 是否后台运行(交互模式生效)
detach = true
# 默认文件权限
uid = 1000
gid = 1000
dir_mode = "0755"
file_mode = "0644"
# 挂载选项
mount_options = ["allow_other"]
# 定义挂载点
[mounts.my-s3]
status = true # 启用此挂载
backend = "s3" # 后端类型
bucket = "my-bucket" # 存储桶名称
mount_path = "/mnt/s3" # 本地挂载路径
# 凭证(也可以通过环境变量或 AWS CLI 配置)
# aws_access_key_id = "xxx"
# aws_secret_access_key = "xxx"
# 初始化配置文件(生成默认配置)
goofys config init
# 初始化到指定路径
goofys config init /etc/goofys/config.toml
# 验证配置文件
goofys config validate
# 查看配置解析路径
goofys config path
将 Goofys 注册为系统服务,实现开机自动启动:
# 安装服务
goofys service install /etc/goofys/config.toml
# 启动服务
goofys service start
# 查看状态
goofys service status
在 /etc/fstab 中添加:
goofys#bucket /mnt/s3 fuse _netdev,allow_other,--file-mode=0666,--dir-mode=0777 0 0
[mounts.s3]
backend = "s3"
bucket = "my-bucket"
# 可选:指定区域
# region = "us-west-2"
[mounts.minio]
backend = "minio"
bucket = "my-minio-bucket"
endpoint = "https://minio.example.com:9000"
signature_version = "v4"
[mounts.az]
backend = "azblob"
bucket = "my-container"
# Azure 连接字符串(推荐通过环境变量 AZURE_STORAGE_CONNECTION_STRING 设置)
# connection_string = "xxx"
[mounts.adl]
backend = "adlgen2"
bucket = "my-filesystem"
endpoint = "https://myaccount.dfs.core.windows.net"
[mounts.gcs]
backend = "gcs"
bucket = "my-bucket"
# 使用应用默认凭证(ADC)
# credentials_file = "/path/to/service-account.json"
| 参数 | 说明 | 默认值 |
|---|---|---|
-f, --foreground | 前台运行 | 后台运行 |
--debug | 开启调试日志 | 关闭 |
--uid | 文件所有者 UID | 当前用户 |
--gid | 文件所属组 GID | 当前用户组 |
--file-mode | 文件权限 | 0644 |
--dir-mode | 目录权限 | 0755 |
--region | AWS 区域 | 自动检测 |
--endpoint | 自定义 S3 兼容端点 | AWS S3 |
--stat-cache-ttl | 元数据缓存时间 | 1小时 |
--type-cache-ttl | 类型缓存时间 | 1小时 |
在 EC2 m5.4xlarge(us-west-2a)测试,连接到 us-west-2 的 S3 存储桶:

详细测试方法见 bench/bench.sh
由于云存储与本地文件系统的本质差异,Goofys 存在以下非 POSIX 兼容行为:
| 限制 | 说明 |
|---|---|
| 顺序写入 | 仅支持追加写入,不支持随机写入 |
| 权限模拟 | 不存储文件权限,使用全局配置 --file-mode |
| 无链接 | 不支持符号链接和硬链接 |
| 时间戳 | ctime、atime 始终等于 mtime |
| 目录重命名 | 无法重命名包含超过 1000 个子项的目录 |
| 删除行为 | unlink 即使文件不存在也返回成功 |
| 同步 | fsync 被忽略,文件仅在关闭时刷新 |
Q: 挂载后文件权限显示异常?
A: 使用 --uid、--gid、--file-mode、--dir-mode 参数指定。
Q: 挂载点无法访问? A: 检查 FUSE 是否安装,以及是否有足够权限。
Q: 如何提升性能?
A: 调整缓存参数:--stat-cache-ttl 1h --type-cache-ttl 1h
Q: 支持哪些 Linux 发行版? A: 主流发行版(Ubuntu、Debian、CentOS、RHEL、Fedora)均支持。
Apache License 2.0
Copyright (C) 2015 - 2019 Ka-Hing Cheung