No.1 概述

上一篇”Ceph Dashboard全功能集成安装“博文中详细介绍了Ceph 的安装过程,鉴于篇幅的关系没有介绍如何使用Ceph,本文开始Ceph使用系列之一Ceph RGW使用介绍。

No.2 Ceph RGW介绍

Ceph对象网关是在librados之上构建的对象存储接口,旨在为应用程序提供通往Ceph存储集群的RESTful网关,Ceph对象存储使用Ceph对象网关守护进程(radosgw),它是用于与Ceph存储群集进行交互的HTTP服务器。其有多种体现方式,如:apache2、Nginx等,Ceph从Hammer版本后使用civetweb替换原apache2并作为默认的http服务器。

由它提供openstack Swift和Amazon S3兼容的接口,介绍如下:

S3和Swift API共享同一个命名空间,所以可以使用两种API访问相同的数据。

温馨提醒

CivetWeb基于Mongoose项目,是一个易于使用,功能强大的C / C 嵌入式Web服务器,其已经被直接嵌入了radosgw服务中。

ceph应用(使用系列之一RGW使用)(1)

其实除了上面提到两种访问接口外,Ceph还有一个管理接口admin API ,其通过rest api的方式对对象存储进行管理,命令行形式为radosgw-admin,可以用来执行创建用户、删除用户、列出用户等操作,示意图如下:

ceph应用(使用系列之一RGW使用)(2)

No.3 使用radosgw-admin管理RGW

Ceph RGW对象存储中有以下四个概念:

ceph应用(使用系列之一RGW使用)(3)

用户账户有两种类型:

用户:是作为s3接口用户;

子用户:是作为swift接口用户,子用户附属于用户。

ceph应用(使用系列之一RGW使用)(4)

radosgw-admin创建用户。

#radosgw-admin user create --uid="testuser" --display-name="First User" { "user_id": "testuser", "display_name": "First User", "email": "", "suspended": 0, "max_buckets": 1000, "subusers": [], "keys": [ { "user": "testuser", "access_key": "H1YNZV2D6E1X5PGAOSZ7", "secret_key": "MasCiG6OJvEpXRTye4Ptz13SAI2dv5s3zUDXLO26" } ], "swift_keys": [], "caps": [], "op_mask": "read, write, delete", "default_placement": "", "default_storage_class": "", "placement_tags": [], "bucket_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "user_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "temp_url_keys": [], "type": "rgw", "mfa_ids": [] }

创建子用户。

#radosgw-admin subuser create --uid=testuser --subuser=testuser:swift --access=full { "user_id": "testuser", "display_name": "First User", "email": "", "suspended": 0, "max_buckets": 1000, "subusers": [ { "id": "testuser:swift", "permissions": "full-control" } ], "keys": [ { "user": "testuser", "access_key": "H1YNZV2D6E1X5PGAOSZ7", "secret_key": "MasCiG6OJvEpXRTye4Ptz13SAI2dv5s3zUDXLO26" } ], "swift_keys": [ { "user": "testuser:swift", "secret_key": "yahhi4lK5eJIw0cMg0cSm1ylRcncbAEGzQoximrw" } ], "caps": [], "op_mask": "read, write, delete", "default_placement": "", "default_storage_class": "", "placement_tags": [], "bucket_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "user_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "temp_url_keys": [], "type": "rgw", "mfa_ids": [] }

查看用户。

# radosgw-admin user list [ "user-rgw", "rgw", "admin", "test", "testuser" ]

查看用户详细信息。

# radosgw-admin user info --uid test { "user_id": "test", "display_name": "test", "email": "", "suspended": 0, "max_buckets": 1000, "subusers": [], "keys": [ ...................................................

更多可使用-h查看。

