Debian 12 上挂载S3存储桶
安装 s3fs-fusesudo apt update
sudo apt install s3fs
创建访问凭证
以 Hetzner 挂载自家的 S3 存储桶为例,包含 Access Key 和 Secret Key
创建凭证文件
可放本用户目录下
# Create credentials file
echo "your-access-key-id:your-secret-access-key" > ~/.passwd-s3fs
# Set appropriate permissions
chmod 600 ~/.passwd-s3fs
或放 /etc 目录下
sudo echo "your-access-key-id:your-secret-access-key" > /etc/passwd-s3fs
sudo chmod 600 /etc/passwd-s3fs
创建挂载点
# Create mount directory
sudo mkdir -p /mnt/s3bucket
# Or create in your home directory
mkdir -p ~/s3bucket
挂载 S3 存储桶
# Basic mount command
s3fs your-bucket-name /mnt/s3bucket -o passwd_file=~/.passwd-s3fs
# With specific region and options
s3fs your-bucket-name /mnt/s3bucket \
-o passwd_file=~/.passwd-s3fs \
-o url=https://fsn1.your-objectstorage.com \
-o use_path_request_style \
-o allow_other \
-o uid=1000 \
-o gid=1000 \
-o use_cache=/tmp \
-o ensure_diskfree=1000 \
-o umask=0022 \
-o mp_umask=0022
自动挂载配置
sudo nano /etc/fstab
your-bucket-name /home/wwwroot/cdbao.org/data/attachment fuse.s3fs _netdev,passwd_file=/root/.passwd-s3fs,url=https://fsn1.your-objectstorage.com,use_path_request_style,allow_other,uid=1000,gid=1000,use_cache=/tmp,umask=0022,mp_umask=0022,ensure_diskfree=1000 0 0
验证挂载
# Check mount status
df -h | grep s3
# List files in mounted directory
ls -la /mnt/s3bucket/
# Test write operation
echo "test" > /mnt/s3bucket/test.txt
更新文件夹权限
# Ensure correct ownership (should be automatic with correct uid/gid)
chown -R www:www /mnt/s3bucket/
卸载 S3 存储桶
# Unmount S3 bucket
sudo umount /mnt/s3bucket
# Or force unmount if needed
sudo fusermount -u /mnt/s3bucket
页:
[1]