使用S3fs让ECS虚拟机直接挂载OBS对象存储桶
一、服务器下载相关依赖包
yum install fuse sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel
对于Ubuntu 14.04,执行:
[code]sudo apt-get install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config[/code]对于CentOS7,执行:
[code]sudo yum install automake fuse fuse-devel gcc-c++ git libcurl-devel libxml2-devel make openssl-devel[/code]而对于CentOS6.5,需要手动更新fuse包,到libfuse 2.8.4。
二、下载s3fs
支持通过以下两种方式下载s3fs。
方式一:镜像源安装。(云服务器安装)
# Ubuntu sudo apt install s3fs # CentOS sudo yum install epel-release sudo yum install s3fs-fuse
方式二:GitHub获取指定版本安装。
下载地址:https://github.com/s3fs-fuse/s3fs-fuse/tree/v1.91
三、安装s3fs(我这里演示编译)
编译安装。使用方式一安装s3fs请跳过该步骤。
进入s3fs-fuse解压目录,按照以下命令执行编译操作: ./autogen.sh ./configure make sudo make install
执行以下命令检查安装情况。 s3fs --version 当命令回显出现s3fs版本信息时,表示s3fs能够成功运行。
四、配置s3fs
配置AK:SK: echo "AK:SK" >>/root/.passwd-s3fs chmod 600 /root/.passwd-s3fs
五、挂载s3fs
按照以下格式执行挂载命令: s3fs 对象桶名 本地挂载目录 -o passwd_file=密钥文件路径 -o url=区域终端节点地址 -o nonempty -o big_writes -o max_write=131072 其他挂载参数 例如:s3fs aap-lpg /opt/ -o passwd_file=/root/.passwd-s3fs -o url=https://obs.cn-south-1.myhuaweicloud.com -o nonempty -o big_writes -o max_write=131072
六、查看挂载
df -hT
六、卸载
umount <路径> //本地挂载的路径
挂载命令参数的含义
添加参数查看更多信息:
-o dbglevel=info -f :运行时显示更多输出,挂载成功后会占用当前shell前端
-o curldbg:启用 cURL 的调试功能
-o umask=000:挂载目录的权限
-o use_path_request_style:启用不支持的类s3 api的兼容性(必须配置,否则挂载minio存储桶失败)
-o no_check_certificate:不检查证书
-o allow_other:允许所有用户访问
————————————————
挂载桶中的一个目录到本地服务器
s3fs bxlz:/beifen /www/ossfs/obs/bxlz -o passwd_file=/root/.passwd-huawei-s3fs -o url=https://obs.myhuaweicloud.com -o nonempty -o big_writes -o max_write=131072 -o allow_other
----------------
遇到的问题
1.挂载成功后,上传的文件同步导桶的时候,丢失了元数据,导致图片无法在浏览器浏览,打开就下载。
在命令中加入mime参数
s3fs bxlz /www/ossfs/obs/bxlz -o passwd_file=/root/.passwd-huawei-s3fs -o url=https://obs.myhuaweicloud.com -o nonempty -o big_writes -o max_write=131072 -o allow_other -o use_path_request_style -o multireq_max=30 -o mime=/etc/mime.types -o use_xattr -o stat_cache_expire=60 -o dbglevel=info -f
卸载:umount /www/ossfs/obs/bxlz
/etc/mime.types 文件内容
# 文本类型 text/html html htm shtml text/css css text/javascript js # 图像类型 image/jpeg jpeg jpg image/png png image/svg+xml svg svgz # 压缩包类型 application/zip zip application/x-rar-compressed rar
https://github.com/s3fs-fuse/s3fs-fuse/wiki/Fuse-Over-Amazon
2.卸载是由于某进程占用,无法卸载目录
卸载失败时:In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1)
查看挂载点占用进程 lsof /www/wwwroot/www.100xlg.cn/images
强制终止进程 fuser -km /www/wwwroot/www.100xlg.cn/images
3. 挂载是文件目录无法写入
-o umask=000 -o allow_other
4.华为云对象桶设置密码文件的格式:https://developer.aliyun.com/article/1606449
https://www.cnblogs.com/kongshuo/p/18325089
https://developer.aliyun.com/article/1606449
https://blog.csdn.net/qq_40205510/article/details/139267433
使用S3fs让ECS虚拟机直接挂载OBS对象存储桶>>https://bbs.huaweicloud.com/forum/thread-206-1-1.html
通过s3fs工具以文件系统方式访问obs实践与调优>>https://bbs.huaweicloud.com/forum/thread-11650-1-1.html