Aug 102015
 

这是学习 构建可靠的S3服务 的过程。原文提供视频,不过看视频实在太累。不过总算是把实验做完。

Docker的源都在国外,所以我是选择青云的香港节点来做测试,这样简单很多。这真的是我第一次完整完成Docker的实验。并且这个实验还是很值得记录一下。

青云使用基础网络,创建一个虚拟机,Ubuntu 14.04,绑定公网的IP。ssh到虚拟机里。

安装docker

感觉Ubuntu 14.04带的docker比较旧,所以我干脆就直接安装最新的版本的docker。

http://linuxkurser.nu/wp-content/uploads/2015/04/Upgrade-to-Docker-1.6-Ubuntu-14.pdf

curl -sSL https://test.docker.com/ubuntu | sh

查看docker的版本

# docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): f45ba9d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): f45ba9d
OS/Arch (server): linux/amd64

1.7的版本,应该是最新的。

查看网络

# ifconfig
docker0   Link encap:Ethernet  HWaddr 56:84:7a:fe:97:99  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 52:54:38:23:ee:12  
          inet addr:10.70.74.144  Bcast:10.70.74.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:38ff:fe23:ee12/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9828 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6498 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13266351 (13.2 MB)  TX bytes:589469 (589.4 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1184 (1.1 KB)  TX bytes:1184 (1.1 KB)

 

下载docker的镜像,ip地址,需要替换成eth0的IP

docker run -d –net=host -e MON_IP=10.70.74.144 -e CEPH_NETWORK=10.70.74.0/24 ceph/demo

装完后,可以用命令查看

root@i-dczpde51:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
116ae154cae4        ceph/demo           "/entrypoint.sh"    37 seconds ago      Up 36 seconds                           gloomy_jang

 

进入docker ,就是上面的容器的ID

docker exec -i -t 116ae154cae4 /bin/bash

查看ceph

# ps aux | grep "ceph"
root         1  0.1  2.1 563436 22280 ?        Ssl  15:04   0:00 /usr/bin/python /usr/bin/ceph -w
root        34  0.2  2.3 217052 23988 ?        Sl   15:04   0:00 ceph-mon -i i-dczpde51 --public-addr 10.70.74.144:6789
root       203  0.9  2.9 681016 29788 ?        Ssl  15:04   0:00 ceph-osd -i 0 -k /var/lib/ceph/osd/ceph-0/keyring
root       414  0.0  1.1 236640 11428 ?        Ssl  15:04   0:00 ceph-mds --cluster=ceph -i 0
root       472  0.1  2.3 1707856 24360 ?       Ssl  15:04   0:00 radosgw -c /etc/ceph/ceph.conf -n client.radosgw.gateway -k /var/lib/ceph/radosgw/i-dczpde51/keyring --rgw-socket-path= --rgw-frontends=civetweb port=80
root       473  0.4  3.1 710596 32200 ?        Sl   15:04   0:00 /usr/bin/python /usr/bin/ceph-rest-api -n client.admin
root       689  0.0  0.0   8868   720 ?        S+   15:06   0:00 grep --color=auto ceph

 

# ceph -s
    cluster b700af15-ed1d-44ea-bdc7-aac227c24a8d
     health HEALTH_OK
     monmap e1: 1 mons at {i-dczpde51=10.70.74.144:6789/0}
            election epoch 2, quorum 0 i-dczpde51
     mdsmap e5: 1/1/1 up {0=0=up:active}
     osdmap e16: 1 osds: 1 up, 1 in
      pgmap v19: 120 pgs, 8 pools, 2810 bytes data, 63 objects
            2415 MB used, 16572 MB / 20028 MB avail
                 120 active+clean

创建用户,下面命令,你最好是手工敲入,我折腾了半天,才发现进入docker,我的secureCRT的粘贴好像有点不一样。

radosgw-admin user create --uid="johndoe" --display-name="John Doe" --email=john@example.com

下面是输出

{
    "user_id": "johndoe",
    "display_name": "John Doe",
    "email": "john@example.com",
    "suspended": 0,
    "max_buckets": 1000,
    "auid": 0,
    "subusers": [],
    "keys": [
        {
            "user": "johndoe",
            "access_key": "XRCME1D7HXDC3JRBBU1Y",
            "secret_key": "2g7H3mscKD0V6Kj1fkkJuIVNOH8OmU8XuovWP8+s"
        }
    ],
    "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": []
}

重点是access key和secret key。

apt-get update -y
apt-get install -y python
apt-get install -y python-pip
pip install boto
pip install ipython
pip install s3cmd
apt-get install -y vim

参考这里 https://github.com/tobegit3hub/python_s3/blob/master/list_buckets.py

记得替换成自己的access key和secret_key

# ipython
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import boto

In [2]: import boto.s3.connection                                              

In [3]: access_key =  'XRCME1D7HXDC3JRBBU1Y'                                   

In [4]: secret_key = '2g7H3mscKD0V6Kj1fkkJuIVNOH8OmU8XuovWP8+s'                

In [5]: conn = boto.connect_s3(                                                
   ...:         aws_access_key_id = access_key,                                
   ...:         aws_secret_access_key = secret_key,                            
   ...:         host = 'localhost',                                            
   ...:         is_secure=False,                                               
   ...:         calling_format = boto.s3.connection.OrdinaryCallingFormat(),   
   ...:         )                                                              

In [6]: com                                                                    
compile  complex  

In [6]: conn.get_all_bucketes()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-bd413d097011> in <module>()
----> 1 conn.get_all_bucketes()

AttributeError: 'S3Connection' object has no attribute 'get_all_bucketes'

In [7]: conn.get_all_buckets()                                                 
Out[7]: []

In [8]: conn.create_bucket("chenshake")                                        
Out[8]: <Bucket: chenshake>

In [9]: conn.get_all_buckets()                                                 
Out[9]: [<Bucket: chenshake>]

In [10]:                        

成功创建了一个bucket chenshake

 Leave a Reply

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.