s3fs-fuse 将 Linode Object Storage 挂载到 Ubuntu Server 本地文件系统

文章目录

    s3fs 是什么

    s3fs 是一个将 Amazon S3 存储桶挂载到本地文件系统的工具,它允许用户通过标准的文件系统接口访问 S3 存储桶中的数据,从而简化了与 S3 的交互过程。

    s3fs 通过 FUSE(Filesystem in Userspace)将 S3 存储桶映射为本地文件系统,使得用户可以使用标准的文件系统 API 来与 S3 中的数据进行交互,而无需直接调用 S3 API。

    https://github.com/s3fs-fuse/s3fs-fuse

    • s3fs allows Linux, macOS, and FreeBSD to mount an S3 bucket via FUSE.
    • s3fs makes you operate files and directories in S3 bucket like a local file system.
    • s3fs preserves the native object format for files, allowing use of other tools like AWS CLI.

    Linode Objects

    Object Storage 是全球可用、兼容 S3 的存储解决方案,即便您的数据增长,性能仍然保持不变。

    参考:

    https://www.linode.com/zh/products/object-storage/

    价格:250G,5 刀每月。500GB 的传输费用为 0 美元。相对 AWS S3 和 Google Cloud Storage 省去了传输费用。

    Ubuntu 24.04 安装 s3fs

    sudo apt install s3fs
    

    /etc/fstab

    配置 /etc/fstab 文件 (/etc/fstab 文件中的每一行表示一个挂载点),添加

    mybucket /mount/s3 fuse.s3fs _netdev,allow_other,use_path_request_style,url=https://us-east-1.linodeobjects.com/ 0 0
    

    /etc/passwd-s3fs

    填写

    ACCESS_KEY:SECRET_KEY
    
    chmod 600 /etc/passwd-s3fs
    
    // mount bucket
    mount -a
    

    说明:

    mount -a 是指:Mount all filesystems (of the given types) mentioned in fstab。

    对应的是卸载:

    umount /some/path

    报错:MOUNTPOINT directory is not empty

    # mount -a
    s3fs: MOUNTPOINT directory /var/www/html/xxx is not empty. if you are sure this is safe, can use the 'nonempty' mount option.
    mount: (hint) your fstab has been modified, but systemd still uses
           the old version; use 'systemctl daemon-reload' to reload.
    

    在 /etc/fstab 中增加一个 nonempty 配置

    mybucket /mount/s3 fuse.s3fs _netdev,allow_other,use_path_request_style,nonempty,url=https://us-east-1.linodeobjects.com/ 0 0
    

    报错:bucket name contains an illegal character.

    在这些 mount -a 时,报错:

    s3fs: BUCKET xxx – bucket name contains an illegal character.

    这个报错有迷惑性,实际上是 bucket 名字写错了。到 Linode 后台确认一下名字,改正即可。

    umount 参考

    ubuntu server 下使用 /etc/fstab 挂载的 s3 存储目录,如何卸载掉

    docker 容器中不生效问题

    Linux 宿主机挂载 s3 对象存储,docker 内没有生效问题

    参考

    • https://www.linode.com/community/questions/18817/how-do-i-use-s3fs-on-linode-object-storage
    • https://www.linode.com/community/questions/21663/how-do-i-mount-a-subdirectory-in-my-object-storage-bucket-using-s3fs

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式