目录
Please enable Javascript to view the contents

S3fs — 利用 S3 作为弹性文件存储方案

 ·  ☕ 1 分钟

重要

s3fs 通过 FUSE 将 S3 Bucket 挂载为本地文件系统,支持容器内以非特权用户挂载。

1. 安装

发行版命令
Debian / Ubuntusudo apt install s3fs
RHEL / CentOSsudo yum install epel-release && sudo yum install s3fs-fuse

2. 挂载

2.1 主机挂载

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs
sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
mkdir /mnt/s3

s3fs <bucket-name> /mnt/s3 \
  -o _netdev \
  -o allow_other \
  -o use_path_request_style \
  -o url=http://obs.cn-north-4.myhuaweicloud.com

2.2 容器内挂载

1
2
3
4
5
6
7
8
docker run -d --name app \
  --cap-add mknod --cap-add sys_admin \
  --security-opt apparmor:unconfined \
  --device=/dev/fuse \
  app:latest

docker exec -it -u 1000 app bash
# 在容器内执行 2.1 的挂载步骤

容器挂载需要 --cap-add sys_admin--device=/dev/fuse

3. 参数说明

参数说明示例
use_path_request_style非 AWS 的 S3 实现(华为云 OBS、Minio)必须指定
urlS3 服务端点http://obs.cn-north-4.myhuaweicloud.com
allow_other允许非 root 用户访问挂载点
user_allow_other/etc/fuse.conf 中启用

4. 常见问题

问题方案
fuse: device not foundK8s 容器需要特权模式
节点需要安装 fuse 吗?不需要,fuse 是用户态组件,容器内安装即可
.passwd-s3fs 权限错误chmod 600 ~/.passwd-s3fs
写操作性能差s3fs 不适合高频写场景,每次写都会重新上传文件

参考

分享

Hex
作者
Hex
CloudNative Developer