<center></center>node
原文地址:RGW 安裝和建立python
本文經過ceph-deploy
安裝和建立RGW
,而後分別建立S3
和Swift
接口並提供了相應的方案。swift
Ceph RGW
基於librados
,是爲應用提供RESTful
類型的對象存儲接口。RGW
提供兩種類型的接口:app
Amazon S3 RESTful API
OpenStack Swift API
S3
和Swift API
共享同一個命名空間,因此可使用兩種API
訪問相同的數據。curl
參考連接: Ceph:建立RGW工具
cd /etc/ceph
我這邊是node1
,根據hostname
對號入座就行測試
ceph-deploy install --rgw node1
ceph-deploy gatherkeys node1
ceph-deploy rgw create node1
Ceph CLI
工具須要在管理員模式下運行,所以須要執行如下命令ui
ceph-deploy admin node1
一旦RGW
開始運行,就能夠經過端口7480
(若是沒有修改的話)來訪問。如: http://node1:7480
,若是RGW
運行正常,它應該返回相似的信息:url
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
命令實現了這些功能。spa
其中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
了。