1. 首页 > Linux教程 > 正文

Linux教程FG348-Ceph RGW对象存储

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档介

风哥提示:

绍Ceph RGW对象存储的配置和使用方法。

Part01-RGW服务部署

1.1 安装RGW服务

# 创建RGW存储池
[root@ceph-mon1 ~]# ceph osd pool create .rgw.root 32 32
pool ‘.rgw.root’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.control 32 32
pool ‘default.rgw.control’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.meta 32 32
pool ‘default.rgw.meta’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.log 32 32
pool ‘default.rgw.log’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.buckets.index 32 32
pool ‘default.rgw.buckets.index’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.buckets.data 128 128
pool ‘default.rgw.buckets.data’ created
[root@ceph-mon1 ~]# ceph osd pool create default.rgw.buckets.non-ec 32 32
pool ‘default.rgw.buckets.non-ec’ created

# 部署RGW
[root@ceph-admin ceph-cluster]# ceph-deploy rgw create ceph-mon1
[ceph_deploy.rgw][DEBUG ] Deploying rgw, cluster ceph, host ceph-mon1
[ceph-mon1][DEBUG ] write conf to /etc/ceph/ceph.conf
[ceph-mon1][DEBUG ] create rgw path /var/lib/ceph/radosgw/ceph-ceph-mon1
[ceph-mon1][DEBUG ] write keyring to /var/lib/ceph/radosgw/ceph-ceph-mon1/keyring

# 查看RGW状态
[root@ceph-mon1 ~]# ceph -s
cluster:
id: 12345678-90ab-cdef-1234-567890abcdef
health: HEALTH_OK

services:
mon: 3 daemons, quorum ceph-mon1,ceph-mon2,ceph-mon3 (age 30m)
mgr: ceph-mon1(active, since 29m), standbys: ceph-mon2
osd: 4 osds: 4 up, 4 in
rgw: 1 daemon active (ceph-mon1)

data:
pools: 9 pools, 504 pgs
objects: 200 objects, 1.0 MiB
usage: 4.1 GiB used, 3.9 TiB / 4.0 TiB avail
pgs: 504 active+clean

# 查看RGW服务
[root@ceph-mon1 ~]# systemctl status ceph-radosgw@rgw.ceph-mon1
● ceph-radosgw@rgw.ceph-mon1.service – Ceph rados gateway
Loaded: loaded (/usr/lib/systemd/system/ceph-radosgw@.service; enabled; preset: disabled)
Active: active (running) since Fri 2026-04-04 19:50:00 CST; 5min ago
Main PID: 12345 (radosgw)
Tasks: 100 (limit: 11232)
Memory: 200.0M
CGroup: /system.slice/system-ceph\x2dradosgw.from PG视频:www.itpux.comslice/ceph-radosgw@rgw.ceph-mon1.service
└─12345 /usr/bin/radosgw -f –cluster ceph –name client.rgw.ceph-mon1 –setuser ceph –setgroup ceph

# 测试RGW服务
[root@ceph-mon1 ~]# curl http://localhost:7480
anonymous

1.2 配置RGW服务

# 配置RGW端口
[root@ceph-mon1 ~]# ceph config set client.rgw rgw_frontends “beast port=7480”

# 配置DNS样式
[root@ceph-mon1 ~]# ceph config set client.rgw rgw_dns_name “rgw.fgedu.net.更多学习教程公众号风哥教程itpux_comcn”

# 配置S3 API
[root@ceph-mon1 ~]# ceph config set client.rgw rgw_s3_auth_use_rados true

# 重启RGW服务
[root@ceph-mon1 ~]# systemctl restart ceph-radosgw@rgw.ceph-mon1

# 创建S3用户
[root@ceph-mon1 ~]# radosgw-admin user create –uid=”testuser” –display-name=”Test User”
{
“user_id”: “testuser”,
“display_name”: “Test User”,
“email”: “”,
“suspended”: 0,
“max_buckets”: 1000,
“subusers”: [],
“keys”: [
{
“user”: “testuser”,
“access_key”: “ABCDEFGHIJKLMNOPQRST”,
“secret_key”: “1234567890abcdefghijklmnopqrstuvwxyz”
}
],
“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”: []
}

# 查看用户列表
[root@ceph-mon1 ~]# radosgw-admin user list
[
“testuser”
]

# 查看用户信息
[root@ceph-mon1 ~]# radosgw-admin user info –uid=testuser
{
“user_id”: “testuser”,
“display_name”: “Test User”,
“email”: “”,
“suspended”: 0,
“max_buckets”: 1000,
“subusers”: [],
“keys”: [
{
“user”: “testuser”,
“access_key”: “ABCDEFGHIJKLMNOPQRST”,
“secret_key”: “1234567890abcdefghijklmnopqrstuvwxyz”
}
]
}

Part02-S3客户端配置

2.1 使用AWS CLI

# 安装AWS CLI
[root@client ~]# dnf install -y awscli
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 19:55:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
awscli noarch 2.9.0-1.el9 epel 50 M

Transaction Summary
================================================================================
Install 1 Package

