27

Ucloud网络文件系统s3fs介绍-10931853

 4 years ago
source link: https://blog.51cto.com/wujianwei/2497984
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

一、功能说明:

s3fs 工具支持将Bucket挂载到本地,像使用本地文件系统一样直接操作对象存储中的对象。

二、s3fs 使用方法:

2.1配置密钥文件:

在/etc/目录中创建passwd-s3fs 文件。文件格式为[API 公钥:API 秘钥]

[root@localhost ~]# cat /etc/passwd-s3fs 
RTdB5Tv0i+45+YDNv6cOmCU9XsEFJcBlTUbJjKHkOXuqRCK3f69e1Q=:/WyeyWQDNUVi8kHktkLxa6pHqVQYfKeCei/qGNbry1H4JHOYw2ZUrDyy7AFDwTS
[root@localhost ~]# chmod 600  /etc/passwd-s3fs

秘钥生成方法参考下面的文档:
https://docs.ucloud.cn/uai-train/basic/key

Ucloud网络文件系统s3fs介绍

公私钥如下:


PublicKey:RTdB5Tv0i+4+YDNv6cOmCU9XsEFJcBlTUbJjKHkOXuqRCK3f69e1Q=
PrivateKey:/WyeyWQDUVi8kHktkLxa6pHqVQYfKeCei/qGNbry1H4JHOYw2ZUrDyy7AFDwTS

2.2CentOS 6和centos7编译s3fs,并且安装该程序:

https://github.com/s3fs-fuse/s3fs-fuse
git clone https://github.com/s3fs-fuse/s3fs-fuse.git

安装所需要的依赖:

yum install automake gcc-c++ git libcurl-devel libxml2-devel   fuse-devel make openssl-devel fuse unzip -y

克隆s3fs-fuse版本库:

[root@localhost s3fs]# git clone https://github.com/s3fs-fuse/s3fs-fuse.git
正克隆到 's3fs-fuse'...

remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (71/71), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 6016 (delta 37), reused 38 (delta 16), pack-reused 5945
接收对象中: 100% (6016/6016), 3.67 MiB | 36.00 KiB/s, done.
处理 delta 中: 100% (4162/4162), done.

编译安装:

 cd s3fs-fuse
./autogen.sh  
./configure  
make  
make install  

s3fs --version #查看 s3fs版本号:

[root@localhost s3fs-fuse]# which s3fs
/usr/local/bin/s3fs
[root@localhost s3fs-fuse]# s3fs --version 
Amazon Simple Storage Service File System V1.86 (commit:0b60aa8) with OpenSSL
Copyright (C) 2010 Randy Rizun <[email protected]>
License GPL2: GNU GPL version 2 <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

可以看s3fs的版本号,到此,s3fs已经安装成功。

特别备注:

在执行第五步,./configure的过程中,可能会遇到以下的问题。汇总为:
报错: configure: error: Package requirements (fuse >= 2.8.4 libcurl >= 7.0 libxml-2.0 >= 2.6 ) were not met:
原因: fuse 版本过低,此时,您需要手动安装 fuse 2.8.4及以上版本,安装命令示例如下:

yum -y remove fuse-devel #卸载当前版本的fuse
wget https://github.com/libfuse/libfuse/releases/download/fuse_2_9_4/fuse-2.9.4.tar.gz
tar -zxvf fuse-2.9.4.tar.gz
cd fuse-2.9.4
./configure
make
make install
export
PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/lib64/pkgconfig/:/usr/local/lib/pkgconfig
modprobe fuse #挂载 fuse 内核模块
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig #更新动态链接库
pkg-config --modversion fuse #查看 fuse 版本号,当看到 “2.9.4” 时,表示
fuse2.9.4 安装成功

2.3说明:

官网文档:
https://docs.ucloud.cn/ufile/s3/s3_introduction
目前只支持的挂载地域


接入域名           (Endpoint)
地域             外网Endpoint                           内网Endpoint
中国-北京二        s3-cn-bj.ufileos.com                  internal.s3-cn-bj.ufileos.com
中国-上海         s3-cn-sh2.ufileos.com                 internal.s3-cn-sh2.ufileos.com
中国-广州         待支持                               internal.s3-cn-gd.ufileos.com
中国-香港         s3-hk.ufileos.com                     internal.s3-hk.ufileos.com
越南-胡志明        s3-vn-sng.ufileos.com                 internal.s3-vn-sng.ufileos.com
尼日利亚-拉各斯      s3-afr-nigeria.ufileos.com            internal.s3-afr-nigeria.ufileos.com
韩国-首尔         s3-kr-seoul.ufileos.com               internal.s3-kr-seoul.ufileos.com
巴西-圣保罗        bra-saopaulo.ufileos.com              待支持
美国-洛杉矶        s3-us-ca.ufileos.com                  internal.s3-us-ca.ufileos.com
注意: 目前中国-北京二,中国-香港,越南-胡志明,韩国-首尔,巴西-圣保罗地域已经支持https协议,其他地域后续支持 (所有地域内网不支持https)

参数说明如下:

s3fs ${UFileBucketName} ${LocalFilePath}
-o url={UFileS3URl} -o passwd_file=~/.passwd-s3fs
-o dbglevel=info
-o curldbg,use_path_request_style,allow_other
-o retries=1 //错误重试次数
-o multipart_size="8" //分片上传的大小为 8MB,目前仅支持该值 -o
multireq_max="8" //当上传的文件大于 8MB 是采用分片上传,目前UFile 的 S3
接入层不允许 PUT 单个文件超过 8MB,所以该值建议必填
-f //表示前台执行,后台执行则省略
-o parallel_count="32" //并行操作数,可以提高分片并发操作,建议不要超过 128

注意:
存储空间名称不带域名后缀,比如UFile空间名称显示为[wbbj-test.cn-bj.ufileos.com],则${UFileBucketName}=wbbj-test

[root@localhost video]# s3fs wbbj-test  /data/www/video -o url=http://s3-cn-bj.ufileos.com  -o passwd_file=/etc/passwd-s3fs -o dbglevel=info -o curldbg,use_path_request_style,allow_other -o retries=1 -o multipart_size="8" -o multireq_max="8" -o parallel_count="32" 

下图说明已经挂载成功:

Ucloud网络文件系统s3fs介绍

cp文件到此目录/data/www/video下
[root@mysql-redis105 video]# cp /root/1105.sql ./
[root@mysql-redis105 video]# pwd
/data/www/video
[root@mysql-redis105 video]# ls
1105.sql

控制台查看bukets存储,发现文件1105.sql已经放到了buckets
在控制台bukets wbbj_test存储新建一个txt文件夹

Ucloud网络文件系统s3fs介绍
Ucloud网络文件系统s3fs介绍

服务器查看有文件txt01生成:
Ucloud网络文件系统s3fs介绍

浏览器可以通过如下格式下载文件:
http://${bucket名字}.${Endpoint}/${key名字},类似UFile目前使用的URL形式

http://wbbj-test.s3-cn-bj.ufileos.com/test001/1.txt

卸载挂载目录:
umount /data/www/video


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK