S3FS 是一个开源工具,可以将 S3 对象存储通过 FUSE 挂载到本地,以用户熟悉的形式如在本地磁盘一样进行读写访问。除了 AWS S3,它还支持所有兼容 S3 API 的对象存储,比如七牛云对象存储 Kodo。通过配置,您可以通过 S3FS 管理您在七牛云对象存储的资源。
参考官方介绍:S3FS
安装 S3FS
大部分 Linux 操作系统都提供 S3FS 的安装包。
-
Amazon Linux EPEL:
sudo amazon-linux-extras install epel sudo yum install s3fs-fuse -
Arch Linux:
sudo pacman -S s3fs-fuse -
Debian 9 和 Ubuntu 16.04 或更新版本:
sudo apt install s3fs -
Fedora 27 或更新版本:
sudo dnf install s3fs-fuse -
Gentoo:
sudo emerge net-fs/s3fs -
RHEL 和 CentOS 7 或更新版本 EPEL:
sudo yum install epel-release sudo yum install s3fs-fuse -
SUSE 12 和 openSUSE 42.1 或更新版本:
sudo zypper install s3fs -
macOS 10.12 或更新版本,通过 Homebrew:
brew install --cask macfuse brew install gromgit/fuse/s3fs-mac -
FreeBSD:
pkg install fusefs-s3fs -
UNIX / Linux 支持自行编译
- 准备以下依赖
fuse >= 2.8.4automakegcc-c++makelibcurllibxml2opensslmime.types
- 使用以下命令编译 S3FS
git clone https://github.com/s3fs-fuse/s3fs-fuse.git cd s3fs-fuse ./autogen.sh ./configure make sudo make install
- 准备以下依赖
配置 S3FS
配置 AWS Credentials
S3FS 默认使用 ${HOME}/.passwd-s3fs 作为当前用户的 AWS Credentials,如果不存在,则使用 /etc/passwd-s3fs 作为系统的 AWS Credentials。
通过以下命令设置 ${HOME}/.passwd-s3fs
echo "${QINIU_ACCESS_KEY_ID}:${QINIU_SECRET_KEY}" > "${HOME}/.passwd-s3fs"
chmod 600 "${HOME}/.passwd-s3fs"
启动 S3FS
s3fs "${BUCKET}" "${MOUNTPOINT}" -o url=https://s3.cn-east-1.qiniucs.com # 这里以华东-浙江区为例,如果 $BUCKET 为其他区域,则填写该区域的 S3 服务域名
其中,${BUCKET} 为指定存储空间,${MOUNTPOINT} 为指定目录。该命令中 url 需要填写为 S3 服务域名,可以参考 服务域名 查看七牛云对象存储各区域的 S3 服务地址。
命令执行成功后,S3FS 将作为守护进程启动,访问 $MOUNTPOINT 即可读写指定 Bucket 中的文件。
自动挂载 S3FS
将 S3FS 配置追加到 /etc/fstab 中
${BUCKET} ${MOUNTPOINT} fuse.s3fs _netdev,allow_other,url=https://s3.cn-east-1.qiniucs.com 0 0
调试 S3FS
采用如下命令,将直接在 Shell 中启动 S3FS,并直接输出 S3FS 日志。
s3fs "${BUCKET}" "${MOUNTPOINT}" -o url=https://s3.cn-east-1.qiniucs.com -f -o dbglevel=info -o curldbg
其他选项可以参考 Ubuntu Manpage 中的 s3fs 页面。