Akemi

RGW部署与awscli连接

2025/07/10

对象存储相关概念啥的略过

Ceph支持S3接口和OpenStack Swift接口

RGW介绍

RADOSGW(RGW)是一种使用标准对象存储API为客户端提供对ceph集群访问的服务

客户端使用标准api与RGW通信,RGW调用librados模块与ceph集群通信

RADOSGW提供了一种专用的radosgw-admin应用程序,用于控制权限,使用户只能访问网关,无法直接使用cephx对集群进行访问

默认池

RGW会在每个区域的基础上自动创建默认池,这些池使用PG,并使用默认CRUSH层级结构
默认会有比如.rgw.root .default.rgw.control这种池

可以自定义,红帽建议使用zone名字作为前缀创建pool,比如.eu-central.rgw.control、.eu-central.rgw.buckets.data

RGW层级

在 Ceph RGW 中,Realm、Zonegroup 和 Zone 是用于多站点部署和逻辑隔离的核心概念,它们不仅仅是简单的层级结构,而是构成了 RGW 的多租户架构基础

概念 层级 功能描述 类比说明
Realm 最高 顶级逻辑容器,代表一个独立的管理域 相当于一个国家
Zonegroup 中层 地理或逻辑区域组,包含一组 Zone,定义复制策略 相当于省/州
Zone 基础 具体部署单元,包含实际的 RGW 实例和存储池
一般一个集群都是一个zone 相当于城市

RGW部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
使用服务特定文件部署
service_type: rgw
service_id: realm.zone
placement:
count: 4
hosts:
- cephadm-1
- cephadm-2
- cephadm-3
spec:
rgw_frontend_port: 8080

ceph orch apply -i /etc/ceph/initial-config-primary-cluster.yaml

使用命令行创建
ceph orch apply rgw <service-name> --realm=<realm> --zone=zone-name \
--port 8080 --placement="2 node1 node2" --ssl

如果创建了多实例,第一个会使用rgw_frontend_port,第二个会+1
比如一台上两个RGW实例分别是8080和8081

部署验证
ceph orch ls
NAME PORTS RUNNING REFRESHED AGE PLACEMENT
alertmanager ?:9093,9094 1/1 31s ago 12d count:1
crash 4/4 32s ago 12d *
grafana ?:3000 1/1 31s ago 12d count:1
iscsi.iscsi ?:5000 3/3 32s ago 2m cephadm-1;cephadm-2;cephadm-3
mgr 4/4 32s ago 2m ansible;cephadm-1;cephadm-2;cephadm-3
mon 3/3 32s ago 2m cephadm-1;cephadm-2;cephadm-3
node-exporter ?:9100 4/4 32s ago 12d *
osd.default_drive_group 9 32s ago 2m count:3;label:ssd-node;cephadm-*
prometheus ?:9095 1/1 31s ago 12d count:1
rgw.realm.zone ?:8080 4/4 32s ago 39s cephadm-1;cephadm-2;cephadm-3;count:4

[root@cephadm-1 ~]# curl localhost:8080
<?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></ListAllMy

多site(站点)RGW配置(未完成

多ceph集中之间自动复制对象数据,即不同集群之间的双活

比较少见,等用到了再研究吧

S3 API连接Ceph RGW

在使用Amazon S3 API时,需要考虑对象和元数据大小的限制:
1.对象大小介于最小0B和最大5TB之间。
2.在单个上传操作中,最大大小为5GB。
3.使用多部分上传功能上传大于100MB的对象。
4.在单个HTTP请求中,元数据的最大大小为16,000字节

为S3 API创建一个用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
radosgw-admin user create --uid=test --display-name='test user' \
--access-key=12345 --secret=67890

--uid 必选,
--display-name 必选
--access-key,--secret可选,如果不写,则会提示

就像这样
radosgw-admin user create --uid=wangsheng --display-name='wangsheng user'
{
"user_id": "wangsheng",
"display_name": "wangsheng user",
"email": "",
"suspended": 0,
"max_buckets": 1000,
"subusers": [],
"keys": [
{
"user": "wangsheng",
"access_key": "5DMSE495PNGYFJLROAEL",
"secret_key": "P9F9IquHCtKQkM1rWC1ZeE7BmPaE0cpyXOVZkcRp"
}
],
...

管理RGW用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
重新生成现有用户密钥
radosgw-admin key create --uid=wangsheng --access-key="123123" \
--gen-secret
{
"user_id": "wangsheng",
"display_name": "wangsheng user",
"email": "",
"suspended": 0,
"max_buckets": 1000,
"subusers": [],
"keys": [
{
"user": "wangsheng",
"access_key": "123123",
"secret_key": "tGhC7XOoCyArl2B3FHpLL8YIoP71g3KC4qaue0D4"
},
{
"user": "wangsheng",
"access_key": "5DMSE495PNGYFJLROAEL",
"secret_key": "P9F9IquHCtKQkM1rWC1ZeE7BmPaE0cpyXOVZkcRp"

删除用户密钥
radosgw-admin key rm --access-key=5DMSE495PNGYFJLROAEL

修改用户的权限
radosgw-admin user modify --uid=wangsheng --access=full

删除一个用户,同时删除他们的对象存储
radosgw-admin user rm --uid=wangsheng --purge-data

查看用户信息
radosgw-admin user info --uid=test
radosgw-admin user stats --uid=test

设置用户配额

1
2
3
4
5
6
7
8
9
10
11
12
13
14
先设置配额参数,再启用配额。如果要禁用配额,可以将配额参数设置为负值。

用户app1最高1024个对象
radosgw-admin quota set --quota-scope=user --uid=app1 --max-objects=1024
启用配额
radosgw-admin quota enable --quota-scope=user --uid=app1

桶loghistory的最大大小1024B
radosgw-admin quota set --quota-scope=bucket --uid=loghistory --max-objects=1024B
radosgw-admin quota enable --quota-scope=bucket --uid=loghistory

全局配额,所有桶都会收到影响
radosgw-admin global quota set --quota-scope=bucket --max-objects 2048
radosgw-admin global quota enable --quota-scope=bucket

安装与使用awscli

说实话感觉不如mc,花里胡哨的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
yum install unzip -y
unzip awscliv2.zip
./aws/install
aws --version
aws-cli/2.27.49 Python/3.13.4 Linux/4.18.0-553.51.1.el8_10.x86_64 exe/x86_64.rocky.8

交互式配置awscli
aws configure --profile=ceph
AWS Access Key ID [None]: 12345
AWS Secret Access Key [None]: 67890
Default region name [None]:
Default output format [None]:

创建一个桶
aws --profile=ceph --endpoint=http://cephadm-1:8080 s3api create-bucket \
--bucket testbucket \
--create-bucket-configuration LocationConstraint=

列出桶
aws --profile=ceph --endpoint-url=http://cephadm-1:8080 s3 ls
2025-07-09 04:48:47 testbucket

****上传文件
dd if=/dev/zero of=./testfile-1G bs=1M count=1024
aws --profile=ceph --endpoint=http://cephadm-1:8080 s3 cp testfile-1G s3://testbucket
upload: ./testfile-10M to s3://testbucket/testfile-10M

验证
aws --profile=ceph --endpoint=http://cephadm-1:8080 s3 ls s3://testbucket
2025-07-09 05:04:06 10485760 testfile-10M
CATALOG
  1. 1. RGW介绍
  2. 2. RGW部署
  3. 3. 多site(站点)RGW配置(未完成
  4. 4. S3 API连接Ceph RGW