#radosgw-admin -h usage: radosgw-admin <cmd> [options...] commands: user create create a new user user modify modify user user info get user info user rm remove user user suspend suspend a user user enable re-enable user after suspension user check check user info user stats show user stats as accounted by quota subsystem user list list users caps add add user capabilities caps rm remove user capabilities subuser create create a new subuser subuser modify modify subuser subuser rm remove subuser key create create access key key rm remove access key bucket list list buckets (specify --allow-unordered for ..............................................

No.4使用Ceph Dashboard操作RGW

Ceph Dashboard现在支持如下三个功能:

Ceph Dashboard现在还不支持上传下载对象,只能通过s3或swift接口实现,详细可参见下文。

以下为查看RGW主机界面。

ceph应用(使用系列之一RGW使用)(5)

新建用户。

ceph应用(使用系列之一RGW使用)(6)

创建子用户。

ceph应用(使用系列之一RGW使用)(7)

ceph应用(使用系列之一RGW使用)(8)

ceph应用(使用系列之一RGW使用)(9)

可以看到子用户附属于用户。

ceph应用(使用系列之一RGW使用)(10)

创建桶界面。

ceph应用(使用系列之一RGW使用)(11)

No.5 使用s3接口操作RGW

5.1 安装s3cmd

要想使用s3接口访问rgw,需要先安装aws s3cmd命令行客户端工具,s3cmd 是一款 Amazon S3 命令行工具。它不仅能上传、下载、同步,还能设置权限。

下载并s3cmd工具。

因为s3cmd是使用python写的,所以要先安装pip工具。

# yum -y install python-pip

安装s3cmd,因为pip默认使用国外源,容易下载失败,所以加了临时使用国内源的命令,使用-i指定国内源地址。

#pip install s3cmd -i https://pypi.tuna.tsinghua.edu.cn/simple

查看s3cmd版本。

#s3cmd --version s3cmd version 2.1.0

配置s3cmd配置文件, 该命令会在/root目录下,创建.s3cfg文件。文件内容包括向导式中填写的内容。也可以一直下一步生成空的配置文件,直接编辑配置文件,也可以按向导提示填入内容。

#s3cmd --configure Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables. Access Key: YC57G2R9XJIMNG825UQP Secret Key: PEDoHiveAUhEciOeeKFYLkaArlhtSy5mBMfWhWes Default Region [US]: Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3. S3 Endpoint [s3.amazonaws.com]: 192.168.123.172:7480 Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used if the target S3 system supports dns based buckets. DNS-style bucket hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: 192.168.123.172:7480/%(bucket) Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: Path to GPG program [/usr/bin/gpg]: When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP, and can only be proxied with Python 2.7 or newer Use HTTPS protocol [Yes]: no On some networks all internet access must go through a HTTP proxy. Try setting it here if you can't connect to S3 directly HTTP Proxy server name: New settings: Access Key: YC57G2R9XJIMNG825UQP Secret Key: PEDoHiveAUhEciOeeKFYLkaArlhtSy5mBMfWhWes Default Region: US S3 Endpoint: 192.168.123.172:7480 DNS-style bucket hostname:port template for accessing a bucket: 192.168.123.172:7480/%(bucket) Encryption password: Path to GPG program: /usr/bin/gpg Use HTTPS protocol: False HTTP Proxy server name: HTTP Proxy server port: 0 Test access with supplied credentials? [Y/n] Please wait, attempting to list all buckets... Success. Your access key and secret key worked fine :-) Now verifying that encryption works... Not configured. Never mind. Save settings? [y/N] y Configuration saved to '/root/.s3cfg'

生产了s3cf配置文件,如果哪些设置有错误,也可以直接编辑该配置文件。

#vi /root/.s3cfg [default] access_key = YC57G2R9XJIMNG825UQP access_token = PEDoHiveAUhEciOeeKFYLkaArlhtSy5mBMfWhWes cloudfront_host = 192.168.123.172:7480 host_base = 192.168.123.172:7480 host_bucket = 192.168.123.172:7480/%(bucket)

5.2 测试s3接口访问

测试 S3 访问。

