需將s3 bucket 掛載到本地centos7服務器,用作附件或備份存儲。
授權
在aws上創建 s3 bucket的IAM用戶,並添加讀寫權限。在此獲取 Access Key ID 與 Secret Access Key。
安裝依賴包
yum install fuse.x86_64 fuse-devel.x86_64 fuse-libs.x86_64 libconfuse-devel.x86_64 libconfuse.x86_64 -y
yum install gcc-c++.noarch -y
yum install curl.x86_64 libcurl-devel.x86_64 libcurl.x86_64 -y
yum install libxml2.x86_64 libxml2-devel.x86_64 openssl-devel.x86_64 -y
安裝s3fs-fuse
cd /usr/local/
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse/
./autogen.sh
./configure
make
make install
以下命令輸出代表安裝成功
[root@one s3test]# /usr/local/bin/s3fs
s3fs: missing BUCKET argument.
Usage: s3fs BUCKET:[PATH] MOUNTPOINT [OPTION]...
添加Access Key ID 與 Secret Access Key
vim ~/.passwd-s3fs
格式為 Access Key ID:Secret Access Key
chmod 600 ~/.passwd-s3fs
掛載:
mkdir /mnt/s3bucket
/usr/local/bin/s3fs -o passwd_file=~/.passwd-s3fs -o url=https://s3.cn-northwest-1.amazonaws.com.cn -o allow_other my-buckentname /mnt/s3bucket/ -o use_cache=/tmp
此處會有報錯 libcurl版本低的問題
更新curl版本
見:https://www.htcp.net/337.html
步驟為:
cp /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-bundle.crt.bak
curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt
vim /etc/yum.repos.d/city-fan-for-curl.repo
[CityFanforCurl]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/
enabled=0
gpgcheck=0
yum update curl --enablerepo=CityFanforCurl -y
重新掛載
/usr/local/bin/s3fs -o passwd_file=~/.passwd-s3fs -o url=https://s3.cn-northwest-1.amazonaws.com.cn -o allow_other my-buckentname /mnt/s3bucket/ -o use_cache=/tmp
df -h #查看掛載是否成功
注:若掛載未成功,可在掛載命令添加-d -d -f -o f2 -o curldbg ,輸出日志查看問題
注意以上命令中,它實際訪問的鏈接是https://my-buckentname.s3.cn-northwest-1.amazonaws.com.cn;
若要它的訪問鏈接完全等於url中的鏈接,可加上 -o use_path_request_style
/usr/local/bin/s3fs -o passwd_file=~/.passwd-s3fs -o use_path_request_style -o url=http://minio-s3.test.net:3000 -o allow_other my-buckentname /mnt/s3bucket/