s3fs-fuse 完整操作手册
简介
s3fs 是一个基于 FUSE (Filesystem in Userspace) 的文件系统,允许将 Amazon S3 或兼容 S3 API 的对象存储挂载为本地文件系统。它使您能够像操作本地文件一样操作 S3 存储桶中的文件和目录。
主要特性
- 支持 POSIX 文件系统的子集,包括读/写文件、目录、符号链接、模式、uid/gid 和扩展属性
- 兼容 Amazon S3 和其他基于 S3 的对象存储
- 支持随机写入和追加
- 通过多部分上传支持大文件
- 通过服务器端复制支持重命名
- 可选的服务器端加密
- 通过 MD5 哈希确保数据完整性
- 内存中的元数据缓存
- 本地磁盘数据缓存
- 用户指定的区域,包括 Amazon GovCloud
- 通过 v2 或 v4 签名认证
系统要求
- Linux、macOS 或 FreeBSD 系统
- FUSE 库和内核模块
- libcurl 7.16 或更高版本
- libxml2
安装
通过包管理器安装
Debian/Ubuntu
sudo apt updatesudo apt install s3fsRHEL/CentOS/Fedora
sudo yum install epel-releasesudo yum install s3fs-fuseArch Linux
sudo pacman -S s3fs-fusemacOS (通过 Homebrew)
brew install --cask macfusebrew install gromgit/fuse/s3fs-macFreeBSD
pkg install fusefs-s3fs从源码编译
git clone https://github.com/s3fs-fuse/s3fs-fuse.gitcd s3fs-fuse./autogen.sh./configuremakesudo make install认证配置
方法一: AWS 凭证文件
s3fs 支持标准的 AWS 凭证文件格式,位于 ${HOME}/.aws/credentials:
[default]aws_access_key_id = YOUR_ACCESS_KEY_IDaws_secret_access_key = YOUR_SECRET_ACCESS_KEY方法二: 密码文件
创建密码文件并设置正确的权限:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fschmod 600 ${HOME}/.passwd-s3fs对于多个 bucket:
bucket1:ACCESS_KEY_ID_1:SECRET_ACCESS_KEY_1bucket2:ACCESS_KEY_ID_2:SECRET_ACCESS_KEY_2系统范围的密码文件:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > /etc/passwd-s3fschmod 640 /etc/passwd-s3fs方法三: 环境变量
export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_IDexport AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEYexport AWS_SESSION_TOKEN=YOUR_SESSION_TOKEN # 可选,用于临时凭证方法四: IAM 角色
在 EC2 实例上使用 IAM 角色:
s3fs mybucket /mnt/s3 -o iam_role=auto指定特定 IAM 角色:
s3fs mybucket /mnt/s3 -o iam_role=my-role-name基本用法
手动挂载
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs使用环境变量
export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_IDexport AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEYs3fs mybucket /path/to/mountpoint指定子目录
s3fs mybucket:/subdir/path /path/to/mountpoint使用 AWS 凭证配置文件
s3fs mybucket /path/to/mountpoint -o profile=myprofile卸载
fusermount -u /path/to/mountpoint命令行参数详解
通用选项
-h / --help
显示帮助信息。
s3fs -h--version
打印版本信息。
s3fs --version-f
FUSE 前台选项,不作为守护进程运行。
s3fs mybucket /mnt/s3 -f-d
调试模式,等同于 dbglevel=info 和 -f。
s3fs mybucket /mnt/s3 -d挂载选项
认证相关
passwd_file=<file>
指定密码文件路径,优先级高于 ${HOME}/.passwd-s3fs 和 /etc/passwd-s3fs。
s3fs mybucket /mnt/s3 -o passwd_file=/path/to/passwd-s3fsprofile=<profile_name>
从 ${HOME}/.aws/credentials 中选择特定的配置文件进行认证。
s3fs mybucket /mnt/s3 -o profile=productioniam_role[=<role_name>]
使用 IAM 角色认证。如果不指定角色名或使用 auto,会自动使用实例上的 IAM 角色。
s3fs mybucket /mnt/s3 -o iam_role=autoecs
启用 ECS 容器凭证元数据地址查询,而不是实例元数据地址。
s3fs mybucket /mnt/s3 -o ecsibm_iam_auth
使用 IBM IAM 认证。在此模式下,AWSAccessKey 和 AWSSecretKey 将分别用作 IBM 的 Service-Instance-ID 和 APIKey。
s3fs mybucket /mnt/s3 -o ibm_iam_authibm_iam_endpoint=<url>
设置 IBM IAM 认证使用的 URL,默认为 <https://iam.cloud.ibm.com>。
s3fs mybucket /mnt/s3 -o ibm_iam_endpoint=https://iam.cloud.ibm.comcredlib=<library_path>
指定处理包含认证令牌的凭证的共享库。
s3fs mybucket /mnt/s3 -o credlib=/usr/lib/s3fs-cred-plugin.socredlib_opts=<options>
指定在加载和初始化 credlib 中指定的共享库时传递的选项。
s3fs mybucket /mnt/s3 -o credlib="option1=value1,option2=value2"网络和连接相关
url=<url>
设置访问 S3 使用的 URL。如果要用 HTTP,可以设置为 url=<http://s3.amazonaws.com>。
s3fs mybucket /mnt/s3 -o url=https://s3.amazonaws.comendpoint=<region>
设置签名版本 4 使用的端点。默认使用 us-east-1 区域。
s3fs mybucket /mnt/s3 -o endpoint=ap-northeast-1host=<hostname>
允许覆盖默认的 Amazon S3 主机名。
s3fs mybucket /mnt/s3 -o host=s3.ap-northeast-1.amazonaws.comservicepath=<path>
当非 Amazon 主机需要前缀时设置服务路径。
s3fs mybucket /mnt/s3 -o servicepath=/s3connect_timeout=<seconds>
连接超时时间,默认为 300 秒。
s3fs mybucket /mnt/s3 -o connect_timeout=60readwrite_timeout=<seconds>
读/写活动超时时间,默认为 120 秒。
s3fs mybucket /mnt/s3 -o readwrite_timeout=300proxy=[scheme://]hostname[:port]
指定 S3 服务器的代理。如果省略端口号,HTTPS 协议使用 443,其他协议使用 1080。
s3fs mybucket /mnt/s3 -o proxy=http://proxy.example.com:8080proxy_cred_file=<file>
指定描述代理用户名和密码的文件。用户名和密码仅对 HTTP 协议有效。
s3fs mybucket /mnt/s3 -o proxy=http://proxy.example.com:8080 -o proxy_cred_file=/etc/s3fs-proxyipresolve=<type>
选择连接时使用的 IP 地址类型。默认是 whatever(可以使用所有 IP 版本),可设置为 IPv4 或 IPv6。
s3fs mybucket /mnt/s3 -o ipresolve=IPv4max_stat_cache_size=<entries>
stat 缓存和符号链接缓存中的最大条目数,默认为 100,000 条目(约 40MB)。
s3fs mybucket /mnt/s3 -o max_stat_cache_size=200000stat_cache_expire=<seconds>
指定 stat 缓存和符号链接缓存中条目的过期时间(秒),默认为 900 秒。
s3fs mybucket /mnt/s3 -o stat_cache_expire=1800stat_cache_interval_expire=<seconds>
基于最后一次访问时间的缓存过期时间,默认为 900 秒。此选项与 stat_cache_expire 互斥。
s3fs mybucket /mnt/s3 -o stat_cache_interval_expire=600disable_noobj_cache
默认情况下,s3fs 会记忆对象不存在直到 stat 缓存超时。禁用此选项可避免缓存陈旧。
s3fs mybucket /mnt/s3 -o disable_noobj_cacheSSL/TLS 相关
no_check_certificate
服务器证书不会根据可用的证书颁发机构进行检查。
s3fs mybucket /mnt/s3 -o no_check_certificatessl_verify_hostname=<value>
当值为 0 时,不会根据主机名验证 SSL 证书。默认值为 2。
s3fs mybucket /mnt/s3 -o ssl_verify_hostname=0ssl_client_cert=<cert>[:<cert_type>[:<private_key>[:<key_type>[:<password>]]]]
指定 SSL 客户端证书。
s3fs mybucket /mnt/s3 -o ssl_client_cert=/path/to/cert.pem:PEM:/path/to/key.pem:PEM:passwordnodnscache
禁用 DNS 缓存。
s3fs mybucket /mnt/s3 -o nodnscachenosscache
禁用 SSL 会话缓存。
s3fs mybucket /mnt/s3 -o nosscacheS3 API 相关
list_object_max_keys=<number>
指定 S3 list object API 返回的最大键数,默认为 1000。
s3fs mybucket /mnt/s3 -o list_object_max_keys=2000listobjectsv2
使用 ListObjectsV2 而不是 ListObjects,适用于不支持 ListObjects 的对象存储。
s3fs mybucket /mnt/s3 -o listobjectsv2sigv2
仅使用签名版本 2 签名 AWS 请求。
s3fs mybucket /mnt/s3 -o sigv2sigv4
仅使用签名版本 4 签名 AWS 请求。
s3fs mybucket /mnt/s3 -o sigv4use_path_request_style
使用旧版 API 调用样式(路径请求样式),支持不支持虚拟主机请求样式的 S3 兼容 API。
s3fs mybucket /mnt/s3 -o use_path_request_stylenoua
抑制 User-Agent 头。
s3fs mybucket /mnt/s3 -o nouacipher_suites=<list>
自定义 TLS 密码套件列表。
s3fs mybucket /mnt/s3 -o cipher_suites=ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384多部分上传相关
parallel_count=<number>
上传大对象的并行请求数,默认为 5。
s3fs mybucket /mnt/s3 -o parallel_count=20multipart_size=<size>
每个多部分请求的分块大小(MB),最小为 5MB,最大为 5GB,默认为 10MB。
s3fs mybucket /mnt/s3 -o multipart_size=50multipart_copy_size=<size>
每个多部分复制请求的分块大小(MB),用于重命名和混合上传,最小为 5MB,最大为 5GB,默认为 512MB。
s3fs mybucket /mnt/s3 -o multipart_copy_size=1024multipart_threshold=<size>
使用多部分上传的阈值(MB),至少为 5MB,默认为 25MB。
s3fs mybucket /mnt/s3 -o multipart_threshold=50singlepart_copy_limit=<size>
在尝试多部分复制之前单部分复制的最大大小(MB),默认为 512MB。
s3fs mybucket /mnt/s3 -o singlepart_copy_limit=1024nomultipart
禁用多部分上传。
s3fs mybucket /mnt/s3 -o nomultipartstreamupload
启用流上传,预期比其他上传功能提供更好的性能。此选项仍处于实验阶段。
s3fs mybucket /mnt/s3 -o streamuploadmax_thread_count=<number>
指定等待流上传的线程数,默认为 5。此选项仍处于实验阶段。
s3fs mybucket /mnt/s3 -o max_thread_count=20max_dirty_data=<size>
在写入一定数量的 MB 数据后将脏数据刷新到 S3,最小值为 50MB,-1 表示禁用。
s3fs mybucket /mnt/s3 -o max_dirty_data=10240缓存相关
use_cache=<directory>
指定本地文件缓存使用的本地文件夹。如果未指定,则禁用缓存。
s3fs mybucket /mnt/s3 -o use_cache=/var/cache/s3fscheck_cache_dir_exist
如果设置了 use_cache,则检查缓存目录是否存在。如果未指定此选项,当缓存目录不存在时会在运行时创建。
s3fs mybucket /mnt/s3 -o use_cache=/var/cache/s3fs -o check_cache_dir_existdel_cache
在 s3fs 启动和退出时删除本地文件缓存。
s3fs mybucket /mnt/s3 -o use_cache=/var/cache/s3fs -o del_cacheensure_diskfree=<size>
设置确保磁盘空闲空间的 MB 数,用于控制 s3fs 使用的缓存文件大小。
s3fs mybucket /mnt/s3 -o use_cache=/var/cache/s3fs -o ensure_diskfree=10240free_space_ratio=<percentage>
设置磁盘的最小空闲空间比率,值为 0 到 100 之间,默认为 10。
s3fs mybucket /mnt/s3 -o use_cache=/var/cache/s3fs -o free_space_ratio=20cachedir=<directory>
设置缓存 s3fs 文件的基础目录,默认为 $HOME/.fuse-s3fs-cache/。
s3fs mybucket /mnt/s3 -o cachedir=/var/cache/s3fspreserve_cache=[no|yes]
如果设置为 yes,给定挂载的缓存在卸载时不会被删除。
s3fs mybucket /mnt/s3 -o preserve_cache=yes存储类和加密相关
storage_class=<class>
使用指定的存储类存储对象。可能值
s3fs mybucket /mnt/s3 -o storage_class=standard_iause_rrs
使用 Amazon 的 Reduced Redundancy Storage。已被 storage_class 选项取代。
use_sse=<type>
指定三种类型的 Amazon 服务器端加密
# SSE-S3s3fs mybucket /mnt/s3 -o use_sse
# SSE-Cs3fs mybucket /mnt/s3 -o use_sse=custom:/path/to/keyfile
# SSE-KMSs3fs mybucket /mnt/s3 -o use_sse=kmsid:my-kms-key-idload_sse_c=<file>
指定用于下载时解密的 SSE-C 密钥文件路径。
s3fs mybucket /mnt/s3 -o load_sse_c=/path/to/sse-c-keys权限和用户相关
uid=<uid>
设置挂载点的用户 ID。
s3fs mybucket /mnt/s3 -o uid=1000gid=<gid>
设置挂载点的组 ID。
s3fs mybucket /mnt/s3 -o gid=1000umask=<mask>
为挂载点下的文件设置 umask。
s3fs mybucket /mnt/s3 -o umask=0000mp_umask=<mask>
为挂载点目录设置 umask。
s3fs mybucket /mnt/s3 -o mp_umask=0000allow_other
允许其他用户访问挂载点。此选项需要 FUSE 配置中的 user_allow_other。
s3fs mybucket /mnt/s3 -o allow_otherACL 和元数据相关
default_acl=<acl>
应用于所有写入的 S3 对象的默认预定义 ACL,例如 “private”、“public-read”。
s3fs mybucket /mnt/s3 -o default_acl=public-readahbe_conf=<file>
指定配置文件路径,用于根据文件(对象)扩展名设置额外的 HTTP 头。
配置文件格式示例:
.gzContent-Encoding gzip
.ZContent-Encoding compress
reg:^/MYDIR/(.*)[.]t2$Content-Encoding text2s3fs mybucket /mnt/s3 -o ahbe_conf=/etc/s3fs/ahbe.confrequester_pays
启用涉及请求者付费存储桶的请求。
s3fs mybucket /mnt/s3 -o requester_pays特殊功能相关
complement_stat
如果文件或目录对象没有 x-amz-meta-mode 头,则补充缺失的文件/目录模式信息。
s3fs mybucket /mnt/s3 -o complement_statcompat_dir
启用替代目录名称的支持。包括 dir/、dir、通过路径间接确定(如 /dir/file 但没有父目录)以及旧的 dir_$folder$ 格式。
s3fs mybucket /mnt/s3 -o compat_diruse_wtf8
支持任意文件系统编码。S3 要求所有对象名都是有效的 UTF-8,但某些客户端使用自己的编码。
s3fs mybucket /mnt/s3 -o use_wtf8use_xattr
启用处理扩展属性(xattrs)。
s3fs mybucket /mnt/s3 -o use_xattrnoxmlns
禁用注册 xml 命名空间。默认从 <http://s3.amazonaws.com/doc/2006-03-01> 查找命名空间。
s3fs mybucket /mnt/s3 -o noxmlnsnomultipart
禁用多部分上传。
s3fs mybucket /mnt/s3 -o nomultipartnomixupload
在多部分上传中禁用复制功能。
s3fs mybucket /mnt/s3 -o nomixuploadnocopyapi
不使用 PUT (copy api),用于不兼容的 S3 API。
s3fs mybucket /mnt/s3 -o nocopyapinorenameapi
仅在重命名命令中不使用 copy-api。
s3fs mybucket /mnt/s3 -o norenameapi数据完整性相关
enable_content_md5
允许 S3 服务器通过 Content-MD5 头检查上传的数据完整性。这会增加 CPU 开销。
s3fs mybucket /mnt/s3 -o enable_content_md5enable_unsigned_payload
不为 PutObject 和 UploadPart 有效负载计算 Content-SHA256。这可以减少传输的 CPU 开销。
s3fs mybucket /mnt/s3 -o enable_unsigned_payload调试和日志相关
logfile=<file>
指定日志输出文件。
s3fs mybucket /mnt/s3 -o logfile=/var/log/s3fs.logdbglevel=<level>
设置调试消息级别。可设置为 crit(严重)、err(错误)、warn(警告)、info(信息)、debug(调试)。
s3fs mybucket /mnt/s3 -o dbglevel=infocurldbg[=normal|body]
输出 libcurl 的调试消息。
s3fs mybucket /mnt/s3 -o curldbg=bodyno_time_stamp_msg
调试消息中不输出时间戳。
s3fs mybucket /mnt/s3 -o no_time_stamp_msgset_check_cache_sigusr1[=<file>]
发送 SIGUSR1 信号到 s3fs 进程时检查缓存状态。
s3fs mybucket /mnt/s3 -o set_check_cache_sigusr1=/tmp/cache-check.loginstance_name=<name>
当前 s3fs 挂载点的实例名称,将添加到日志消息和用户代理头中。
s3fs mybucket /mnt/s3 -o instance_name=production-s3其他选项
tmpdir=<directory>
临时文件的本地文件夹,默认为 /tmp。
s3fs mybucket /mnt/s3 -o tmpdir=/var/tmp/s3fsretries=<number>
重试失败的 S3 事务的次数,默认为 5。
s3fs mybucket /mnt/s3 -o retries=10bucket=<bucket_name>[:/path]
指定要挂载的 Amazon S3 存储桶名称。如果命令行中没有指定存储桶名称(和路径),必须在 -o 选项后指定此选项。
s3fs /mnt/s3 -o bucket=mybucket:/subdir/pathpublic_bucket=[1|yes]
设置为 1 时匿名挂载公共存储桶,忽略 $HOME/.passwd-s3fs 和 /etc/passwd-s3fs 文件。
s3fs mybucket /mnt/s3 -o public_bucket=1use_session_token
指示应提供会话令牌。
s3fs mybucket /mnt/s3 -o use_session_tokenmultireq_max=<number>
列出对象的并行请求的最大数量,默认为 20。
s3fs mybucket /mnt/s3 -o multireq_max=50lazy_fsdata=[no|yes]
如果设置为 yes,文件系统元数据仅在卸载时写回 S3,默认为 yes。
s3fs mybucket /mnt/s3 -o lazy_fsdata=yeswriteback_time=<seconds>
考虑上传文件到 S3 时的暂停秒数。如果在暂停后,s3fs 检测到其他进程已打开文件,则推迟上传,默认为 10 秒。
s3fs mybucket /mnt/s3 -o writeback_time=30bucket_size=<size>
桶大小,默认为最大长无符号整数值。
s3fs mybucket /mnt/s3 -o bucket_size=10TBmime=<file>
指定 mime.types 文件的路径,默认为 /etc/mime.types。
s3fs mybucket /mnt/s3 -o mime=/etc/mime.typesupdate_parent_dir_stat
当创建或删除文件或目录时,更新父目录的 mtime 和 ctime。
s3fs mybucket /mnt/s3 -o update_parent_dir_statIMDS (实例元数据服务) 相关
imdsv1only
使用 IMDSv1 而不是 IMDSv2。在环境不支持 IMDSv2 时使用。
s3fs mybucket /mnt/s3 -o imdsv1only挂载配置
/etc/fstab 配置
将 S3 存储桶添加到 /etc/fstab 可以在启动时自动挂载:
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,passwd_file=/etc/passwd-s3fs 0 0完整示例
基本配置
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other 0 0指定区域和端点
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,url=https://s3.ap-northeast-1.amazonaws.com,endpoint=ap-northeast-1 0 0启用缓存
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,use_cache=/var/cache/s3fs 0 0使用加密
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,use_sse 0 0使用 SSE-KMS
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,use_sse=kmsid:arn:aws:kms:us-east-1:123456789012:key/abcd1234-5678-90ef-ghij-klmnopqrstuv 0 0使用 IAM 角色
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,iam_role=auto 0 0非 Amazon S3 存储
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,use_path_request_style,url=https://storage.example.com 0 0使用代理
mybucket /mnt/s3 fuse.s3fs _netdev,allow_other,proxy=http://proxy.example.com:8080 0 0Systemd 单元文件
创建 /etc/systemd/system/s3fs-mybucket.service:
[Unit]Description=s3fs for mybucketAfter=network.target
[Service]Type=fuseUser=s3fs-userGroup=s3fs-groupExecStart=/usr/bin/s3fs mybucket:/data /mnt/s3 \ -o passwd_file=/home/s3fs-user/.passwd-s3fs \ -o url=https://s3.ap-northeast-1.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o allow_other \ -o mp_umask=000 \ -o dbglevel=info \ -o curldbg
ExecStop=/bin/fusermount -u /mnt/s3Restart=on-failureRestartSec=30s
[Install]WantedBy=multi-user.target启用和启动服务:
sudo systemctl daemon-reloadsudo systemctl enable s3fs-mybucket.servicesudo systemctl start s3fs-mybucket.service生产环境优化
基础优化配置
对于一般生产环境,推荐以下基础配置:
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o ensure_diskfree=10240 \ -o free_space_ratio=20 \ -o max_stat_cache_size=100000 \ -o stat_cache_expire=900 \ -o parallel_count=20 \ -o multipart_size=50 \ -o multipart_copy_size=1024 \ -o multipart_threshold=25 \ -o connect_timeout=60 \ -o readwrite_timeout=300 \ -o retries=10 \ -o allow_other \ -o noatime \ -o _netdev高性能配置
对于需要更高性能的场景:
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o ensure_diskfree=20480 \ -o free_space_ratio=15 \ -o max_stat_cache_size=200000 \ -o stat_cache_expire=1800 \ -o stat_cache_interval_expire=600 \ -o parallel_count=50 \ -o multipart_size=100 \ -o multipart_copy_size=2048 \ -o multipart_threshold=50 \ -o max_dirty_data=10240 \ -o connect_timeout=30 \ -o readwrite_timeout=180 \ -o retries=15 \ -o multireq_max=100 \ -o disable_noobj_cache \ -o allow_other \ -o noatime \ -o _netdev高可靠性配置
对于需要更高可靠性的场景:
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o ensure_diskfree=51200 \ -o free_space_ratio=25 \ -o max_stat_cache_size=50000 \ -o stat_cache_expire=600 \ -o stat_cache_interval_expire=300 \ -o parallel_count=10 \ -o multipart_size=25 \ -o multipart_copy_size=512 \ -o multipart_threshold=25 \ -o connect_timeout=120 \ -o readwrite_timeout=600 \ -o retries=20 \ -o enable_content_md5 \ -o preserve_cache=yes \ -o allow_other \ -o noatime \ -o _netdev加密和安全配置
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o use_sse=kmsid:arn:aws:kms:us-east-1:123456789012:key/abcd1234 \ -o ssl_verify_hostname=2 \ -o connect_timeout=60 \ -o readwrite_timeout=300 \ -o allow_other \ -o noatime \ -o _netdev低延迟配置
对于需要低延迟的场景:
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o max_stat_cache_size=300000 \ -o stat_cache_expire=3600 \ -o stat_cache_interval_expire=1800 \ -o parallel_count=100 \ -o multireq_max=200 \ -o connect_timeout=15 \ -o readwrite_timeout=60 \ -o retries=5 \ -o streamupload \ -o max_thread_count=50 \ -o enable_unsigned_payload \ -o disable_noobj_cache \ -o allow_other \ -o noatime \ -o _netdev存储成本优化配置
s3fs mybucket /mnt/s3 \ -o passwd_file=/etc/passwd-s3fs \ -o endpoint=us-east-1 \ -o url=https://s3.amazonaws.com \ -o use_cache=/var/cache/s3fs \ -o ensure_diskfree=51200 \ -o free_space_ratio=30 \ -o storage_class=intelligent_tiering \ -o max_stat_cache_size=100000 \ -o stat_cache_expire=1800 \ -o parallel_count=5 \ -o multipart_size=50 \ -o multipart_copy_size=1024 \ -o multipart_threshold=128 \ -o connect_timeout=120 \ -o readwrite_timeout=600 \ -o retries=10 \ -o allow_other \ -o noatime \ -o _netdev性能调优
并发优化
增加 parallel_count
对于高带宽网络或大文件上传:
-o parallel_count=50对于低带宽网络或小文件:
-o parallel_count=5增加 multireq_max
用于目录列表优化:
-o multireq_max=100缓存优化
调整缓存大小
-o max_stat_cache_size=200000调整缓存过期时间
-o stat_cache_expire=1800-o stat_cache_interval_expire=900多部分上传优化
调整分块大小
对于大文件:
-o multipart_size=100-o multipart_copy_size=2048对于小文件:
-o multipart_size=10-o multipart_copy_size=512调整阈值
-o multipart_threshold=50网络优化
调整超时时间
-o connect_timeout=60-o readwrite_timeout=300调整重试次数
-o retries=10CPU 优化
禁用 MD5 校验
-o enable_content_md5 # 不设置此项以减少 CPU 开销启用未签名有效负载
-o enable_unsigned_payload内存优化
限制缓存大小
-o max_stat_cache_size=50000-o ensure_diskfree=20480故障排查
常见问题
1. Input/output error
可能原因:
- 存储桶不存在
- 凭证不正确
- 本地时钟与 Amazon 服务器时间差超过 15 分钟
解决方案:
# 检查存储桶是否存在aws s3 ls s3://mybucket
# 检查时钟同步sudo ntpdate pool.ntp.org
# 使用调试模式查看详细错误s3fs mybucket /mnt/s3 -f -o dbglevel=info -o curldbg2. Permission denied
可能原因:
- 文件/目录权限问题
- 缺少 allow_other 选项
- 文件由其他工具创建,缺少元数据
解决方案:
# 添加 allow_other 选项s3fs mybucket /mnt/s3 -o allow_other
# 使用 complement_stat 选项s3fs mybucket /mnt/s3 -o complement_stat
# 设置 umasks3fs mybucket /mnt/s3 -o umask=0000 -o mp_umask=00003. Check bucket failed
可能原因:
- 非 Amazon S3 存储
- 需要使用路径请求样式
解决方案:
s3fs mybucket /mnt/s3 -o use_path_request_style4. HTTPS 连接失败(存储桶名称包含点)
可能原因:
- 通配符 SSL 证书不支持多级标签
解决方案:
s3fs mybucket /mnt/s3 -o use_path_request_style -o endpoint=us-west-25. 挂载时无法连接网络
解决方案:
# 在 fstab 中添加 _netdev 选项mybucket /mnt/s3 fuse.s3fs _netdev,allow_other 0 0
# 确保 netfs 服务启动sudo systemctl enable netfssudo systemctl start netfs调试技巧
启用调试日志
s3fs mybucket /mnt/s3 -f -o dbglevel=info -o curldbg查看系统日志
tail -f /var/log/messagestail -f /var/log/syslogtail -f /var/log/s3fs.log检查挂载状态
mount | grep s3fsdf -h | grep s3fs测试网络连接
curl -I https://s3.amazonaws.comcurl -I https://s3.us-east-1.amazonaws.com/mybucket性能监控
使用 iostat 监控磁盘 I/O
iostat -x 1使用 top/htop 监控 CPU 和内存
tophtop使用 nfsiostat 监控文件系统性能
nfsiostat 1最佳实践
安全最佳实践
- 使用 IAM 角色而不是硬编码凭证
- 限制存储桶访问权限,只授予必要的权限
- 启用服务器端加密
- 使用 HTTPS 连接 S3
- 定期轮换访问密钥
- 限制 allow_other 的使用,仅在必要时启用
- 保护密码文件权限 (600 或 640)
性能最佳实践
- 启用本地缓存以减少网络请求
- 调整并行上传数量以适应网络带宽
- 合理设置缓存过期时间
- 使用较大的多部分上传分块处理大文件
- 避免频繁的小文件操作
- 禁用 noatime 以减少元数据更新
- 使用 appropriate 存储类以降低成本
可靠性最佳实践
- 设置合理的重试次数和超时时间
- 监控磁盘空间,确保有足够的缓存空间
- 使用 enable_content_md5 确保数据完整性
- 定期备份重要数据
- 测试故障恢复流程
- 监控日志和错误
成本优化最佳实践
- 使用智能分层存储类 (intelligent_tiering)
- 设置合理的缓存大小以减少 API 调用
- 优化目录结构,减少 ListObject 调用
- 使用生命周期策略自动转换存储类
- 监控和审计 API 使用情况
运维最佳实践
- 使用 systemd 或 fstab 实现自动挂载
- 配置日志轮转避免日志文件过大
- 设置监控和告警
- 定期清理缓存
- 使用配置管理工具统一管理配置
- 文档化配置和流程
工具模式
列出不完整的多部分上传
s3fs --incomplete-mpu-list mybucket删除不完整的多部分上传
# 删除所有s3fs --incomplete-mpu-abort all mybucket
# 删除 24 小时前的(默认)s3fs --incomplete-mpu-abort mybucket
# 删除 1 年 6 个月 10 天 12 小时 30 分 30 秒前的s3fs --incomplete-mpu-abort 1Y6M10D12h30m30s mybucket限制和注意事项
文件系统限制
- 单文件大小限制: 5TB (受 S3 限制)
- 目录结构性能: 由于网络延迟,元数据操作性能较差
- 随机写入: 需要重写整个对象,使用多部分复制优化
- 原子性: 不支持文件或目录的原子重命名
- 硬链接: 不支持硬链接
- 多客户端: 多个客户端挂载同一存储桶没有协调机制
- inotify: 仅检测本地修改,不检测其他客户端或工具的外部修改
一致性限制
- AWS S3: 自 2020 年 12 月起提供读写后强一致性
- 非 AWS 提供商: 可能提供最终一致性,读取可能暂时返回陈旧数据
性能限制
- 网络延迟影响所有操作
- 大量小文件操作性能较差
- 列出目录需要多个 API 调用