2016年7月13日 星期三

[docker] run s3 on Ceph in docker containers 在 docker 來執行 s3 ceph



怎麼使用 docker 來執行 ceph 呢?

ceph 官方有提供一個可以很快搭建開發環境的 docker container

ceph-docker/ceph-releases/jewel/ubuntu/14.04/demo at master · ceph/ceph-docker
https://github.com/ceph/ceph-docker/tree/master/ceph-releases/jewel/ubuntu/14.04/demo


先 ifconfig 看一下目前自己ip

docker run -d --net=host -v /etc/ceph:/etc/ceph -e MON_IP=10.1.193.59 -e CEPH_PUBLIC_NETWORK=10.1.193.0/24 ceph/demo

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
662e2c899f4c        ceph/demo           "/entrypoint.sh"    35 minutes ago      Up 35 minutes                           tender_carson

為了執行 s3 ceph 所以使用  radosgw 來建立user 取得 access_key 與 secret_key

 # radosgw-admin user create --uid="pc" --display-name="pc"          
2016-07-13 12:08:14.244392 7f1bb4069900  0 RGWZoneParams::create(): error creating default zone params: (17) File exists
{
    "user_id": "pc",
    "display_name": "pc",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [],
    "keys": [
        {
            "user": "pc",
            "access_key": "F47DG9NWH4HNMZ06EAYD",
            "secret_key": "9FdywQQltiJHrHuOwfRtDE0HVc6exIAJZ1PHjLDa"
        }
    ],
    "swift_keys": [],
    "caps": [],
    "op_mask": "read, write, delete",
    "default_placement": "",
    "placement_tags": [],
    "bucket_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "user_quota": {
        "enabled": false,
        "max_size_kb": -1,
        "max_objects": -1
    },
    "temp_url_keys": []
}


可以撰寫一個簡單的s3 程式

Python S3 Examples — Ceph Documentation 

import boto
import boto.s3.connection
access_key = 'put your access key here!'
secret_key = 'put your secret key here!'

conn = boto.connect_s3(
        aws_access_key_id = access_key,
        aws_secret_access_key = secret_key,
        host = 'objects.dreamhost.com',
        #is_secure=False,               # uncomment if you are not using ssl
        calling_format = boto.s3.connection.OrdinaryCallingFormat(),
        )

conn.create_bucket('my-new-bucket')

for bucket in conn.get_all_buckets():
    print bucket
這樣就可以看到有create bucket了

沒有留言:

張貼留言