温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Ceph 对象存储

发布时间:2020-07-27 12:15:36 来源:网络 阅读:2473 作者:司徒晓宇 栏目:大数据

一、什么是对象存储

1、对象存储,也就是键值存储,通过其接口指令,也就是简单GET、PUT、DEL和其他扩展指令,向存储服务上传下载数据等

2、对象存储中所有数据都被认为是一个对象。所以,任何数据都可以存入对象存储服务器,如图片、视频、音频等

二、Ceph 对象存储的构成

Ceph 对象存储主要是通过 RGW  来实现,那么什么是 RGW 呢?

1、RGW 即 Rados Gateway 的全称。

2、RGW 是 Ceph 对象存储网关,用于向客户端应用程序提供存储界面,提供 RESTful API 访问接口。

3、RGW 可以部署多台做为 高可用和负载均衡,拓扑如下图:

Ceph 对象存储

三、部署 RGW 服务

1、在 ceph-a 上通过 ceph-deploy 将 ceph-radosgw 软件包安装到 ceph-e 中

[root@ceph-a ~]# ceph-deploy install --rgw ceph-e

Ceph 对象存储

2、将配置文件、密钥文件同步到 ceph-e

[root@ceph-a ceph]# ceph-deploy admin ceph-e

Ceph 对象存储

3、启动一个RGW服务

[root@ceph-a ceph]# ceph-deploy rgw create ceph-e

Ceph 对象存储

4、登陆 ceph-e 验证服务是否启动

[root@ceph-e yum.repos.d]# ps -ef | grep radosgw

Ceph 对象存储

5、查看 rgw 状态

[root@ceph-e yum.repos.d]# systemctl status ceph-radosgw\*

Ceph 对象存储

6、查看端口是否有监听

[root@ceph-e yum.repos.d]# netstat -tpnl | grep 7480

Ceph 对象存储

通过以上 6 步,我们的 RGW 服务已经可以成功运行了。

7、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

8、查看端口是否修改成功

[root@ceph-e ceph]# netstat -tpnl

Ceph 对象存储

9、验证

打开浏览器,输入 http://192.168.20.148,如下图

Ceph 对象存储

或者在命令行中输入 curl http://192.168.20.148 \r ,\r表示发送回车键指令,如下如

Ceph 对象存储

四、使用第三方软件访问

1、使用亚马逊 s3 客户端进行访问

①、登陆 ceph-e(RGW)创建用户

[root@ceph-e radosgw]# radosgw-admin user create --uid="radosgw" --display-name="First User"

Ceph 对象存储

user: radosgw
access_key: N6ALEK0KS0ISYCIM5JBG
secret_key: qK9hrpX2uwna4elPP1VsuErmAHBw3So40fE2K4yM

②、授权用户,允许 radosgw 读写 users 信息:

[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="users=*"

Ceph 对象存储

允许 radosgw 读写所有的usage信息:

[root@ceph-e radosgw]# radosgw-admin caps add --uid=radosgw --caps="usage=read,write"

Ceph 对象存储

③、创建子用户,做为后面 swift 客户端访问时使用

[root@ceph-e radosgw]# radosgw-admin subuser create --uid=radosgw --subuser=radosgw:swift --access=full

Ceph 对象存储

④、创建密钥

[root@ceph-e radosgw]# radosgw-admin key create --subuser=radosgw:swift --key-type=swift --gen-secret

Ceph 对象存储

user: radosgw:swift
secret_key: NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl

⑤、在 ceph-f 安装 s3 客户端软件

首先,我们找一下 yum 源有没有 s3 的 rpm 包

[root@ceph-f ~]# yum list | grep s3

Ceph 对象存储

发现,有 s3 的 rpm 包,因此直接安装即可

[root@ceph-f ~]# yum -y install s3cmd.noarch

⑥、对 s3 进行配置

[root@ceph-f ~]# s3cmd --configure

Ceph 对象存储

注意:

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

Ceph 对象存储

空的,因为就像百度云盘一样,刚申请,没有创建,所以是空的

⑧、创建存储数据的 bucket (类似于存储数据的目录)要求 xxx_yyy 格式

[root@ceph-f ~]# s3cmd mb s3://cephdir

Ceph 对象存储

发现报错了,看上图,发现,出错是因为我们的写的格式不正确,按照正确的格式重新书写,再来一次

[root@ceph-f ~]# s3cmd mb s3://ceph_dir

Ceph 对象存储

如上图,成功了

⑨、再次查看客户端内容

[root@ceph-f ~]# s3cmd ls

Ceph 对象存储

这里提供 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、主机名和端口

2、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

Ceph 对象存储

swift -A http://192.168.20.148/auth/v1.0 -U radosgw:swift -K NhTk42HlMcAnv2GBXqatqMPeI20eSLod30AOJLwl stat -v

Ceph 对象存储

这里提供 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 集群的实现,请参阅小弟的另外一篇博文:https://blog.51cto.com/4746316/2329558
关于 Ceph 块设备的应用,请参阅小弟的另外一篇博文:https://blog.51cto.com/4746316/2330070
关于 CephFS 文件系统的应用,请参阅小弟的另外一篇博文:https://blog.51cto.com/4746316/2330186


五、总结

Ceph 对象存储目前尚不不稳定,且官方文档较旧,这里只做大概讲解,不做深入研究。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI