参考文档:html
Ceph Object Gateway是对象存储接口,构建在librados之上,为应用提供restful类型的网关。其支持两种接口:python
以《CEPH LIO iSCSI Gateway》中的环境为基础,即:linux
Hostnameweb |
IPswift |
Servicevim |
Remarkcentos |
ceph01服务器 |
public:172.30.200.57 restful cluster:192.30.200.57网络 |
1. centos7.5 with kernel v4.18.7-1; 2. ceph-13.2.1 mimic (stable),已部署 3. ntp已部署; 4. 禁用selinux; 5. 禁用firewalld或iptables,rgw内嵌civetweb默认采用7480端口。 |
|
ceph02 |
public:172.30.200.58 cluster:192.30.200.58 |
||
ceph03 |
public:172.30.200.59 cluster:192.30.200.59 |
||
ceph-client |
172.30.200.50 |
# 经过部署服务器部署,格式:ceph-deploy install --rgw Gateway-NODE1 [Gateway-NODE2 …]; # 如因网络缘由致使安装不成功,可在各节点独立安装:ceph-radosgw ceph-common
[root@ceph01 ~]# su - cephde
[cephde@ceph01 ~]$ cd cephcluster/ [cephde@ceph01 cephcluster]$ ceph-deploy install --rgw ceph01 ceph02 ceph03
Ceph 对象存储使用 Ceph 对象网关守护进程( radosgw ,RGW),内嵌了Civetweb服务器与FastCGI 模块。
其中Civetweb服务器默认使用tcp 7480端口。
# 变动Civetweb服务器默认端口,可修改ceph.conf文件,增长[client.rgw.<GATEWAY-NODE>]字段,其中“GATEWAY-NODE”为所在网关节点的短主机名,即:hostname -s; # 可在部署服务器修改后分发到各网关节点,也可在各网关节点独立修改; # [client.rgw.<GATEWAY-NODE>]字段与[global]字段在相同层级,且1个网关节点使用1个字段,其中”client”表示客户端配置,“rgw”表示客户端类型,“GATEWAY-NODE”标识实例名;
[cephde@ceph01 cephcluster]$ cat ceph.conf [client.rgw.ceph01] rgw_frontends = "civetweb port=80" [client.rgw.ceph02] rgw_frontends = "civetweb port=80" [client.rgw.ceph03] rgw_frontends = "civetweb port=80"
# 从部署服务器分发ceph.conf
[cephde@ceph01 cephcluster]$ ceph-deploy --overwrite-conf config push ceph01 ceph02 ceph03
# 在部署服务器建立实例; # 建立后,在各网关节点对应的守护进程启动; # 若是ceph.conf配置文件变动,可在对应节点重启服务
[cephde@ceph01 cephcluster]$ ceph-deploy rgw create ceph01 ceph02 ceph03
# 查看服务
[root@ceph01 ~]# systemctl status ceph-radosgw@rgw.ceph01
# 查看端口
[root@ceph01 ~]# netstat -tunlp | grep radosgw
# 建立实例后,同时建立部分默认pool; # 或:”rados df” 与 “ceph osd pool ls”
[root@ceph01 ~]# ceph osd lspools
# 格式:http://RGW-IP:port [root@ceph01 ~]# curl http://172.30.200.57 # 若是网关实例正常运行,响应以下: <?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>anonymous</ID>
<DisplayName></DisplayName>
</Owner>
<Buckets>
</Buckets>
</ListAllMyBucketsResult>
使用REST接口验证,步骤以下:
# “--uid”与“--display-name”自定义; # 返回结果中,keys->access_key 与 keys->secret_key 是访问验证时须要的值
[root@ceph01 ~]# radosgw-admin user create --uid="objectuser" --display-name="Object Stoage User"
Swift用户建立分两步:
# 建立子用户,基于已建立的s3用户; # 赋予全权限
[root@ceph01 ~]# radosgw-admin subuser create --uid=objectuser --subuser=objectuser:swift --access=full
# 生成秘钥; # 返回结果中,swift_keys ->secret_key 是访问验证时须要的值
[root@ceph01 ~]# radosgw-admin key create --subuser=objectuser:swift --key-type=swift --gen-secret
测试采用python脚本完成,脚本流程以下:测试脚本链接radosgw,建立bucket,list bucket。
# 客户端须要安装python-boto
[root@ceph-client ~]# yum install -y python-boto
# 编辑测试脚本; # 注意”access_key”,”secret_key”,”host”与”port”值修改
[root@ceph-client ~]# vim s3.py
import boto.s3.connection access_key = 'YT6ZE7N82VOY82CP5F1D' secret_key = 'tvRcE4sLh7YOrBBgcLUAWL4Czdqrak2UBg5DsOcy' conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host='172.30.200.57', port=80, 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, ) # 运行脚本,返回结果符合预期
[root@ceph-client ~]# python s3.py
测试采用swift客户端进行。
# 安装swift客户端
[root@ceph-client ~]# yum install python-setuptools
[root@ceph-client ~]# easy_install pip
[root@ceph-client ~]# pip install --upgrade setuptools
[root@ceph-client ~]# pip install --upgrade python-swiftclient
# 命令格式:swift -A http://{IP ADDRESS}:{port}/auth/1.0 -U USER:swift -K '{swift_secret_key}' list; # 这里基于s3测试生成的bucket,list bucker,返回结果符合预期
[root@ceph-client ~]# swift -A http://172.30.200.57/auth/1.0 -U objectuser:swift -K '9mm3yJT6CQ62A1II0AqENu3LDKmBxcEwy1kXBspn' list