想要将 AWS S3 挂载到本地目录,可以使用一个名为s3fs
的工具来实现。具体安装过程如下:
首先,准备必要的软件包:
1
2
3
|
sudo apt update
sudo apt-get install -y automake fuse gcc g++ git \
libcurl4-openssl-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
|
然后,从源码编译并安装s3fs:
1
2
3
4
5
6
|
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse
./autogen.sh
./configure
make
sudo make install
|
配置访问凭证:
1
2
|
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ~/.passwd-s3fs
chmod 600 ~/.passwd-s3fs
|
尝试挂载:
1
|
s3fs bucket_name /path/to/local/mount -o passwd_file=~/.passwd-s3fs
|
检查是否挂载成功:
取消挂载:
1
|
fusermount -u /path/to/local/mount
|
要设置自动挂载,可以添加如下行到/etc/fstab
中:
s3fs#bucket_name /path/to/local/mount fuse _netdev,allow_other,use_path_request_style,url=https://s3.amazonaws.com,passwd_file=/home/your_username/.passwd-s3fs 0 0
如果需要挂载中国区的S3,则在执行挂载命令,指定相关参数(下面以宁夏cn-northwest-1
为例):
1
2
|
s3fs bucket_name /path/to/local/mount \
-o passwd_file=~/.passwd-s3fs,url=https://s3.cn-northwest-1.amazonaws.com.cn,endpoint=cn-northwest-1
|
如果挂载失败,可以通过查看系统日志,定位错误原因:
1
|
sudo cat /var/log/syslog | grep s3fs
|