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://help.aliyun.com/document_detail/32196.html?spm=5176.doc31883.6.541.3B03r4