S3 client 访问ceph rgw

S3 client 访问ceph rgw

安装配置S3 client:

安装,s3cmd是使用python编写的客户端:

$pip install s3cmd 

也可以使用yum 安装

$yum install s3cmd

验证安装是否成功:

$s3cmd --version
s3cmd version 1.5.2 #表示安装成功

为S3的访问创建账号:

sudo radosgw-admin user create --secret="yankunli" --uid="yankunli" --display-name="First User"
{ "user_id": "yankunli",
  "display_name": "First User",
  "email": "",
  "suspended": 0,
  "max_buckets": 1000,
  "auid": 0,
  "subusers": [],
  "keys": [ { "user": "yankunli", "access_key": "3WD7VXGJ8ZO0UBTFM5XR", "secret_key": "11111111"}],
  "swift_keys": [],
  "caps": [],
  "op_mask": "read, write, delete",
  "default_placement": "",
  "placement_tags": [],
  "bucket_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1},
  "user_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1},
  "temp_url_keys": []}

在创建用户时可以指定用的access key 和secret key,也可以让其自动产生,但是在返回的结果中可能包含转义字符,有些客户端不能识别,需要将其删除,或者重新生成。
同一个用户可以有多对access_key和secret_key,但是一个access_key只能对应一个用户。
S3 中access_key和secret_key分别扮演者用户名ID和用户密码的角色。
access_key–>用户名ID
secret_key–>用户密码

配置S3 client:

$ s3cmd --configure

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.
Access Key []: 3WD7VXGJ8ZO0UBTFM5XR
Secret Key []: 11111111
Default Region [US]: 

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: 
Path to GPG program [/usr/bin/gpg]: 

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP, and can only be proxied with Python 2.7 or newer
Use HTTPS protocol [No]: 

On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't connect to S3 directly
HTTP Proxy server name: 

New settings:
  Access Key: 3WD7VXGJ8ZO0UBTFM5XR
  Secret Key: 11111111
  Default Region: US
  Encryption password: 
  Path to GPG program: /usr/bin/gpg
  Use HTTPS protocol: False
  HTTP Proxy server name: 
  HTTP Proxy server port: 0

Test access with supplied credentials? [Y/n] n

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'

在这个交互配置过程中,只配置了其中access_key和secret_key,如果要正常使用自己搭建的存储还有3项需要配置:

  1. cloudfont_host
  2. host_base
  3. host_bucket
    其对应的配置如下:
$cat .s3cfg
 [default]
access_key = 3WD7VXGJ8ZO0UBTFM5XR
access_token = 
add_encoding_exts = 
add_headers = 
bucket_location = US
ca_certs_file = 
cache_file = 
check_ssl_certificate = True
cloudfront_host = <server-hostname>
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = UTF-8
encrypt = False
expiry_date = 
expiry_days = 
expiry_prefix = 
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase = 
guess_mime_type = True
host_base = <server-hostname>:<server_port>
host_bucket = %(bucket)s.<server-hostname>
human_readable_sizes = False
ignore_failed_copy = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
list_md5 = False
log_target_prefix = 
max_delete = -1
mime_type = 
multipart_chunk_size_mb = 15
preserve_attrs = True
progress_meter = True
proxy_host = 
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 4096
reduced_redundancy = False
restore_days = 1
secret_key = 11111111
send_chunk = 4096
server_side_encryption = False
signature_v2 = False
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
urlencoding_mode = normal
use_https = False
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com/
website_error = 
website_index = index.html

至此S3 client的配置就结束了,可以测试是否成功。

测试S3 client:

1.创建bucket:

$ s3cmd mb s3://first_bucket
Bucket 's3://first_bucket/' created

2.列举buckets:

$ s3cmd -v  ls
2015-09-14 06:31  s3://first_bucket

3.删除bucket:

$ s3cmd rb s3://first_bucket
Bucket 's3://first_bucket/' removed

4.上传文件对象:

$ s3cmd put file.txt s3://first_bucket
file.txt -> s3://first_bucket/file.txt  [1 of 1]
 12 of 12   100% in    0s   180.54 B/s  done

s3cmd的操作方法比较多,其他方法的使用可以使用man s3cmd查看。
参考:Amazon S3 - What are my AWS Access and Secret Key?

你可能感兴趣的:(ceph,radosgw,s3cmd)