文章目录
SeaweedFS可以兼容Amazon S3 API。
1. 实现机制
weed s3
命令可以启动一个无状态的gateway去作为Amazon S3 API和SeaweedFS Filer之间的桥梁。
S3的每个桶对应SeaweadFS的一个Collection。
2. 支持更多的桶
S3每个桶都有自己的Collection,通常来说一个Collection需要使用7个Volume,每个Volume默认最大size是30GB, 如果创建很多个桶,建议把Volume的最大size调小或者限制Volume的增长速度,否则Volume很快就会耗尽。
2.1 Volume的最大size调小
-volumeSizeLimitMB, weed master
命令行选项
2.2 限制Volume的增长速度
-volumeGrowthCount
,weed shell
参数,
fs.configure -locationPrefix=/buckets/ -volumeGrowthCount=1 -apply
如果启动的replication,则需要更多的volume,volume的增长需要稍微调大,例如replication为001时,volumeGrowthCount则应不小于2。
fs.configure -locationPrefix=/buckets/ -replication=001 -volumeGrowthCount=2 -apply
3. 启动S3 gateway服务
./weed s3 # 单独启动一个s3 gateway服务
./weed filer -s3 #启动filer服务的时候同时启动s3 gateway服务,两个服务在同一个进程
S3 gateway服务的默认端口为8333。
4. 通过s3cmd操作SeaweedFS
4.1 s3cmd的安装
参考:https://s3tools.org/download
4.2 配置
s3cmd --configure
...
New settings:
Access Key: any_no_empty_key
Secret Key: any_no_empty_key
Default Region: US
S3 Endpoint: localhost:8333
DNS-style bucket+hostname:port template for accessing a bucket: localhost:8333
Encryption password:
Path to GPG program: /usr/local/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0
在命令行执行s3cmd --configure
,
S3 Endpoint 填写 S3 gateway 的地址,默认为localhost:8333。
4.3 s3cmd使用案例
# 创建桶
$ s3cmd mb s3://newbucket
Bucket 's3://newbucket/' created
# 查看桶的列表
$ s3cmd ls s3://
2019-01-01 01:30 s3://newbucket
# 上传文件到桶
$ s3cmd put /etc/passwd s3://newbucket
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
upload: '/etc/passwd' -> 's3://newbucket/passwd' [1 of 1]
6804 of 6804 100% in 0s 87.93 kB/s done
# 下载文件到本地
$ s3cmd get s3://newbucket/passwd
download: 's3://newbucket/passwd' -> './passwd' [1 of 1]
6804 of 6804 100% in 0s 595.33 kB/s done
# 修改本地文件
$ vi passwd
# 同步本地文件到桶
$ s3cmd sync passwd s3://newbucket/
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
upload: 'passwd' -> 's3://newbucket/passwd' [1 of 1]
22 of 22 100% in 0s 6.45 kB/s done
Done. Uploaded 22 bytes in 1.0 seconds, 22.00 B/s.
# 查看桶的文件列表
$ s3cmd ls s3://newbucket/
2019-01-01 01:32 22 s3://newbucket/passwd
# 删除桶的文件
$ s3cmd del s3://newbucket/passwd
delete: 's3://newbucket/passwd'
# 删除桶
$ s3cmd rb s3://newbucket
Bucket 's3://newbucket/' removed