RGW 安裝和建立

<center>Ceph RGW</center>node

原文地址:RGW 安裝和建立python

本文經過ceph-deploy安裝和建立RGW,而後分別建立S3Swift接口並提供了相應的方案。swift

Ceph RGW基於librados,是爲應用提供RESTful類型的對象存儲接口。RGW提供兩種類型的接口:app

  • S3:兼容Amazon S3 RESTful API
  • Swift:兼容OpenStack Swift API

S3Swift API共享同一個命名空間,因此可使用兩種API訪問相同的數據。curl

參考連接: Ceph:建立RGW工具

部署 RGW

進入 ceph 目錄

cd /etc/ceph

安裝 ceph object gateway

我這邊是node1,根據hostname對號入座就行測試

ceph-deploy install --rgw node1

Gather keys

ceph-deploy gatherkeys node1

建立 rgw 實例

ceph-deploy rgw create node1

Ceph CLI

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>

建立 S3 用戶

想正常的訪問RGW,須要建立相應的RGW用戶,並賦予相應的權限,radosgw-admin命令實現了這些功能。spa

其中keys中的useraccess_keysecret_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 用戶

Swift用戶是做爲子用戶subuser被建立的,執行如下命令:

其中swift_keys中的usersecret_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"
}

測試 S3 接口

須要建立一個python測試腳原本測試S3訪問。該腳本會鏈接RGW,建立一個bucket並打印輸出全部的bucket。其中,變量access_keysecret_access的值,來自於建立S3用戶命令時,radosgw-admin命令返回的keys->access_keykeys->secret_key

安裝 python-boto庫

執行如下步驟,首先安裝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

測試 Swift 接口

安裝相關軟件包

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了。

相關文章
相關標籤/搜索