s3fs-fuse 使用介绍

2023-11-12  本文已影响0人  酱油王0901

安装

Centos

sudo yum install epel-release
sudo yum install s3fs-fuse

Ubuntu

sudo apt install s3fs

建议使用最新的 release 版本。

使用

  1. 创建 passwd 文件,注意替换成实际的 ak 和 sk
touch ${HOME}/.passwd-s3fs # 创建 passwd 文件
echo <ACCESS_KEY_ID>:<SECRET_ACCESS_KEY> > ${HOME}/.passwd-s3fs # 替换成实际的 ak 和 sk
chmod 600 ${HOME}/.passwd-s3fs # chmod

cat ${HOME}/.passwd-s3fs # 查看 passwd 文件
testy:testy
  1. 挂载
s3fs <bucket> </path/to/mountpoint> -o passwd_file=${HOME}/.passwd-s3fs -o url=<endpoint> -o use_path_request_style

# 其中,
#    `url` 指定 s3 endpoint 
#    `passwd_file` 指定上述存储 ak,sk 的文件
#    `use_path_request_style` 指定 older path request style

For example

~/smd (update_ceph ✗) s3cmd ls # 这里只是查看 bucket name,具体使用时换成相应的 bucket 即可                                                                                                              
2023-04-26 12:10  s3://bucket-0arc2cr3vl52r5bi
~/smd (update_ceph ✗) mkdir /mnt/s3 # 创建挂载点 

# 挂载
~/smd (update_ceph ✗) s3fs bucket-0arc2cr3vl52r5bi /mnt/s3 -o passwd_file=${HOME}/.passwd-s3fs -o url="http://10.9.8.72:80" -o use_path_request_style                         

# 查询挂载信息
~/go/src/deeproute.ai/smd (update_ceph ✗) df -hT | grep s3                                                                                                                   
s3fs                    fuse.s3fs   16E     0   16E   0% /mnt/s3

需要注意的是,不能将 {HOME} 换成 ~, 否则会报 s3fs: unexpected error from stat(~/.passwd-s3fs) 错误,对应的 issue s3fs: unexpected error from stat(). · Issue #1889 · s3fs-fuse/s3fs-fuse

  1. 读写文件
~/smd (update_ceph ✗) cd /mnt/s3                                                                                                                                                                                                                    
/mnt/s3 ls
adjust_pg_balance.py               csi-cephfsplugin.yaml   csi-nodeplugin-rbac.yaml   examples/           merge.py   set-pg-balance.py          xxx
ceph-conf.yaml                     csi-cephfs-secret.yaml  csi-provisioner-rbac.yaml  get-osd-pg-info.py  README.md  set_pg_progress.json
csi-cephfsplugin-provisioner.yaml  csi-config-map.yaml     df.old.log                 intree              rookObj1   set-primary-pg-balance.py
/mnt/s3 cat xxx           
xx
/mnt/s3 echo yyy > yyy
/mnt/s3 cat yyy  
yyy

  1. 使用完毕记得 umount
umount /mnt/s3
  1. 如果希望启动时自动挂载,可以修改 /etc/fstab
<mybucket> </path/to/mountpoint> fuse.s3fs _netdev,allow_other,use_path_request_style,url=<https://url.to.s3/> 0 0
# 注意,上述的 bucket 名,挂载点,以及 endpoint 都需要进行替换

注意事项

  1. 如果上传文件数较大(>100G),则会上传失败
cp: error writing '/mnt/s3/xxxx': File too large
cp: failed to close '/mnt/s3/xxxx': File too large

可以设置分段大小 -o multipart_size=30 ,30 代表 30M,可以根据实际需求进行调整。
此参数设置分段大小,默认为 10,单位是 MB,即 10MB x 分段数(默认10000),因此默认只支持100G大小,可以设置此参数来上传更大的文件。

参考链接

上一篇 下一篇

猜你喜欢

热点阅读