通过ossfs把阿里云oss挂载本地

1、安装依赖包:
 sudo yum install automake gcc-c++ git libcurl-devel libxml2-devel fuse-devel make openssl-devel

2、下载ossfs
wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos7.0_x86_64.rpm

3、安装ossfs
yum localinstall ossfs_1.80.6_centos7.0_x86_64.rpm

4、配置ossfs
AccessKey是阿里云全局key,一定要生成专门管理oss的子key,最小权限原则

echo bucket-name:access-key-id:access-key-secret > /etc/passwd-ossfs
chmod 640 /etc/passwd-ossfs

5、挂载
oss挂载到本地的挂载点/tmp/ossfs,EndPoint(地域节点):http://oss-cn-hangzhou.aliyuncs.com

oss挂载到本地的挂载点/tmp/ossfs,EndPoint(地域节点):http://oss-cn-hangzhou.aliyuncs.com

mkdir /tmp/ossfs
ntpdate ntp1.aliyun.com #防止两边服务器时间不一致错误,阿里云时间同步服务器
ossfs bucket-name /tmp/ossfs -o -o nonempty -ourl=http://oss-cn-shanghai.aliyuncs.com
 # 切记后面的url仅为阿里云OSS的地区地址,不是Bucket的地址


6、卸载挂载点命令:
umount /tmp/ossfs # root user
fusermount -u /tmp/ossfs # non-root user
 
7、开机启动:
 
 vim /etc/init.d/ossfs
#! /bin/bash
 # chkconfig: 2345 10 90
 # description: ossfs service
 # 防止两边服务器时间不一致错误,CentOS8 ntpdate已被chrony替代
 ntpdate ntp1.aliyun.com
 testPath="/tmp/ossfs"
 #因为/tmp文件夹会被系统定期清理,所以需要判断文件夹是否存在 -d
 if [[ ! -d "$testPath" ]]; then
         mkdir /tmp/ossfs
 else
         echo "文件夹存在"
 fi
 ossfs bucket-name /tmp/ossfs -ourl=http://oss-cn-shanghai.aliyuncs.com -o nonempty

posted @ 2022-06-21 17:18  da0h1  阅读(1012)  评论(0编辑  收藏  举报