OSSFS将OSS bucket 挂载到本地文件系统及注意事项

OSSFS将OSS bucket 挂载到本地文件系统及注意事项

下载ossfs安装包

 wget http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/32196/cn_zh/1463121229943/ossfs_1.79.8_centos7.0_x86_64.rpm

安装ossfs

sudo yum localinstall ossfs_1.79.8_centos7.0_x86_64.rpm

将image这个bucket挂载到/mnt/ossfs目录下,AccessKeyId是faint, AccessKeySecret是123,oss endpoint是http://oss-cn-hangzhou.aliyuncs.com。


注意

如果你是阿里云的ecs,endpoint可以使用内网地址,例如http://oss-cn-hangzhou-internal.aliyuncs.com,减少流量费用。

更多的内网地址可参考:https://help.aliyun.com/document_detail/31837.html?spm=5176.2020520105.0.0.1QhBJ1

实例:

# echo image:faint:123 > /etc/passwd-ossfs
# chmod 640 /etc/passwd-ossfs
# mkdir /mnt/ossfs
# ossfs image /mnt/ossfs -ourl=http://oss-cn-hangzhou.aliyuncs.com -o allow_other

卸载

# umount /mnt/ossfs

优化及注意事项

开机挂载

vi /etc/rc.d/rc.local

# 开机挂载oss,采用此种方式挂载避免修改/etc/fstab ,导致挂载失败而系统无法启动。加 -o allow_other 允许非root用户操作避免因权限问题导致无法操作oss目录
ossfs image /mnt/ossfs -ourl=http://oss-cn-hangzhou.aliyuncs.com -o allow_other

非阿里云ecs挂载注意事项

为避免后台程序扫描oss文件导致产生费用,如果是updatedb,可以通过修改/etc/updatedb.conf让它跳过。具体做法是:

  • PRUNEFS = 后面加上fuse.ossfs
  • PRUNEPATHS = 后面加上挂载的目录
原文地址:https://www.cnblogs.com/rwxwsblog/p/5938701.html