#yum install python-boto

新建 Python 脚本。

#vi s3test.py

添加下面的内容到该文件中。

#!/usr/bin/python # -*- coding:utf-8 -*- import boto.s3.connection access_key = 'YC57G2R9XJIMNG825UQP' secret_key ='PEDoHiveAUhEciOeeKFYLkaArlhtSy5mBMfWhWes' conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host='ceph-node1',port=7480, 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, )

将 host替换为你配置了网关服务的主机的主机名,比如 gateway host.将access_key替换为正确的值,将secret_key替换为正确的值。

运行这个脚本:

#python s3test.py

输出类似下面的内容,说明使用s3接口连接rgw对象成功。

# python s3test.py ceph-rgw 2020-05-03T08:29:44.240Z my-new-bucket 2020-03-14T10:21:03.179Z new-bucket-510d1576 2020-03-16T13:20:59.151Z new-bucket-6c11b821 2020-03-14T10:37:11.406Z nextcloud 2020-05-03T04:32:28.547Z rgw-test 2020-05-02T13:17:02.184Z test 2020-03-12T14:55:47.827Z test3 2020-03-14T10:45:54.065Z test4 2020-03-14T10:46:03.714Z test5 2020-03-14T10:46:37.318Z test6 2020-03-14T10:47:46.755Z test7 2020-03-14T10:51:50.559Z test8 2020-03-14T10:53:02.755Z test9 2020-05-02T14:15:04.193Z

5.3 使用s3cmd操作rgw

使用s3cmd创建桶。

# s3cmd mb s3://ceph-rgw Bucket 's3://ceph-rgw/' created

上传文件到rgw对象存储。

#s3cmd put prometheus-2.16.0.linux-amd64.tar.gz s3://ceph-rgw WARNING: Could not refresh role WARNING: Could not refresh role WARNING: Could not refresh role upload: 'prometheus-2.16.0.linux-amd64.tar.gz' -> 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz' [part 1 of 4, 15MB] [1 of 1] 15728640 of 15728640 100% in 0s 29.05 MB/s done WARNING: Could not refresh role upload: 'prometheus-2.16.0.linux-amd64.tar.gz' -> 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz' [part 2 of 4, 15MB] [1 of 1] 15728640 of 15728640 100% in 0s 36.41 MB/s done WARNING: Could not refresh role upload: 'prometheus-2.16.0.linux-amd64.tar.gz' -> 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz' [part 3 of 4, 15MB] [1 of 1] 15728640 of 15728640 100% in 0s 36.27 MB/s done WARNING: Could not refresh role upload: 'prometheus-2.16.0.linux-amd64.tar.gz' -> 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz' [part 4 of 4, 11MB] [1 of 1] 12422595 of 12422595 100% in 0s 31.92 MB/s done WARNING: Could not refresh role

查看桶中的对象。

#s3cmd ls s3://ceph-rgw WARNING: Could not refresh role WARNING: Could not refresh role 2020-05-03 08:48 59608515 s3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz 下载对象 #s3cmd get s3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz prometheus-2.16.0.linux-amd64.tar.gz.bak download: 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz' -> 'prometheus-2.16.0.linux-amd64.tar.gz.bak' [1 of 1] 59608515 of 59608515 100% in 0s 142.89 MB/s done

删除桶中的对象,可以使用rm或del命令。

#s3cmd rm s3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz WARNING: Could not refresh role WARNING: Could not refresh role delete: 's3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz'

查看对象占用空间大小

#s3cmd du -H s3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz 56.8471097946M 1 objects s3://ceph-rgw/prometheus-2.16.0.linux-amd64.tar.gz

更多命令请参考s3cmd帮助。

No.6 使用S3 Browser访问RGW

打开s3 browser,点击"add new account"。

ceph应用(使用系列之一RGW使用)(12)

输入以下内容,注意签名版本为V4。

ceph应用(使用系列之一RGW使用)(13)

