@tony-yin
2017-11-08T17:26:45.000000Z
字数 4100
阅读 1520
Ceph
RGW
本文通过ceph-deploy
安装和创建RGW
,然后分别创建S3
和Swift
接口并提供了相应的方案。
Ceph RGW
基于librados
,是为应用提供RESTful
类型的对象存储接口。RGW
提供两种类型的接口:
Amazon S3 RESTful API
OpenStack Swift API
S3
和Swift API
共享同一个命名空间,所以可以使用两种API
访问相同的数据。
参考链接: Ceph:创建RGW
cd /etc/ceph
我这边是node1
,根据hostname
对号入座就行
ceph-deploy install --rgw node1
ceph-deploy gatherkeys node1
ceph-deploy rgw create node1
Ceph CLI
工具需要在管理员模式下运行,因此需要执行以下命令
ceph-deploy admin node1
一旦RGW
开始运行,就可以通过端口7480
(如果没有修改的话)来访问。如:
http://node1:7480
,如果RGW
运行正常,它应该返回类似的信息:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>anonymous</ID>
<DisplayName/>
</Owner>
<Buckets/>
</ListAllMyBucketsResult>
想正常的访问RGW
,需要创建相应的RGW
用户,并赋予相应的权限,radosgw-admin
命令实现了这些功能。
其中keys
中的user
,access_key
和secret_key
用于之后的S3
接口访问确认
[root@node1 ~]# radosgw-admin user create --uid="admin" --display-name="First user"
2017-11-08 16:51:39.883217 7fb6868fac40 0 WARNING: detected a version of libcurl which contains a bug in curl_multi_wait(). enabling a workaround that may degrade performance slightly.
{
"user_id": "admin",
"display_name": "First user",
"email": "",
"suspended": 0,
"max_buckets": 1000,
"auid": 0,
"subusers": [],
"keys": [
{
"user": "admin",
"access_key": "1MWH3LWM1BS4ZF4HN5IH",
"secret_key": "cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O"
}
],
"swift_keys": [],
"caps": [],
"op_mask": "read, write, delete",
"default_placement": "",
"placement_tags": [],
"bucket_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"user_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"temp_url_keys": [],
"type": "rgw"
}
Swift
用户是作为子用户subuser
被创建的,执行以下命令:
其中swift_keys
中的user
和secret_key
用于之后的swift
接口访问确认
[root@node1 ~]# radosgw-admin subuser create --uid=admin --subuser=admin:swift --access=full
2017-11-08 16:55:05.371174 7fb4cbfc2c40 0 WARNING: detected a version of libcurl which contains a bug in curl_multi_wait(). enabling a workaround that may degrade performance slightly.
{
"user_id": "admin",
"display_name": "First user",
"email": "",
"suspended": 0,
"max_buckets": 1000,
"auid": 0,
"subusers": [
{
"id": "admin:swift",
"permissions": "full-control"
}
],
"keys": [
{
"user": "admin",
"access_key": "1MWH3LWM1BS4ZF4HN5IH",
"secret_key": "cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O"
}
],
"swift_keys": [
{
"user": "admin:swift",
"secret_key": "PKRXACd8Ysgx7MCTjd9gHnL3sdpJ2J6wsuy2IS0P"
}
],
"caps": [],
"op_mask": "read, write, delete",
"default_placement": "",
"placement_tags": [],
"bucket_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"user_quota": {
"enabled": false,
"check_on_raw": false,
"max_size": -1,
"max_size_kb": 0,
"max_objects": -1
},
"temp_url_keys": [],
"type": "rgw"
}
需要创建一个python
测试脚本来测试S3
访问。该脚本会连接RGW
,创建一个bucket
并打印输出所有的bucket
。其中,变量access_key
和secret_access
的值,来自于创建S3
用户命令时,radosgw-admin
命令返回的keys->access_key
和keys->secret_key
。
执行以下步骤,首先安装python-boto
库,该库用于连接S3
:
yum install -y python-boto
#!/usr/bin/python
# -*- coding:utf-8 -*-
import boto.s3.connection
access_key = '1MWH3LWM1BS4ZF4HN5IH'
secret_key ='cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O'
conn = boto.connect_s3(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
host='{hostname}',port={port},
is_secure=False,calling_format=boto.s3.connection.OrdinaryCallingFormat(),
)
bucket = conn.create_bucket('my-new-bucket')
for bucket in conn.get_all_buckets():
print"{name} {created}".format(
name=bucket.name,
created=bucket.creation_date,
)
需要将上面的{hostname}
替换成对应的hostname
或者IP
,例如192.168.1.1
;将{port}
替换成RGW
运行的端口,默认为7480
;前者为字符串,后者为数字
[root@node1 ceph]# python s3test.py
my-new-bucket 2017-11-01T10:58:53.670Z
pip installpython-setuptools
pip installpython-swiftclient
替换{ip}
,{port}
和{swift_secret_key}
,其中{swift_secret_key}
为创建Swift
用户时,radosgw-admin
命令返回的swift_keys->secret_key
的值
swift -A http://{ip}:{port}/auth/1.0 -Utestuser:swift -K '{swift_secret_key}' list
正常输出应该如下:
[root@node1 ceph]# swift -Ahttp://192.168.1.1:7480/auth/1.0 -U admin:swift -K 'PKRXACd8Ysgx7MCTjd9gHnL3sdpJ2J6wsuy2IS0P' list
my-new-bucket
ceph-deploy
命令,大大地简化了对Ceph
集群和RGW的
安装和配置,可以很快速的搭建测试环境,达到测试效果,但如果要在生产环境中应用的话,可能需要手动做一些配置就,不能完全依赖ceph-deploy
了。