一、COSFS 工具介绍
COSFS 工具支持将对象存储(Cloud Object Storage,COS)存储桶挂载到本地,像使用本地文件系统一样直接操作腾讯云对象存储中的对象, COSFS 提供的主要功能包括:支持 POSIX 文件系统的大部分功能,如:文件读写、目录操作、链接操作、权限管理、uid/gid 管理等功能。
官方文档:https://cloud.tencent.com/document/product/436/6883
下载地址:https://github.com/tencentyun/cosfs/releases
二、安装使用COSFS 工具
1、提前准备好存储桶名称以及密钥
https://console.cloud.tencent.com/cos/bucket
https://console.cloud.tencent.com/cam/capi
2、安装COSFS
#先安装依赖再下载安装cosfs
yum install libxml2-devel libcurl-devel fuse-devel openssl-devel fuse -y
wget https://github.com/tencentyun/cosfs/releases/download/v1.0.23/cosfs-1.0.23-centos7.0.x86_64.rpm
rpm -ivh cosfs-1.0.23-centos7.0.x86_64.rpm
3、 配置密钥文件
在文件 /etc/passwd-cosfs 中,写入存储桶名称(格式为 BucketName-APPID),以及该存储桶对应的 <SecretId> 和 <SecretKey>,三项之间使用半角冒号隔开
echo disk-1251101346:AKIDiMrOsCh0AAzb5PYUTYjl**********2:fCkDUcZMxPjw0sbAYi**********1Si > /etc/passwd-cosfs
chmod 600 /etc/passwd-cosfs
4、运行工具
将COS挂载到本地/data/blog_html目录

#先创建本地目录
mkdir -p /data/blog_html
#运行挂载命令,ap-shanghai是地域,根据自己的COS注意更换
cosfs blog-1251101346 /data/blog_html \
-ourl=https://cos.ap-shanghai.myqcloud.com \
-oallow_other \
-ononempty \
-odefault_permission=755 \
-omp_umask=022

5、异常处理
# 卸载原有挂载
fusermount -u /data/blog_html
# 检查密钥,然后重新挂载
/etc/passwd-cosfs