1、什么是对象存储python
一、对象存储,也就是键值存储,经过其接口指令,也就是简单GET、PUT、DEL和其余扩展指令,向存储服务上传下载数据等nginx
二、对象存储中全部数据都被认为是一个对象。因此,任何数据均可以存入对象存储服务器,如图片、视频、音频等web
2、Ceph 对象存储的构成apache
Ceph 对象存储主要是经过 RGW 来实现,那么什么是 RGW 呢?swift
一、RGW 即 Rados Gateway 的全称。vim
二、RGW 是 Ceph 对象存储网关,用于向客户端应用程序提供存储界面,提供 RESTful API 访问接口。浏览器
三、RGW 能够部署多台作为 高可用和负载均衡,拓扑以下图:bash
3、部署 RGW 服务服务器
一、在 ceph-a 上经过 ceph-deploy 将 ceph-radosgw 软件包安装到 ceph-e 中负载均衡
[root@ceph-a ~]# ceph-deploy install --rgw ceph-e
二、将配置文件、密钥文件同步到 ceph-e
[root@ceph-a ceph]# ceph-deploy admin ceph-e
三、启动一个RGW服务
[root@ceph-a ceph]# ceph-deploy rgw create ceph-e
四、登录 ceph-e 验证服务是否启动
[root@ceph-e yum.repos.d]# ps -ef | grep radosgw
五、查看 rgw 状态
[root@ceph-e yum.repos.d]# systemctl status ceph-radosgw\*
六、查看端口是否有监听
[root@ceph-e yum.repos.d]# netstat -tpnl | grep 7480
经过以上 6 步,咱们的 RGW 服务已经能够成功运行了。
七、RGW 内建了一个名为 civetweb 的 web 服务器,这个服务器与 apache/nginx 相似,既然是 web 服务,那么使用 80 端口就更为方便,为了应用便捷,能够将默认的 7480 端口修改成 80 端口。
修改 ceph-e 节点的 ceph.conf 配置文件,追加如下内容:
[root@ceph-e ceph]# vim ceph.conf [client.rgw.ceph-e] host = ceph-e rgw_frontends = "civetweb port=80"
保存退出并重启服务
[root@ceph-e ceph]# systemctl restart ceph-radosgw.target
八、查看端口是否修改为功
[root@ceph-e ceph]# netstat -tpnl
九、验证
打开浏览器,输入 http://192.168.20.148,以下图
或者在命令行中输入 curl http://192.168.20.148 \r ,\r表示发送回车键指令,以下如
4、使用第三方软件访问
一、使用亚马逊 s3 客户端进行访问
①、登录 ceph-e(RGW)建立用户
[root@ceph-e radosgw]# radosgw-admin user create --uid="radosgw" --display-name="First User"
user: radosgw access_key: N6ALEK0KS0ISYCIM5JBG secret_key: qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM
②、受权用户,容许 radosgw 读写 users 信息:
[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="users=*"
容许 radosgw 读写全部的usage信息:
[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="usage=read,write"
③、建立子用户,作为后面 swift 客户端访问时使用
[root@ceph-e radosgw]# radosgw-admin subuser create --uid=radosgw --subuser=radosgw:swift --access=full
④、建立密钥
[root@ceph-e radosgw]# radosgw-admin key create --subuser=radosgw:swift --key-type=swift --gen-secret
user: radosgw:swift secret_key: NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl
⑤、在 ceph-f 安装 s3 客户端软件
首先,咱们找一下 yum 源有没有 s3 的 rpm 包
[root@ceph-f ~]# yum list | grep s3
发现,有 s3 的 rpm 包,所以直接安装便可
[root@ceph-f ~]# yum -y install s3cmd.noarch
⑥、对 s3 进行配置
[root@ceph-f ~]# s3cmd --configure
注意:
Access Key: N6ALEK0KS0ISYCIM5JBG Secret Key: qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM Default Region [US]: #这里必定不要修改,不然后面会报错 S3 Endpoint [s3.amazonaws.com]: 192.168.20.148 DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: %(bucket)s.192.168.20.148 bucket #至关于百度网盘的建立文件夹,这里是固定格式 Path to GPG program [/usr/bin/gpg]: #保持默认 Use HTTPS protocol [Yes]: no #这里写 no ,由于没有提供 https 端口 HTTP Proxy server name: #这里不用写,由于没有代理 Test access with supplied credentials? [Y/n] y Save settings? [y/N] y
⑦、客户端测试,查看内容
[root@ceph-f ~]# s3cmd ls
空的,由于就像百度云盘同样,刚申请,没有建立,因此是空的
⑧、建立存储数据的 bucket (相似于存储数据的目录)要求 xxx_yyy 格式
[root@ceph-f ~]# s3cmd mb s3://cephdir
发现报错了,看上图,发现,出错是由于咱们的写的格式不正确,按照正确的格式从新书写,再来一次
[root@ceph-f ~]# s3cmd mb s3://ceph_dir
如上图,成功了
⑨、再次查看客户端内容
[root@ceph-f ~]# s3cmd ls
这里提供 s3 的测试脚本
[root@ceph-f ~]# yum -y install python-boto [root@ceph-f ~]# vim s3test.py
import boto.s3.connection access_key = 'N6ALEK0KS0ISYCIM5JBG' secret_key = 'qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM' conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host='ceph-e', port=80, is_secure=False, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) bucket = conn.create_bucket('xxx_yyy') for bucket in conn.get_all_buckets(): print "{name} {created}".format( name=bucket.name, created=bucket.creation_date, )
在使用时,请替换本身的 access_key、secret_key、主机名和端口
二、swift 接口测试
①、须要安装如下软件包
[root@ceph-f ~]# yum install python-setuptools [root@ceph-f ~]# easy_install pip [root@ceph-f ~]# pip install --upgrade setuptools [root@ceph-f ~]# pip install --upgrade python-swiftclient
②、命令行访问
swift -A http://192.168.20.148/auth/v1.0 -U radosgw:swift -K NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl list
swift -A http://192.168.20.148/auth/v1.0 -U radosgw:swift -K NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl stat -v
这里提供 swift 的测试脚本:
[root@ceph-f ~]# vim swift.py
import swiftclient user = 'radosgw:swift' key = 'NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl' conn = swiftclient.Connection( user=user, key=key, authurl='http://192.168.20.148/auth/v1.0', ) for container in conn.get_account()[1]: print container['name']
在使用时,请替换本身的 access_key、secret_key、authurl
到此,的 Ceph 对象存储已经完结,若是各位大侠有什么不明白的地方,请参考官网文档。
关于 Ceph 集群的实现,请参阅小弟的另一篇博文:http://www.javashuo.com/article/p-ghmqdwwp-cq.html
关于 Ceph 块设备的应用,请参阅小弟的另一篇博文:http://www.javashuo.com/article/p-wsutnfvb-n.html
关于 CephFS 文件系统的应用,请参阅小弟的另一篇博文:http://www.javashuo.com/article/p-clfsvaka-x.html
5、总结
Ceph 对象存储目前尚不不稳定,且官方文档较旧,这里只作大概讲解,不作深刻研究。