我们已经部署了Ceph RGW服务,并使用管理工具radosgw-admin创建了S3用户,本篇我们尝试使用S3 API访问Ceph RGW。 在开始之前先了解一下Amazon S3。

Amazon S3

Amazon S3(即Amazon Simple Storage Service) 是一种面向 Internet 的存储服务,Amazon还提供了S3 REST API可随时在 Web 上的任何位置存储和检索的任意大小的数据,同时提供Java、Python、Golang等各种语言的的SDK。 而Ceph RGW兼容绝大部分S3 Api,我们先熟悉一下S3服务的一些基本概念。

AccessKey和SecretKey

AccessKey用于标识客户端身份;SecretKey作为私钥保存在客户端服务器,不会在网络中传输,通常用于作为计算请求签名的密钥。使用AccessKey进行身份识别,使用SecretKey进行签名,完成客户端的接入、认证和授权。

Object

Object即对象,Object包含key和data,key为Object的名字,UTF-8编码后不能超过1024个字节,data是Object的数据。Object的key中可以带有斜杠,自动会在控制台里组织成目录结构。

Bucket

Bucket是S3的存储桶,S3是对象存储服务,Bucket就是存放Object的容器,每个Object必须存放在特定的Bucket中。

在Ceph RGW中每个用户最多创建1000个Bucket,每个Bucket中可以存放无数个Object。

Service

Service即服务,是S3提供给用户的虚拟存储空间,在这个虚拟空间里,一个用户可以拥有多个Bucket。

Region

在创建S3的Bucket时需要选择Region(区域),一般用于标识存储的物理位置,如华东区、华北区。Region的外网域名具体指明该区的外网接入地址。

CEPH OBJECT GATEWAY S3 API FEATURES SUPPORT中给出了RGW和S3 API的兼容列表。

ACL

访问控制权限ACL是对Bucket和Object相关的访问控制策略,支持READ, READ, FULL_CONTROL三种权限,具体内容可以参考Managing Access with ACLs

使用s3cmd命令行工具访问RGW

s3cmd是基于S3 API的命令行管理工具,我们先使用s3cmd来体验一下访问RGW服务。

安装s3cmd:

1yum install -y s3cmd

接下来配置s3cmd, 指定Access Key和Secret Key:

 1s3cmd --configure
 2
 3Enter new values or accept defaults in brackets with Enter.
 4Refer to user manual for detailed description of all options.
 5
 6Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.
 7Access Key: W0FE3UJ375EAHMT0660A
 8Secret Key: HeHbboOIfpc6N1lAxlCmW0S69owWBCBRQnL4BI6m
 9Default Region [US]:
10
11Encryption password is used to protect your files from reading
12by unauthorized persons while in transfer to S3
13Encryption password:
14Path to GPG program [/usr/bin/gpg]:
15
16When using secure HTTPS protocol all communication with Amazon S3
17servers is protected from 3rd party eavesdropping. This method is
18slower than plain HTTP, and can only be proxied with Python 2.7 or newer
19Use HTTPS protocol [Yes]: No
20
21On some networks all internet access must go through a HTTP proxy.
22Try setting it here if you can't connect to S3 directly
23HTTP Proxy server name:
24
25New settings:
26  Access Key: W0FE3UJ375EAHMT0660A
27  Secret Key: HeHbboOIfpc6N1lAxlCmW0S69owWBCBRQnL4BI6m
28  Default Region: US
29  Encryption password:
30  Path to GPG program: /usr/bin/gpg
31  Use HTTPS protocol: False
32  HTTP Proxy server name:
33  HTTP Proxy server port: 0
34
35Test access with supplied credentials? [Y/n] n
36
37Save settings? [y/N] y
38Configuration saved to '/root/.s3cfg'

修该生成的.s3fg配置文件:

1host_base = c1
2host_bucket = c1/%(bucket)

接下来体验一下:

创建Bucket:

1s3cmd mb s3://mybucket
2Bucket 's3://mybucket/' created

查看Bucket:

1s3cmd ls
22017-02-06 19:40  s3://mybucket

删除Bucket:

1s3cmd mb s3://mybucket1
2s3cmd rb s3://mybucket1

上传Object:

1s3cmd put hello.txt s3://mybucket
2upload: 'hello.txt' -> 's3://mybucket/hello.txt'  [1 of 1]
3 6 of 6   100% in    1s     3.97 B/s  done

查看Object:

1s3cmd ls s3://mybucket
22017-02-06 19:47         6   s3://mybucket/hello.txt

下载Object:

1cd /tmp
2s3cmd get s3://mybucket/hello.txt
3download: 's3://mybucket/hello.txt' -> './hello.txt'  [1 of 1]
4 6 of 6   100% in    0s  1265.82 B/s  done

删除bucket下所有对象:

1s3cmd del -rf s3://mybucket/
2
3s3cmd ls -r s3://mybucket

参考