查看rgw对象存储中所有的桶。

ceph应用(使用系列之一RGW使用)(14)

No.7 使用swift接口操作RGW

安装swift命令行工具,配置swift安装源,因为swift是openstack一个组件,所以此处配置为openstack源,当然也有直接安装swift的命令,不用配置openstack源,不过本人没有使用那个方法安装成功,本文还是使用配置OpenStack源的方法。

#viopenstack.repo [openstack] name=openstack baseurl=https://mirrors.cloud.tencent.com/centos/7.7.1908/cloud/x86_64/openstack-train/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

安装swift命令工具。

#yum install python2-swiftclient

查看swiftclient版本。

#swift --version python-swiftclient 3.8.1

查看子用户名称和密钥。

#radosgw-admin user info --uid testuser [ "user-rgw", "rgw", "admin", "test10", "test", "testuser" ]

#radosgw-admin user info --uid testuser ................................................................................ "swift_keys": [ { "user": "testuser:swift", "secret_key": "yahhi4lK5eJIw0cMg0cSm1ylRcncbAEGzQoximrw" } ], ..................................................................................

使用swift命令查看rgw对象存储状态。

#swift -A http://192.168.123.172:7480/auth/v1.0 -U testuser:swift -K "yahhi4lK5eJIw0cMg0cSm1ylRcncbAEGzQoximrw" stat Account: v1 Containers: 0 Objects: 0 Bytes: 0 Objects in policy "default-placement-bytes": 0 Bytes in policy "default-placement-bytes": 0 Containers in policy "default-placement": 0 Objects in policy "default-placement": 0 Bytes in policy "default-placement": 0 Accept-Ranges: bytes Connection: Keep-Alive X-Timestamp: 1588493556.96500 X-Account-Bytes-Used-Actual: 0 X-Trans-Id: tx0000000000000000003c8-005eae7cf4-f2b7f-default Content-Type: text/plain; charset=utf-8 X-Openstack-Request-Id: tx0000000000000000003c8-005eae7cf4-f2b7f-default

但上面每次需要输入很长的命令,所以可以通过设置环境变量减少每次输入的命令,当然想要永久生效需要把以下内容存储在用户的环境变量文件中,如.bashrc文件中。

把下面的USER和KEY替换成实际的值。

#export ST_AUTH=http://production01.acme.com/auth/v1.0 export ST_USER=user01 export ST_KEY=password

现在就可以通过简短命令操作对象存储了。

创建桶

#swift post bucket

上传文件到桶中

创建桶并上传文件到rgw桶中

#swift upload bucket ceph-iscsi-config-2.7-1.el7.noarch.rpm #swift list bucket ceph-iscsi-config-2.7-1.el7.noarch.rpm

温馨提醒

upload命令上传文件到指定的桶中,如果存在桶名称则直接上传到指定的桶中,如果没有存在桶名称,则新建桶并上传对象到此桶中

查看指定桶中的对象,不加桶名称即查看所有。

#swift list bucket

从指定桶下载对象

#swift download bucket ceph-iscsi-config-2.7-1.el7.noarch.rpm ceph-iscsi-config-2.7-1.el7.noarch.rpm [auth 0.004s, headers 0.008s, total 0.009s, 17.761 MB/s]

查看指定桶中的对象。

#swift stat bucket ceph-iscsi-config-2.7-1.el7.noarch.rpm Account: v1 Container: bucket Object: ceph-iscsi-config-2.7-1.el7.noarch.rpm Content Type: application/x-rpm Content Length: 94632 Last Modified: Tue, 05 May 2020 14:42:34 GMT ETag: 86f3c320ed3b5c2ea8389710c31b7997 Meta Mtime: 1583988649.031517 Accept-Ranges: bytes Connection: Keep-Alive X-Timestamp: 1588689754.31758 X-Trans-Id: tx0000000000000000000ce-005eb1801f-fc7b1-default X-Openstack-Request-Id: tx0000000000000000000ce-005eb1801f-fc7b1-default

