挂载对象存储OSS到服务器目录


ossfs能让您在Linux系统中,将对象存储OSS的存储空间(Bucket)挂载到本地文件系统中,您能够像操作本地文件一样操作OSS的对象(Object),实现数据的共享

1.下载安装包
以下载CentOS 7.0 (x64)版本为例:
#wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos7.0_x86_64.rpm

2.安装ossfs
CentOS6.5及以上系统版本的安装命令:
#yum localinstall your_ossfs_package

3.配置账号访问信息
将Bucket名称以及具有此Bucket访问权限的AccessKeyId/AccessKeySecret信息存放在/etc/passwd-ossfs文件中。注意这个文件的权限必须正确设置,建议设为640
#echo my-bucket:my-access-key-id:my-access-key-secret > /etc/passwd-ossfs
#chmod 640 /etc/passwd-ossfs

4.将Bucket挂载到指定目录
#ossfs my-bucket my-mount-point -ourl=my-oss-endpoint
示例:
将杭州地域名称为bucket-test的Bucket挂载到/tmp/ossfs目录下
#echo bucket-test:LTAIbZcdVCmQ****:MOk8x0y9hxQ31coh7A5e2MZEUz**** > /etc/passwd-ossfs
#chmod 640 /etc/passwd-ossfs
#mkdir /tmp/ossfs
#ossfs bucket-test /tmp/ossfs -ourl=http://oss-cn-hangzhou.aliyuncs.com
加参数-o allow_other #允许所以用户,权限是777

5.卸载oss
fusermount -u /tmp/ossfs

6.挂载遇到下面问题时:有可能是系统时间不对 把系统时间设置为正常时间试试
ossfs: invalid credentials

RequestTimeTooSkewed
The difference between the request time and the current time is too large.
5B0E0DDD96CC863947FEA1C5
dujiangyan-test.oss-cn-hangzhou.aliyuncs.com
900000
2018-05-29T18:35:05.000Z
2018-05-30T02:35:09.000Z

7.ossfs看到的文件信息(例如大小)与其他工具看到的不一致时
解决方案:可以在挂载的时候加上参数-o max_stat_cache_size=0,禁用元数据缓存功能。每次ls时,都会向OSS 发送请求,获取最新的文件信息。

8.开启ossfs的debug日志,加上-d -o f2参数,ossfs会把日志写入到系统/var/log/message
---------------------------------------------------------------------------
centos6.5安装及问题
1.下载
#wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos6.5_x86_64.rpm

2.安装时报以下错误
Transaction Check Error:
file /sbin/mount.fuse from install of ossfs-1.80.5-1.x86_64 conflicts with file from package fuse-2.8.3-5.el6.x86_64
file /usr/bin/fusermount from install of ossfs-1.80.5-1.x86_64 conflicts with file from package fuse-2.8.3-5.el6.x86_64
file /usr/bin/ulockmgr_server from install of ossfs-1.80.5-1.x86_64 conflicts with file from package fuse-2.8.3-5.el6.x86_64

Error Summary
-------------
解决方法:卸载所有fuse-2.8.3
# rpm -qa | grep fuse
# fuse-2.8.3-5.el6.x86_64
# fuse-libs-2.8.3-5.el6.x86_64
卸载
# yum remove fuse

3.挂载时报错1
bash: ossfs: command not found
解决:
# ln -sf /usr/local/bin/ossfs /usr/bin/ossfs

4.挂载时报错2
fuse: warning: library too old, some operations may not not work
解决:
是因为fuse-libs库太老了,安装ossfs_1.80.5的时候自带了fuse-libs
rpm -ql ossfs | grep fuse
找到库文件所在路径,在挂载命令前加LD_LIBRARY_PATH=/usr/lib
#LD_LIBRARY_PATH=/usr/lib ossfs soyoungoss /backup/ossfs -ourl=http://oss-cn-beijing-internal.aliyuncs.com

5.挂载时报错3
ossfs: error while loading shared libraries: libcrypto.so.10: cannot open shared object file: No such file or directory
解决:是因为没有安装,找到对应Linux版本安装
#wget http://rpmfind.net/linux/centos/8-stream/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
#yum localinstall compat-openssl10-1.0.2o-3.el8.x86_64.rpm

6.非root用户授权读写
在挂载命令中添加 -o allow_other

7.启动文件rc.local中使用
/usr/local/bin/ossfs

8.挂载时如果bash: ossfs: command not found则
ln -sf /usr/local/bin/ossfs /usr/bin/ossfs