[关闭]
@tony-yin 2017-11-08T17:26:45.000000Z 字数 4100 阅读 1520

Ceph RGW 安装和创建

Ceph RGW


本文通过ceph-deploy安装和创建RGW,然后分别创建S3Swift接口并提供了相应的方案。

Ceph RGW基于librados,是为应用提供RESTful类型的对象存储接口。RGW提供两种类型的接口:

S3Swift API共享同一个命名空间,所以可以使用两种API访问相同的数据。

参考链接: Ceph:创建RGW

部署 RGW

进入 ceph 目录

  1. cd /etc/ceph

安装 ceph object gateway

我这边是node1,根据hostname对号入座就行

  1. ceph-deploy install --rgw node1

Gather keys

  1. ceph-deploy gatherkeys node1

创建 rgw 实例

  1. ceph-deploy rgw create node1

Ceph CLI

Ceph CLI工具需要在管理员模式下运行,因此需要执行以下命令

  1. ceph-deploy admin node1

测试是否安装成功

一旦RGW开始运行,就可以通过端口7480(如果没有修改的话)来访问。如:
http://node1:7480,如果RGW运行正常,它应该返回类似的信息:

  1. This XML file does not appear to have any style information associated with it. The document tree is shown below.
  2. <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  3. <Owner>
  4. <ID>anonymous</ID>
  5. <DisplayName/>
  6. </Owner>
  7. <Buckets/>
  8. </ListAllMyBucketsResult>

创建 S3 用户

想正常的访问RGW,需要创建相应的RGW用户,并赋予相应的权限,radosgw-admin命令实现了这些功能。

其中keys中的useraccess_keysecret_key用于之后的S3接口访问确认

  1. [root@node1 ~]# radosgw-admin user create --uid="admin" --display-name="First user"
  2. 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.
  3. {
  4. "user_id": "admin",
  5. "display_name": "First user",
  6. "email": "",
  7. "suspended": 0,
  8. "max_buckets": 1000,
  9. "auid": 0,
  10. "subusers": [],
  11. "keys": [
  12. {
  13. "user": "admin",
  14. "access_key": "1MWH3LWM1BS4ZF4HN5IH",
  15. "secret_key": "cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O"
  16. }
  17. ],
  18. "swift_keys": [],
  19. "caps": [],
  20. "op_mask": "read, write, delete",
  21. "default_placement": "",
  22. "placement_tags": [],
  23. "bucket_quota": {
  24. "enabled": false,
  25. "check_on_raw": false,
  26. "max_size": -1,
  27. "max_size_kb": 0,
  28. "max_objects": -1
  29. },
  30. "user_quota": {
  31. "enabled": false,
  32. "check_on_raw": false,
  33. "max_size": -1,
  34. "max_size_kb": 0,
  35. "max_objects": -1
  36. },
  37. "temp_url_keys": [],
  38. "type": "rgw"
  39. }

创建 Swift 用户

Swift用户是作为子用户subuser被创建的,执行以下命令:

其中swift_keys中的usersecret_key用于之后的swift接口访问确认

  1. [root@node1 ~]# radosgw-admin subuser create --uid=admin --subuser=admin:swift --access=full
  2. 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.
  3. {
  4. "user_id": "admin",
  5. "display_name": "First user",
  6. "email": "",
  7. "suspended": 0,
  8. "max_buckets": 1000,
  9. "auid": 0,
  10. "subusers": [
  11. {
  12. "id": "admin:swift",
  13. "permissions": "full-control"
  14. }
  15. ],
  16. "keys": [
  17. {
  18. "user": "admin",
  19. "access_key": "1MWH3LWM1BS4ZF4HN5IH",
  20. "secret_key": "cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O"
  21. }
  22. ],
  23. "swift_keys": [
  24. {
  25. "user": "admin:swift",
  26. "secret_key": "PKRXACd8Ysgx7MCTjd9gHnL3sdpJ2J6wsuy2IS0P"
  27. }
  28. ],
  29. "caps": [],
  30. "op_mask": "read, write, delete",
  31. "default_placement": "",
  32. "placement_tags": [],
  33. "bucket_quota": {
  34. "enabled": false,
  35. "check_on_raw": false,
  36. "max_size": -1,
  37. "max_size_kb": 0,
  38. "max_objects": -1
  39. },
  40. "user_quota": {
  41. "enabled": false,
  42. "check_on_raw": false,
  43. "max_size": -1,
  44. "max_size_kb": 0,
  45. "max_objects": -1
  46. },
  47. "temp_url_keys": [],
  48. "type": "rgw"
  49. }

测试 S3 接口

需要创建一个python测试脚本来测试S3访问。该脚本会连接RGW,创建一个bucket并打印输出所有的bucket。其中,变量access_keysecret_access的值,来自于创建S3用户命令时,radosgw-admin命令返回的keys->access_keykeys->secret_key

安装 python-boto库

执行以下步骤,首先安装python-boto库,该库用于连接S3

  1. yum install -y python-boto

创建脚本

  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import boto.s3.connection
  4. access_key = '1MWH3LWM1BS4ZF4HN5IH'
  5. secret_key ='cuObxYgtl1lJgqNxOIpENycVqXfxLxZ8z5IXDM0O'
  6. conn = boto.connect_s3(
  7. aws_access_key_id=access_key,
  8. aws_secret_access_key=secret_key,
  9. host='{hostname}',port={port},
  10. is_secure=False,calling_format=boto.s3.connection.OrdinaryCallingFormat(),
  11. )
  12. bucket = conn.create_bucket('my-new-bucket')
  13. for bucket in conn.get_all_buckets():
  14. print"{name} {created}".format(
  15. name=bucket.name,
  16. created=bucket.creation_date,
  17. )

需要将上面的{hostname}替换成对应的hostname或者IP,例如192.168.1.1;将{port}替换成RGW运行的端口,默认为7480;前者为字符串,后者为数字

执行脚本测试

  1. [root@node1 ceph]# python s3test.py
  2. my-new-bucket 2017-11-01T10:58:53.670Z

测试 Swift 接口

安装相关软件包

  1. pip installpython-setuptools
  2. pip installpython-swiftclient

命令行访问

替换{ip}{port}{swift_secret_key},其中{swift_secret_key}为创建Swift用户时,radosgw-admin命令返回的swift_keys->secret_key的值

  1. swift -A http://{ip}:{port}/auth/1.0 -Utestuser:swift -K '{swift_secret_key}' list

正常输出应该如下:

  1. [root@node1 ceph]# swift -Ahttp://192.168.1.1:7480/auth/1.0 -U admin:swift -K 'PKRXACd8Ysgx7MCTjd9gHnL3sdpJ2J6wsuy2IS0P' list
  2. my-new-bucket

小结

ceph-deploy命令,大大地简化了对Ceph集群和RGW的安装和配置,可以很快速的搭建测试环境,达到测试效果,但如果要在生产环境中应用的话,可能需要手动做一些配置就,不能完全依赖ceph-deploy了。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注