删除对象。

#swift delete bucket ceph-iscsi-config-2.7-1.el7.noarch.rpm ceph-iscsi-config-2.7-1.el7.noarch.rpm

更多命令请参考swift帮助。

No.8 使用CloudBerry 访问RGW

打开cloudberry explorer。

ceph应用(使用系列之一RGW使用)(15)

设置账号。

ceph应用(使用系列之一RGW使用)(16)

点击增加存储。

ceph应用(使用系列之一RGW使用)(17)

按以下内容输入详细,使用第三节创建的testuser:swift子用户以及密钥。

ceph应用(使用系列之一RGW使用)(18)

温馨提醒

注意地址栏中的auth关键字,这个必须要有否者连接不上

注意keystone version中使用的是“do not user”

No.9 Nextcloud网盘应用访问Ceph RGW

9.1 nextcloud介绍

上面演示了使用很多图形或命令行工具操作使用RGW对象存储,其实RGW使用最多的还是通过应用程序使用它,本节使用一个网盘应用软件Nextcloud,配置其后端存储使用RGW对象存储,为用户提供网盘应用,用户上传的文件实现是存储在了RGW对象存储中,示意图如下:

ceph应用(使用系列之一RGW使用)(19)

9.2 安装nextcloud

为了简化安装步骤,本文使用snap工具安装nextcloud.

配置epel源。

#yum install epel-release

安装snapd工具。

#yum install snapd

配置snapd socket。

#systemctl enable --now snapd.socket

配置软链接。

#ln -s /var/lib/snapd/snap /snap

通过snap安装nextcloud。

#snap install nextcloud

查看源已通过snap安装的nextcloud应用。

#snap list Name Version Rev Tracking Publisher Notes core 16-2.44.3 9066 stable canonical✓ core nextcloud 18.0.4snap1 20498 stable nextcloud✓ -

snap安装的nextcloud默认使用80端口,输入IP地址打开nextcloud配置界面。

设置用户名和密码,点击完成。

ceph应用(使用系列之一RGW使用)(20)

9.1 配置nextcloud

安装完成打开nextcloud使用界面。

ceph应用(使用系列之一RGW使用)(21)

配置nextcloud使用rgw存储,点击应用按钮。

ceph应用(使用系列之一RGW使用)(22)

在已禁用应用中选择“external storage support",点击启用。

ceph应用(使用系列之一RGW使用)(23)

完成后点击设置查看左侧功能菜单出现”外部存储“。

ceph应用(使用系列之一RGW使用)(24)

创建nextcloud桶。

# s3cmd mb s3://nextcloud Bucket 's3://nextcloud/' created

查看桶。

# s3cmd ls |grep nextcloud 2020-05-03 04:32 s3://nextcloud

配置nextcloud使用s3访问rgw对象存储,填写目录名称,并勾选启用路径,当左边出现绿色的图标表示连接成功。

ceph应用(使用系列之一RGW使用)(25)

温馨提醒

启用路径样式后,将使用发出请求http://hostname.domain/bucket。只有这格式的才能对接成功(默认为http://bucket.hostname.domain)。

回到nextcloud界面,看到出现rgw目标,只有上传到该目录的文件才会使用s3接口存储到rgw存储中。

ceph应用(使用系列之一RGW使用)(26)

上传文件到rgw目录后,查看对应桶中的对象。

ceph应用(使用系列之一RGW使用)(27)

至此nextcloud使用s3对接使用rgw完成,当然nextcloud也支持使用swift接口对接nextcloud,但只能是在OpenStack中安装的swift,不能是单独的swift,因为nextcloud配置swift接口的界面中必须写keystone版本。

当然RGW的使用还不止上文中提到的这些,RGW还有

Multisite场景,其涉及的内容比较多,有机会再单独写一篇文章。

ceph应用(使用系列之一RGW使用)(28)

,