Total download size: 50 M
Installed size: 200 M
Downloading Packages:
awscli-2.9.0-1.el9.noarch.rpm 20 MB/s | 50 MB 00:02
——————————————————————————–
Total 20 MB/s | 50 MB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : awscli-2.9.学习交流加群风哥微信: itpux-com0-1.el9.noarch 1/1
Running scriptlet: awscli-2.9.0-1.el9.noarch 1/1
Verifying : awscli-2.9.0-1.el9.noarch 1/1

Installed:
awscli-2.9.0-1.el9.noarch

Complete!

# 配置AWS CLI
[root@client ~]# aws configure –profile ceph
AWS Access Key ID [None]: ABCDEFGHIJKLMNOPQRST
AWS Secret Access Key [None]: 1234567890abcdefghijklmnopqrstuvwxyz
Default region name [None]: default
Default output format [None]: json

# 创建配置文件
[root@client ~]# cat > ~/.aws/config << 'EOF' [profile ceph] region = default output = json s3 = endpoint_url = http://192.168.1.11:7480 signature_version = s3v4 EOF # 创建存储桶 [root@client ~]# aws --profile ceph s3 mb s3://test-bucket make_bucket: test-bucket # 上传文件 [root@client ~]# echo "Hello Ceph" > test.txt
[root@client ~]# aws –profile ceph s3 cp test.txt s3://test-bucket/
upload: ./test.txt to s3://test-bucket/test.txt

# 列出存储桶
[root@client ~]# aws –profile ceph s3 ls
2026-04-04 20:00:00 test-bucket

# 列出存储桶内容
[root@client ~]# aws –profile ceph s3 ls s3://test-bucket/
2026-04-04 20:00:00 11 test.txt

# 下载文件
[root@client ~]# aws –profile ceph s3 cp s3://test-bucket/test.txt download.txt
download: s3://test-bucket/test.txt to ./download.txt

# 删除文件
[root@client ~]# aws –profile ceph s3 rm s3://test-bucket/test.txt
delete: s3://test-bucket/test.txt

# 删除存储桶
[root@client ~]# aws –profile ceph s3 rb s3://test-bucket
remove_bucket: test-bucket

2.2 使用s3cmd工具

# 安装s3cmd
[root@client ~]# dnf install -y s3cmd
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 20:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
s3cmd noarch 2.2.0-1.el9 epel 200 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 200 k
Installed size: 500 k
Downloading Packages:
s3cmd-2.2.0-1.el9.noarch.rpm 500 kB/s | 200 kB 00:00
——————————————————————————–
Total 500 kB/s | 200 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : s3cmd-2.2.0-1.el9.noarch 1/1
Running scriptlet: s3cmd-2.2.0-1.el9.noarch 1/1
Verifying : s3cmd-2.2.0-1.el9.noarch 1/1

Installed:
s3cmd-2.2.0-1.el9.noarch

Complete!

# 配置s3cmd
[root@client ~]# 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: ABCDEFGHIJKLMNOPQRST
Secret Key: 1234567890abcdefghijklmnopqrstuvwxyz
Default Region [US]: default

S3 Endpoint [s3.amazonaws.com]: 192.168.1.11:7480
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: %(bucket)s.192.168.1.11:7480

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 using it if you have issues connecting to S3.
HTTP Proxy server name:

New settings:
Access Key: ABCDEFGHIJKLMNOPQRST
Secret Key: 1234567890abcdefghijklmnopqrstuvwxyz
Default Region: default
S3 Endpoint: 192.168.1.11:7480
DNS-style bucket+hostname:port template for accessing a bucket: %(bucket)s.192.168.1.11:7480
Use HTTPS: False

Test access with supplied credentials? [Y/n] y
Please wait, attempting to list all buckets…
Success. Your access key and secret key worked fine 🙂

Save settings? [y/N] y
Configuration saved to ‘/root/.s3cfg’

# 创建存储桶
[root@client ~]# s3cmd mb s3://s3cmd-bucket
Bucket ‘s3://s3cmd-bucket/’ created

# 上传文件
[root@client ~]# s3cmd put test.txt s3://s3cmd-bucket/
upload: ‘test.txt’ -> ‘s3://s3cmd-bucket/test.txt’ [1 of 1]
11 of 11 100% in 0s 10.00 B/s done

# 列出存储桶
[root@client ~]# s3cmd ls
2026-04-04 20:05 s3://s3cmd-bucket

# 列出存储桶内容
[root@client ~]# s3cmd ls s3://s3cmd-bucket/
DIR s3://s3cmd-bucket/
2026-04-04 20:05 11 s3://s3cmd-bucket/test.txt

# 下载文件
[root@client ~]# s3cmd get s3://s3cmd-buck学习交流加群风哥QQ113257174et/test.txt download.txt
download: ‘s3://s3cmd-bucket/test.更多视频教程www.fgedu.net.cntxt’ -> ‘download.txt’ [1 of 1]
11 of 11 100% in 0s 0.00 B/s done

# 同步目录
[root@client ~]# mkdir data
[root@client ~]# s3cmd sync data/ s3://s3cmd-bucket/data/

风哥针对RGW配置建议:

  • 配置负载均衡提高可用性
  • 启用HTTPS加密传输
  • 配置用户配额限制
  • 定期备份用户数据
  • 监控RGW服务状态

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息