Ceph的安装就不多说了,本来是只想用rbd进行块设备访问配搭kvm的。

同事也搭好了rgw,正好之前用过amazon的s3,s3cmd用起来十分爽啊,那么怎么用s3cmd对ceph进行访问呢?

过程如下:

首先Ceph是luminous,然后用ceph-deploy安装,安装用户是cephuser

那么登录后用cephuser的身份sudo进行操作,直接用root是不行的,注意

sudo radosgw-admin user create --uid="bajie" --display-name="Ba Jie"  
{
    "user_id": "bajie",
    "display_name": "Ba Jie",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [],
    "keys": [
        {
            "user": "bajie",
            "access_key": "7SIW23M9A411SY2X3H8L",
            "secret_key": "CTSMz1UqVj4Ft4IGe4ibVFRwD9qN6iIjnGIxe9Ns"
        }
    ],
    "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"
}

ok,其实有用的就2行

            "access_key": "7SIW23M9A411SY2X3H8L"
            "secret_key": "CTSMz1UqVj4Ft4IGe4ibVFRwD9qN6iIjnGIxe9Ns"

然后就装s3cmd

sudo yum install s3cmd  

接下来,看看我们的rgw跑在哪台机器的哪个端口上:

ps ax|grep radosgw  
 28861 ?        Ssl    6:36 /usr/bin/radosgw -f --cluster ceph --name client.rgw.vis-16-10-81 --setuser ceph --setgroup ceph

lsof -p 28861|grep LISTEN  
radosgw 28861 ceph   27u  IPv4              99863      0t0       TCP *:7480 (LISTEN)  

跑在172.16.10.81:7480端口上。

我们手动生成.s3cfg文件

cat<<EOF>~/.s3cfg  
[default]
access_key = 7SIW23M9A411SY2X3H8L  
host_base = 172.16.10.81:7480  
host_bucket = 172.16.10.81:7480/%(bucket)  
secret_key = CTSMz1UqVj4Ft4IGe4ibVFRwD9qN6iIjnGIxe9Ns  
cloudfront_host = 172.16.10.81:7480  
use_https = False  
EOF  

依样画葫芦即可。

然后运行s3cmd

#建桶
s3cmd mb s3://iso  
#放文件进筒
s3cmd put ubuntu-16.04-desktop-amd64.iso s3://iso/  
#从桶里把文件取出来
s3cmd get s3://iso/ubuntu-16.04-desktop-amd64.iso  

然后如果想编程,就装boto库

sudo yum install -y python-boto  

写个测试程序s3.py

import boto.s3.connection

access_key = '7SIW23M9A411SY2X3H8L'  
secret_key = 'CTSMz1UqVj4Ft4IGe4ibVFRwD9qN6iIjnGIxe9Ns'  
conn = boto.connect_s3(  
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key,
        host='172.16.10.81', port=7480,
        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,
    )

运行s3.py,然后s3cmd ls一下就可以了:

s3cmd ls  
2018-04-28 05:29  s3://my-new-bucket  
comments powered by Disqus