HMK's blog

保持思考|00后|等待


  • Home
  • Archive
  • Tags
  •   

© 2026 Hekang

Theme Typography by Makito

Proudly published with Hexo

ceph_install_v20.2.2

Posted at 2026-08-06 Storage 

一、Ceph基础

1.1 ceph简介

Ceph 是一个开源的分布式存储系统,同时支持对象存储、文件系统、块设备。

img

ceph把每一个待管理的数据流(文件等数据)切分为一到多个固定大小(默认4兆)的对象数据,并以其为原子单元(原子是构成元素的最小单元)完成数据读写。

ceph的底层存储服务是由多个存储主机组成的存储集群,该集群也被称为RADOS(reliable automatic distributed obeject store)存储集群,即可靠的、自动化的、分布式的对象存储系统。

librados是RADOS存储集群的API,支持C/C++/JAVA/Python/ruby/php/go等编程语言客户端。

Ceph 独特地在一个统一系统中提供对象、块和文件存储。Ceph 高度可靠、易于管理且免费。Ceph 提供了卓越的可扩展性——数千个客户端访问 PB 到 EB 级别的数据。一个 Ceph 节点利用商用硬件和智能守护程序,而一个Ceph 存储集群 容纳大量节点,这些节点彼此通信以动态复制和重新分配数据。

image-20260803171953372

1.2 ceph的组成部分

Ceph 存储集群需要以下组件:至少一个 Ceph Monitor 和至少一个 Ceph Manager,以及至少与 Ceph 集群中存储的给定对象副本数一样多的Ceph 对象存储守护进程(OSD)(例如,如果 Ceph 集群中存储了给定对象的三个副本,则该 Ceph 集群中必须至少存在三个 OSD)。

Ceph 元数据服务器对于运行 Ceph 文件系统客户端是必需的。

  • Monitors:Ceph Monitor (ceph-mon) 维护集群状态的地图(maintains maps of the cluster status),包括monitor 地图、manager 地图、OSD 地图、MDS 地图和 CRUSH 地图。这些地图是 Ceph 守护进程相互协调所需的关键集群状态。Monitors 还负责管理守护进程和客户端之间的身份验证。通常需要至少三个 monitors 以实现冗余和高可用性。
  • Managers:Ceph Manager 守护进程 (ceph-mgr) 负责跟踪运行时指标和 Ceph 集群的当前状态,包括存储利用率、当前性能指标和系统负载。Ceph Manager 守护进程还托管基于 python 的模块,用于管理和公开 Ceph 集群信息,包括基于 web 的Ceph Dashboard。通常需要至少两个 managers 以实现高可用性。
  • Ceph OSDs:对象存储守护进程 Ceph OSD, ceph-osd) 存储数据,处理数据复制、恢复、再平衡,并通过检查其他 Ceph OSD 守护进程的心跳来向 Ceph Monitors 和 Managers 提供一些监控信息。通常需要至少三个 Ceph OSD 以实现冗余和高可用性。
  • MDSes:Ceph 元数据服务器 (MDS, ceph-mds) 存储Ceph 文件系统的元数据。Ceph 元数据服务器允许 CephFS 用户运行基本命令(如 ls、find 等),而不会给 Ceph 存储集群带来负担。
  • RGWs:Ceph 对象网关(RGW, ceph-radosgw) 守护进程提供应用程序和 Ceph 存储集群之间的 RESTful 网关。S3 兼容 API 是最常用的,但也提供 Swift API。

Ceph 将数据存储为逻辑存储池中的对象。使用 CRUSH算法,Ceph 计算哪个 placement group (PG) 应该包含该对象,以及哪个 OSD 应该存储该 placement group。CRUSH 算法使 Ceph 存储集群能够动态扩展、再平衡和恢复。

ceph的管理节点:ceph的常用管理接口是一组命令行工具程序,例如rados、ceph、rbd等命令,ceph 管理员可以从某个特定的ceph-mon节点执行管理操作

1.3 ceph的逻辑架构

Pool:存储池、存储数据的逻辑环境(不能直接对应OSD)、不同业务可以使用不同的存储池隔离数据(类似于k8s的namespace),存储池的空间大小取决于底层物理存储空间的大小。

PG(placement group): 一个pool内部通常有多个PG存在,pool和PG都是抽象的逻辑概念,一个pool中有多少个PG可以通过公式粗略计算。

OSD(Object Storage Daemon,对象存储设备):每一个磁盘都是一个osd,一个主机由一个或多个osd组成。

ceph集群部署好之后,要先创建存储池并指定PG数量、才能向ceph写入数据,文件在向ceph保存之前要先进行一致性hash计算,计算后会把文件保存在某个对应的PG,此文件一定属于某个pool的一个PG,在通过PG保存在OSD上。

数据对象在写到主OSD之后在同步从OSD实例以实现数据的高可用。

池

Ceph 存储系统支持“池”的概念,池是用于存储对象的逻辑分区。

Ceph 客户端从 Ceph Monitor 检索 集群映射,并将 RADOS 对象写入池。Ceph 在池中放置数据的方式由池的 size 或副本数、CRUSH 规则以及池中的放置组数决定。

img

池至少设置以下参数

  • 对象的所有权/访问权限
  • 放置组的数量
  • 要使用的 CRUSH 规则。

将 PG 映射到 OSD

每个池中都有许多放置组 (PG)。CRUSH 动态地将 PG 映射到 OSD。当 Ceph 客户端存储对象时,CRUSH 将每个 RADOS 对象映射到一个 PG。

这种 RADOS 对象到 PG 的映射实现了 Ceph OSD Daemon 和 Ceph 客户端之间的抽象和间接层。当内部拓扑发生变化时,Ceph 存储集群必须能够增长(或收缩)并自适应地重新分配数据。

如果 Ceph 客户端“知道”哪个 Ceph OSD Daemon 正在存储哪个对象,那么 Ceph 客户端和 Ceph OSD Daemon 之间就会存在紧密耦合。但是 Ceph 避免了这种紧密耦合。相反,CRUSH 算法将每个 RADOS 对象映射到放置组,然后将每个放置组映射到一个或多个 Ceph OSD Daemon。当新的 Ceph OSD Daemon 及其底层 OSD 设备上线时,这种“间接层”允许 Ceph 动态地重新平衡。下图显示了 CRUSH 算法如何将对象映射到放置组,以及如何将放置组映射到 OSD。

img

客户端使用其集群映射副本和 CRUSH 算法来精确计算读取或写入特定对象时将使用哪个 OSD

二、部署ceph集群

2.1 部署方式

ceph-ansible: https://github.com/ceph/ceph-ansible # python

ceph-salt: https://github.com/ceph/ceph-salt # python

ceph-container: https://github.com/ceph-container # shell

cephadm: https://docs.ceph.com/en/cephadm # ceph 15版本加入

最低硬件配置

https://docs.redhat.com/zh-cn/documentation/red_hat_ceph_storage/4/html/installation_guide/minimum-hardware-considerations-for-red-hat-ceph-storage_install

Cephadm 是一个可用于安装和管理 Ceph 集群的工具。

  • cephadm 仅支持 Octopus 及更高版本。
  • cephadm 与编排 API 完全集成,并完全支持用于管理集群部署的 CLI 和仪表板功能。
  • cephadm 需要容器支持(以 Podman 或 Docker 的形式)和 Python 3。
  • cephadm 需要 systemd。

Rook 部署和管理运行在 Kubernetes 中的 Ceph 集群,同时还通过 Kubernetes API 实现存储资源的管理和配置。我们推荐使用 Rook 作为在 Kubernetes 中运行 Ceph 或将现有 Ceph 存储集群连接到 Kubernetes 的方式。

  • Rook 仅支持 Nautilus 及更高版本的 Ceph。
  • Rook 是在 Kubernetes 上运行 Ceph 或将 Kubernetes 集群连接到现有(外部)Ceph 集群的首选方法。
  • Rook 支持编排器 API。CLI 和仪表板中的管理功能得到全面支持。

cephadm 是用于管理 Ceph 集群的实用程序。

以下是 cephadm 可以执行的一些操作列表

  • cephadm 可以向集群添加 Ceph 容器。
  • cephadm 可以从集群中删除 Ceph 容器。
  • cephadm 可以更新 Ceph 容器。

cephadm 不依赖于 Ansible、Rook 或 Salt 等外部配置工具。但是,这些外部配置工具可用于自动化非 cephadm 本身执行的操作。要了解有关这些外部配置工具的更多信息,请访问它们的页面

  • https://github.com/ceph/cephadm-ansible
  • https://rook.io/docs/rook/v1.10/Getting-Started/intro/
  • https://github.com/ceph/ceph-salt

cephadm 管理 Ceph 集群的完整生命周期。这个生命周期始于引导过程,此时 cephadm 在单个节点上创建一个小型 Ceph 集群。该集群由一个监视器和一个管理器组成。cephadm 随后使用编排接口扩展集群,添加主机并配置 Ceph 守护程序和服务。此生命周期的管理可以通过 Ceph 命令行界面 (CLI) 或仪表板 (GUI) 执行。

cephadm 是在 Ceph v15.2.0 (Octopus) 版本中引入的,不支持较旧版本的 Ceph。

网络配置参考

仔细的网络基础设施和配置对于构建弹性、高性能的Ceph 存储集群至关重要。Ceph 存储集群不会代表Ceph 客户端执行请求路由或分派。相反,Ceph 客户端直接向 Ceph OSD 守护进程发出请求。Ceph OSD 代表 Ceph 客户端执行数据复制,这会给 Ceph 网络带来额外负载。

我们的快速入门配置提供了一个最小的 Ceph 配置文件,其中包括 Monitor IP 地址和守护进程主机名。除非您指定集群网络,否则 Ceph 假定使用单个“公共”网络。在许多部署中,仅使用公共网络,Ceph 也能正常工作,尤其是在使用 25GE 或更快网络链接的情况下。对于客户端流量较高的集群,通过配置第二个专用网络可以显著提高弹性和性能。

可以使用两个网络运行 Ceph 存储集群:一个“公共”(“客户端”、“前端”)网络和一个“集群”(“专用”、“复制”、“后端”)网络。然而,这种方法使网络配置、成本和管理复杂化,并且通常可能对整体性能没有显著影响。如果使用的网络技术按现代标准来看较慢(例如 1GE,或者对于密集或 SSD 节点为 10GE),您可能希望绑定两个以上的链接以获得足够的吞吐量和/或实现专用的复制网络。

我们建议为了弹性和容量,网络接口应进行绑定并连接到冗余交换机。绑定应为主动/主动(active/active),或使用 FRR 或类似技术实现第 3 层多路径策略。使用 LACP 绑定时,咨询您的组织网络团队以确定正确的传输散列策略非常重要,通常为 2+3 或 3+4。错误的选择可能导致网络链接利用不平衡,吞吐量仅为可用吞吐量的一小部分。网络可观察性工具,包括 bmon、iftop 和 netstat,对于确保绑定成员链接得到充分利用非常宝贵。

如果尽管存在复杂性,仍希望为 Ceph 集群配置专用复制网络,则每个Ceph 节点将需要有多个网络接口或 VLAN。有关更多详细信息,请参阅硬件推荐 - 网络。

img

2.2 cephadm部署ceph集群

Cephadm 通过引导单个主机来创建新的 Ceph 集群,将集群扩展到包含任何额外的主机,然后部署所需的服务。

要求

  • Python 3
  • Systemd
  • 用于运行容器的 Podman 或 Docker
  • 时间同步(例如 Chrony 或旧版 ntpd)
  • 用于配置存储设备的 LVM2

任何现代 Linux 发行版都应该足够。依赖项将通过下面的引导过程自动安装。

有关允许重启 Docker 引擎而无需重启所有正在运行的容器的可选功能,请参阅 Docker Live Restore。

有关 Ceph 版本与 Podman 兼容性的表格,请参阅 与 Podman 版本的兼容性 部分。并非所有版本的 Podman 都与 Ceph 兼容。

安装 cephadm

安装 cephadm 时有两个关键步骤:首先需要获取 cephadm 的初始副本,然后第二步是确保您拥有最新的 cephadm。获取初始 cephadm 的方法有两种

  1. 特定发行版的安装方法

    特定仓库

  2. 基于 curl 的安装方法

    CEPH_RELEASE=18.2.0 # replace this with the active release
    curl –silent –remote-name –location https://download.ceph.com/rpm-${CEPH_RELEASE}/el9/noarch/cephadm

系统环境初始化:

​ 时间同步

​ 关闭selinux和防火墙(centos)

​ 配置主机域名解析或通过DNS解析

​ 配置节点间免密

​ 安装docker

Ubuntu 22.04 默认使用 systemd-timesyncd 进行时间同步,通过 timedatectl 管理。{下面发现问题改用 chrony }

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
# 查看当前时间同步状态
timedatectl status

# 设置时区为 Asia/Shanghai
timedatectl set-timezone Asia/Shanghai

# 启用 NTP 时间同步
timedatectl set-ntp true

# 配置自定义 NTP 服务器(编辑 timesyncd.conf)
cat > /etc/systemd/timesyncd.conf << 'EOF'
[Time]
NTP=10.10.0.232
FallbackNTP=time.cloudflare.com 0.ubuntu.pool.ntp.org
RootDistanceMaxSec=5
EOF

# 重启 timesyncd 服务使配置生效
systemctl restart systemd-timesyncd
systemctl enable systemd-timesyncd

# 验证时间同步状态
timedatectl status
# 关注输出中:
# "System clock synchronized: yes" → 已同步
# "NTP service: active" → NTP 服务运行中

# 查看时间同步详细信息
timedatectl timesync-status

# 如果集群节点无法访问外网,可指定内网某节点为 NTP 源
# 在 ceph-node1(可访问外网)上保持上述配置
# 在 ceph-node2/3 上配置指向 ceph-node1:
# NTP=10.10.0.11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apt install chrony -y
root@ceph-node1:~# egrep -v "^#|^$" /etc/chrony/chrony.conf
confdir /etc/chrony/conf.d
server ntp.aliyun.com iburst
allow 10.10.0.0/24
sourcedir /run/chrony-dhcp
sourcedir /etc/chrony/sources.d
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1 3
leapsectz right/UTC

2.2.1 配置网络(所有节点)

集群规划:

2.1.2 节点规划

角色 主机名 业务网络 (Public) 存储网络 (Cluster) 说明
Monitor + Manager + OSD ceph-node1 10.10.0.230/24 192.168.75.230/24 引导节点(Bootstrap)
Monitor + Manager + OSD ceph-node2 10.10.0.231/24 192.168.75.231/24 —
Monitor + Manager + OSD ceph-node3 10.10.0.232/24 192.168.75.232/24 —

2.1.3 网络规划

网络类型 网段 网卡示例 用途
Public Network(业务网络) 10.10.0.0/24 ens33 客户端访问、Monitor 通信、可访问外网
Cluster Network(存储网络) 192.168.75.0/24 ens37 OSD 数据复制、恢复、回填流量

2.1.4 下载cephadm(仅 Bootstrap 节点)

https://download.ceph.com/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@ceph-node1:~# curl -O https://download.ceph.com/debian-20.2.1/pool/main/c/ceph/cephadm_20.2.1-1noble_amd64.deb
# 安装cephadm
root@ceph-node1:~# curl -O https://download.ceph.com/debian-20.2.1/pool/main/c/ceph/cephadm_20.2.1-1noble_amd64.deb
# pull 镜像
root@ceph-node1:~# cephadm pull
Pulling container image quay.io/ceph/ceph:v20...
{
"ceph_version": "ceph version 20.2.2 (0fcffee29411e3a38036764817b6e1afc59741cc) tentacle (stable)",
"image_id": "6b4b5ae33acd3d736eb26d2a19238bce71a22f9cfb99cca887ba6312d0957644",
"repo_digests": [
"quay.io/ceph/ceph@sha256:6b4b5ae33acd3d736eb26d2a19238bce71a22f9cfb99cca887ba6312d0957644"
]
}
# docker pull quay.io/ceph/ceph:v20.2.0
# docker save quay.io/ceph/ceph:v20.2.0 > ceph-v20.2.0.tar
# 传输到其他节点后:docker load < ceph-v20.2.0.tar

2.1.5 初始化ceph集群

1
2
3
4
5
6
7
8
9
10
11
cephadm bootstrap \
--mon-ip 10.10.0.230 \
--cluster-network 192.168.75.0/24 \
--initial-dashboard-user admin \
--initial-dashboard-password 'Admin@2024' \
--dashboard-password-noupdate \
--allow-overwrite \
--config /etc/ceph/ceph.conf \
--ssh-user root \
--ssh-config /root/.ssh/config \
--allow-fqdn-hostname
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
root@ceph-node1:~# cephadm bootstrap --mon-ip 10.10.0.230 --cluster-network 192.168.75.0/24 --allow-fqdn-hostname
Creating directory /etc/ceph for ceph.conf
Verifying podman|docker is present...
Verifying lvm2 is present...
Verifying time synchronization is in place...
Unit systemd-timesyncd.service is enabled and running
Repeating the final host check...
docker (/usr/bin/docker) is present
systemctl is present
lvcreate is present
Unit systemd-timesyncd.service is enabled and running
Host looks OK
Cluster fsid: 32e044ec-8fb1-11f1-a636-000c29b8ae8b
Verifying IP 10.10.0.230 port 3300 ...
Verifying IP 10.10.0.230 port 6789 ...
Mon IP `10.10.0.230` is in CIDR network `10.10.0.0/24`
Mon IP `10.10.0.230` is in CIDR network `10.10.0.0/24`
Pulling container image quay.io/ceph/ceph:v20...
Ceph version: ceph version 20.2.2 (0fcffee29411e3a38036764817b6e1afc59741cc) tentacle (stable)
Extracting ceph user uid/gid from container image...
Creating initial keys...
Creating initial monmap...
Creating mon...
Waiting for mon to start...
Waiting for mon...
mon is available
Assimilating anything we can from ceph.conf...
Generating new minimal ceph.conf...
Restarting the monitor...
Setting public_network to 10.10.0.0/24 in global config section
Setting cluster_network to 192.168.75.0/24
Wrote config to /etc/ceph/ceph.conf
Wrote keyring to /etc/ceph/ceph.client.admin.keyring
Creating mgr...
Verifying port 0.0.0.0:9283 ...
Verifying port 0.0.0.0:8765 ...
Verifying port 0.0.0.0:8443 ...
Waiting for mgr to start...
Waiting for mgr...
mgr not available, waiting (1/15)...
mgr not available, waiting (2/15)...
mgr is available
Enabling cephadm module...
Waiting for the mgr to restart...
Waiting for mgr epoch 4...
mgr epoch 4 is available
Verifying orchestrator module is enabled...
Setting orchestrator backend to cephadm...
Generating ssh key...
Wrote public SSH key to /etc/ceph/ceph.pub
Adding key to root@localhost authorized_keys...
Adding host ceph-node1...
Deploying mon service with default placement...
Deploying mgr service with default placement...
Deploying crash service with default placement...
Deploying ceph-exporter service with default placement...
Deploying prometheus service with default placement...
Deploying grafana service with default placement...
Deploying node-exporter service with default placement...
Deploying alertmanager service with default placement...
Enabling the dashboard module...
Waiting for the mgr to restart...
Waiting for mgr epoch 8...
mgr epoch 8 is available
Using certmgr to generate dashboard self-signed certificate...
Creating initial admin user...
Fetching dashboard port number...
Ceph Dashboard is now available at:

URL: https://ceph-node1:8443/
User: admin
Password: kga53xcdds

Enabling client.admin keyring and conf on hosts with "admin" label
Saving cluster configuration to /var/lib/ceph/32e044ec-8fb1-11f1-a636-000c29b8ae8b/config directory
You can access the Ceph CLI as following in case of multi-cluster or non-default config:

sudo /usr/sbin/cephadm shell --fsid 32e044ec-8fb1-11f1-a636-000c29b8ae8b -c /etc/ceph/ceph.conf -k /etc/ceph/ceph.client.admin.keyring

Or, if you are only running a single cluster on this host:

sudo /usr/sbin/cephadm shell

Please consider enabling telemetry to help improve Ceph:

ceph telemetry on

For more information see:

https://docs.ceph.com/en/latest/mgr/telemetry/

Bootstrap complete.
Log rotation will not occur because the logrotate service is not installed. Please install it to enable log rotation.

root@ceph-node1:~# sudo /usr/sbin/cephadm shell --fsid 32e044ec-8fb1-11f1-a636-000c29b8ae8b -c /etc/ceph/ceph.conf -k /etc/ceph/ceph.client.admin.keyring
Inferring config /var/lib/ceph/32e044ec-8fb1-11f1-a636-000c29b8ae8b/mon.ceph-node1/config
Not using image 'sha256:6b4b5ae33acd3d736eb26d2a19238bce71a22f9cfb99cca887ba6312d0957644' of ceph daemon: not in the list of non-dangling images with ceph=True label
root@ceph-node1:/# ceph orch ps
NAME HOST PORTS STATUS REFRESHED AGE MEM USE MEM LIM VERSION IMAGE ID CONTAINER ID
alertmanager.ceph-node1 ceph-node1 *:9093,9094 running (5m) 4m ago 6m 15.4M - 0.28.1 27c475db5fb1 f08a4d4df76b
ceph-exporter.ceph-node1 ceph-node1 *:9926 running (6m) 4m ago 6m 7516k - 20.2.2 6b4b5ae33acd cb5e42c910e0
crash.ceph-node1 ceph-node1 running (6m) 4m ago 6m 7967k - 20.2.2 6b4b5ae33acd f60e70c42deb
grafana.ceph-node1 ceph-node1 *:3000 running (5m) 4m ago 6m 107M - 12.3.1 2175aaa91c96 c778de84fdee
mgr.ceph-node1.axywbf ceph-node1 *:9283,8765,8443 running (7m) 4m ago 7m 206M - 20.2.2 6b4b5ae33acd 67f106fa9d88
mon.ceph-node1 ceph-node1 running (7m) 4m ago 7m 33.9M 2048M 20.2.2 6b4b5ae33acd 6148eacad298
node-exporter.ceph-node1 ceph-node1 *:9100 running (6m) 4m ago 6m 8968k - 1.9.1 d00a542e409e 5e51982a1229
prometheus.ceph-node1 ceph-node1 *:9095 running (5m) 4m ago 5m 91.4M - 3.6.0 76947e7ef22f 654b7a9bf8bc

宿主机安装管理命令common

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@ceph-node1:~# cephadm add-repo --release tentacle
Installing repo GPG key from https://download.ceph.com/keys/release.gpg...
Installing repo file at /etc/apt/sources.list.d/ceph.list...
Updating package list...
Completed adding repo.
root@ceph-node1:~# apt-cache madison ceph-common
ceph-common | 20.2.2-1noble | https://download.ceph.com/debian-tentacle noble/main amd64 Packages
ceph-common | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-updates/main amd64 Packages
ceph-common | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-security/main amd64 Packages
ceph-common | 19.2.0~git20240301.4c76c50-0ubuntu6 | http://mirrors.aliyun.com/ubuntu noble/main amd64 Packages

#可选:
root@ceph-node1:~# cat /etc/apt/sources.list.d/ceph.list
deb https://mirrors.tuna.tsinghua.edu.cn/ceph/debian-tentacle/ noble main

#安装
root@ceph-node1:~# apt install ceph-common

分发ceph密钥

1
2
3
root@ceph-node1:~# ssh-copy-id -f -i /etc/ceph/ceph.pub root@ceph-node1
root@ceph-node1:~# ssh-copy-id -f -i /etc/ceph/ceph.pub root@ceph-node2
root@ceph-node1:~# ssh-copy-id -f -i /etc/ceph/ceph.pub root@ceph-node3

2.1.6 添加主机

1
2
3
4
5
6
7
8
root@ceph-node1:~# cephadm shell ceph orch host add ceph-node2 10.10.0.231
Inferring fsid 32e044ec-8fb1-11f1-a636-000c29b8ae8b
Inferring config /var/lib/ceph/32e044ec-8fb1-11f1-a636-000c29b8ae8b/mon.ceph-node1/config
Not using image 'sha256:6b4b5ae33acd3d736eb26d2a19238bce71a22f9cfb99cca887ba6312d0957644' of ceph daemon: not in the list of non-dangling images with ceph=True label
Added host 'ceph-node2' with addr '10.10.0.231'
root@ceph-node1:~# ceph orch host add ceph-node3 10.10.0.232
Added host 'ceph-node3' with addr '10.10.0.232'

添加到集群的主机默认都部署了mon服务

常用命令

·查看集群主机·

ceph orch host ls

·调整mon 节点·

会中止其他节点的mon服务,到指定节点起mon服务

ceph orch apply mon mon1-hostname mon2-hostname mon3-hostname

·列出所有当前存储在 Monitor 配置数据库中的配置选项及其值·

ceph config dump

·列出主机磁盘设备·

ceph orch device ls

·重启osd daemon·

ceph orch daemon restart osd.2

ceph orch host rescan ceph-node3

·开启/关闭自动部署 osd service spec·

ceph orch apply osd --all-available-devices

ceph orch rm osd.all-available-devices

只删除自动部署规则,不会删除已经创建的 OSD

root@ceph-node1:# ceph orch rm osd.all-available-devices
Error EINVAL: If osd.all-available-devices is removed then the following OSDs will remain, –force to proceed anyway
host ceph-node3: osd.2
root@ceph-node1:
# ceph orch rm osd.all-available-devices –force

1
2
3
4
5
6
7
8
root@ceph-node1:~# ceph orch device ls
HOST PATH TYPE DEVICE ID SIZE AVAILABLE REFRESHED REJECT REASONS
ceph-node1 /dev/nvme0n1 ssd VMware_Virtual_NVMe_Disk_VMware_NVME_0000 20.0G Yes 6m ago
ceph-node1 /dev/sdb hdd 20.0G Yes 6m ago
ceph-node2 /dev/nvme0n1 ssd VMware_Virtual_NVMe_Disk_VMware_NVME_0000 20.0G Yes 19m ago
ceph-node2 /dev/sdb hdd 20.0G Yes 19m ago
ceph-node3 /dev/nvme0n1 ssd VMware_Virtual_NVMe_Disk_VMware_NVME_0000 20.0G Yes 19m ago
ceph-node3 /dev/sdb hdd 20.0G Yes 19m ago

2.1.7 部署OSD

数据分类保存方式:

Data: ceph保存的数据对象

Block: rocks DB数据即元数据

block-wal: 数据库的wal日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 方式一:自动部署所有可用磁盘(推荐)
ceph orch apply osd --all-available-devices

# 方式二:指定节点和磁盘部署
# ceph orch daemon add osd ceph-node1:/dev/sdb,/dev/sdc,/dev/sdd
# ceph orch daemon add osd ceph-node2:/dev/sdb,/dev/sdc,/dev/sdd
# ceph orch daemon add osd ceph-node3:/dev/sdb,/dev/sdc,/dev/sdd

# 查看 OSD 部署进度
ceph orch ps --daemon-type osd

# 查看 OSD 状态
ceph osd tree
ceph osd stat
1
2
3
4
5
6
7
8
9
10
11
12
root@ceph-node1:~# ceph orch daemon add osd ceph-node1:/dev/nvme0n1
Created osd(s) 0 on host 'ceph-node1'
root@ceph-node1:~# ceph orch daemon add osd ceph-node2:/dev/nvme0n1
Created osd(s) 1 on host 'ceph-node2'
root@ceph-node1:~# ceph orch daemon add osd ceph-node3:/dev/nvme0n1
Created osd(s) 2 on host 'ceph-node3'
root@ceph-node1:~# ceph orch daemon add osd ceph-node1:/dev/sdb
Created osd(s) 3 on host 'ceph-node1'
root@ceph-node1:~# ceph orch daemon add osd ceph-node2:/dev/sdb
Created osd(s) 4 on host 'ceph-node2'
root@ceph-node1:~# ceph orch daemon add osd ceph-node3:/dev/sdb
Created osd(s) 5 on host 'ceph-node3'
1
2
3
4
root@ceph-node1:/var/lib/ceph/32e044ec-8fb1-11f1-a636-000c29b8ae8b/osd.0# ls -l
total 64
lrwxrwxrwx 1 167 167 93 Aug 4 11:51 block -> /dev/ceph-0c12d607-500a-4a4e-ac8e-108463f59511/osd-block-0e57a8c8-066a-4145-9674-58e81c3ab770
-rw----

时间同步和互联网同步时间的节点作为server 其他节点同步存在时间偏移

1
2
3
4
5
# 临时放宽到 1 秒
ceph config set mon mon_clock_drift_allowed 1.0

# 确认生效
ceph config get mon mon_clock_drift_allowed
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
root@ceph-node1:~# ceph orch daemon add --help

General usage:
==============
usage: ceph [-h] [-c CEPHCONF] [-i INPUT_FILE] [-o OUTPUT_FILE] [--setuser SETUSER] [--setgroup SETGROUP]
[--id CLIENT_ID] [--name CLIENT_NAME] [--cluster CLUSTER] [--admin-daemon ADMIN_SOCKET] [-s] [-w]
[--watch-debug] [--watch-info] [--watch-sec] [--watch-warn] [--watch-error] [-W WATCH_CHANNEL]
[--version] [--verbose] [--concise] [--daemon-output-file DAEMON_OUTPUT_FILE]
[-f {json,json-pretty,xml,xml-pretty,plain,yaml}] [--connect-timeout CLUSTER_TIMEOUT] [--block]
[--period PERIOD]

Ceph administration tool

options:
-h, --help request mon help
-c CEPHCONF, --conf CEPHCONF
ceph configuration file
-i INPUT_FILE, --in-file INPUT_FILE
input file, or "-" for stdin
-o OUTPUT_FILE, --out-file OUTPUT_FILE
output file, or "-" for stdout
--setuser SETUSER set user file permission
--setgroup SETGROUP set group file permission
--id CLIENT_ID, --user CLIENT_ID
client id for authentication
--name CLIENT_NAME, -n CLIENT_NAME
client name for authentication
--cluster CLUSTER cluster name
--admin-daemon ADMIN_SOCKET
submit admin-socket command (e.g. "help" fora list of available commands)
-s, --status show cluster status
-w, --watch watch live cluster changes
--watch-debug watch debug events
--watch-info watch info events
--watch-sec watch security events
--watch-warn watch warn events
--watch-error watch error events
-W WATCH_CHANNEL, --watch-channel WATCH_CHANNEL
watch live cluster changes on a specific channel (e.g., cluster, audit, cephadm, or '*'
for all)
--version, -v display version
--verbose make verbose
--concise make less verbose
--daemon-output-file DAEMON_OUTPUT_FILE
output file location local to the daemon for JSON produced by tell commands
-f {json,json-pretty,xml,xml-pretty,plain,yaml}, --format {json,json-pretty,xml,xml-pretty,plain,yaml}
Note: yaml is only valid for orch commands
--connect-timeout CLUSTER_TIMEOUT
set a timeout for connecting to the cluster
--block block until completion (scrub and deep-scrub only)
--period PERIOD, -p PERIOD
polling period, default 1.0 second (for polling commands only)

Local commands:
===============

ping <mon.id> Send simple presence/life test to a mon
<mon.id> may be 'mon.*' for all mons
daemon {type.id|path} <cmd>
Same as --admin-daemon, but auto-find admin socket
daemonperf {type.id | path} [stat-pats] [priority] [<interval>] [<count>]
daemonperf {type.id | path} list|ls [stat-pats] [priority]
Get selected perf stats from daemon/admin socket
Optional shell-glob comma-delim match string stat-pats
Optional selection priority (can abbreviate name):
critical, interesting, useful, noninteresting, debug
List shows a table of all available stats
Run <count> times (default forever),
once per <interval> seconds (default 1)


Monitor commands:
=================
orch daemon add [<daemon_type:mon|mgr|rbd-mirror|cephfs- Add daemon(s)
mirror|crash|alertmanager|grafana|node-exporter|ceph-
exporter|prometheus|loki|promtail|mds|rgw|nfs|iscsi|
nvmeof|snmp-gateway|elasticsearch|jaeger-agent|jaeger-
collector|jaeger-query>] [<placement>]
orch daemon add iscsi <pool> <api_user> <api_password> Start iscsi daemon(s)
[<trusted_ip_list>] [<placement>]
orch daemon add mds <fs_name> [<placement>] Start MDS daemon(s)
orch daemon add nfs <svc_id> [<placement>] Start NFS daemon(s)
orch daemon add nvmeof <pool> <group> [<placement>] Start nvmeof daemon(s)
orch daemon add osd [<svc_arg>] [<method:raw|lvm>] [-- Create OSD daemon(s) on specified host and device(s) (e.
skip-validation] g., ceph orch daemon add osd myhost:/dev/sdb)
orch daemon add rgw <svc_id> [<placement>] [--port Start RGW daemon(s)
<int>] [--ssl]

不清楚为什么node1节点有个daemon stop的使用下面的命令,提示把正在运行的node3节点的osd.2删除了

ceph orch daemon rm osd.2 --host ceph-node1 --force

数据在的lvm 正常,加入不了直接删了

现在 cephadm 已经没有 osd.2 daemon,所以直接:

1
ceph osd out 2

然后删除:

1
ceph osd crush remove osd.2

删除认证:

1
ceph auth del osd.2

删除 OSD:

1
ceph osd rm 2
1
2
3
4
5
lvremove -y /dev/ceph-ece6de67-8e56-4e59-89e4-823558549b5d/osd-block-2e0fe218-8b07-41f5-849b-af99538a3000
vgremove -y ceph-ece6de67-8e56-4e59-89e4-823558549b5d
root@ceph-node3:~# pvremove /dev/nvme0n1
Labels on physical volume "/dev/nvme0n1" successfully wiped.
root@ceph-node3:~# wipefs -a /dev/nvme0n1

重新加入

1
2
ceph orch daemon add osd ceph-node3:/dev/nvme0n1
ceph orch device zap ceph-node3 /dev/nvme0n1 --force

image-20260804165207850

2.3 grafana初始化

默认情况下,Grafana不会创建初始管理员用户。为了创建管理员用户,请创建一个grafana.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@ceph-node1:~# cat grafana.yaml
service_type: grafana
spec:
initial_admin_password: admin

ceph orch apply -i grafana.yaml
如果已经部署好了,只想迁移节点:
root@ceph-node1:~# cat grafana.yaml
service_type: grafana
spec:
initial_admin_password: admin
placement:
hosts:
- ceph-node2

访问Grafana:https://10.10.0.231:3000/
image-20260804173315369

2.4 从RADOS移除OSD

Ceph集群中的一个OSD是一个node节点的服务进程对应一个磁盘设备,是一个专用的守护进程,在某个OSD设备出现故障,管理员出于管理的需要,需要移除特定的OSD设备时,需要先停止相关的守护进程,然后再进行移除操作。

1
2
3
4
5
6
7
8
9
10
#停用设备
ceph osd out osd.x

# 停止daemon 容器
ceph orch daemon stop osd.x

# 安全移除OSD
ceph orch daemon rm osd.x --force
# 删除crush信息
ceph orch rm osd.all-available-devices --force

三、存储池管理

3.1 创建存储池

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
# 创建存储池
root@ceph-node1:~# ceph osd pool create myrbd1 64 64
pool 'myrbd1' created
# 存储池启用rbd块存储
root@ceph-node1:~# ceph osd pool application enable myrbd1 rbd
enabled application 'rbd' on pool 'myrbd1'
# 初始化存储池
root@ceph-node1:~# rbd pool init -p myrbd1
# 创建映像
root@ceph-node1:~# rbd create myimg1 --size 5G --pool myrbd1
root@ceph-node1:~# rbd create myimg2 --size 3G --pool myrbd1 --image-format 2 --image-feature layering
root@ceph-node1:~# rbd --image myimg1 -p myrbd1 info
rbd image 'myimg1':
size 5 GiB in 1280 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 401a185ec2d1
block_name_prefix: rbd_data.401a185ec2d1
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Tue Aug 4 23:41:06 2026
access_timestamp: Tue Aug 4 23:41:06 2026
modify_timestamp: Tue Aug 4 23:41:06 2026

3.2 客户端挂在块存储

安装ceph-common

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
root@client:~# apt update
Hit:1 http://mirrors.aliyun.com/ubuntu noble InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu noble-updates InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu noble-backports InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
166 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@client:~# apt-cache madison ceph-common
ceph-common | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-updates/main amd64 Packages
ceph-common | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-security/main amd64 Packages
ceph-common | 19.2.0~git20240301.4c76c50-0ubuntu6 | http://mirrors.aliyun.com/ubuntu noble/main amd64 Packages
root@client:~# apt install ceph-common -y

# ceph 分发集群配置文件和ceph客户端认证文件
root@ceph-node1:~# scp /etc/ceph/ceph.conf /etc/ceph/ceph.client.admin.keyring 10.10.0.233:/etc/ceph/
The authenticity of host '10.10.0.233 (10.10.0.233)' can't be established.
ED25519 key fingerprint is SHA256:G9pwl4hDlg93WN7lqixOV79vGmLDmWSZl2TUv132HcA.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: [hashed name]
~/.ssh/known_hosts:4: [hashed name]
~/.ssh/known_hosts:5: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.0.233' (ED25519) to the list of known hosts.
root@10.10.0.233's password:
ceph.conf 100% 265 313.2KB/s 00:00
ceph.client.admin.keyring 100% 151 223.6KB/s 00:00

# 客户端映射镜像 映射块设备到本地
root@client:~# rbd -p myrbd1 map myimg1
/dev/rbd0


#格式化
root@client:~# mkfs.ext4 /dev/rbd0
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 15f082cd-85a5-4ad5-9bc4-47bfd3747eb2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

root@client:~# mkdir /data
root@client:~# mount /dev/rbd0 /data
root@client:~# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 192M 952K 192M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 38G 6.9G 29G 20% /
tmpfs 960M 0 960M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 99M 1.7G 6% /boot
tmpfs 192M 12K 192M 1% /run/user/0
/dev/rbd0 4.9G 24K 4.6G 1% /data

image-20260805000411301

image-20260805000500942

3.2.1 验证数据 :

1
ceph df

3.2.2删除数据

1
2
3
4
5
6
7
8
9
10
rm -rf /data/*
# 删除完成的数据只是标记为已经被删除,但是不会从块存储立即清空,因此在删除完成后使用ceph df 查看并没有回收空间

但是后期可以使用此空间,如果需要立即在系统层回收空间,需要执行以下命令:
fstrim -v /data
# /data 为挂载点,fstrim 命令来自于英文词组"filesystem trim"的缩写,其功能是回收文件系统中未使用的快资源。

或配置挂载选项
rbd -p myrbd1 map myimg1
mount -t xfs -o discard /dev/rbd0 /data #主要用户SSD,立即触发闲置的块回收
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# PG与PGP组合
root@ceph-node1:~# ceph pg ls-by-pool myrbd1 | awk '{print $1,$2,$15}'
PG OBJECTS UP
2.0 1 [4,5,3]p4
2.1 0 [3,5,4]p3
2.2 0 [1,0,2]p1
2.3 1 [4,3,5]p4
2.4 0 [0,2,1]p0
2.5 0 [2,0,1]p2
2.6 0 [3,2,4]p3
2.7 0 [4,2,3]p4
2.8 0 [1,2,0]p1
2.9 0 [3,4,5]p3
2.a 0 [2,3,1]p2
2.b 0 [5,1,0]p5
2.c 0 [2,0,1]p2
2.d 0 [5,1,3]p5

四、 Ceph 对象存储网关

RGW 提供的是REST风格的API接口,客户端通过http与其进行交互,完成数据的增删改查等管理操作。

radosgw用在需要使用RESTful API接口访问ceph数据的场合,因此在使用RBD即块存储的场合或者使用cephFS的可以不启用radosgw功能。

4.1 ceph radosgw(RGW)对象存储网关

Ceph RADOS Gateway (RGW) 是基于 RADOS 之上构建的对象存储接口,支持 Amazon S3 和 OpenStack Swift API。

4.1.1部署radosgw服务

在 cephadm 环境中,可以通过应用规范文件 (Spec File) 或命令行快速部署 RGW 服务。

在首次部署 RGW 之前,必须显式建立 Ceph RGW 的三级组织架构,并提交配置(Period)。

1 创建 Realm(领域)

1
radosgw-admin realm create --rgw-realm=default --default

2 创建Zonegroup(区域组)并绑定 Realm

1
radosgw-admin zonegroup create --rgw-zonegroup=default --rgw-realm=default --master --default

3 创建 Zone(区域)并绑定 Zonegroup 与 Realm

1
radosgw-admin zone create --rgw-zonegroup=default --rgw-zone=default --rgw-realm=default --master --default

4 提交 Period(配置生效)

1
radosgw-admin period update --commit

确认标志:输出中包含 "current_period" 以及 "epoch": 1(或更高的数字),且无错误提示。

部署 RGW 守护进程服务

底层的元数据链路打通后,使用 cephadm 自动化部署容器化 RGW 服务。

5 部署 RGW 服务

在主控节点上运行以下命令,指定端口(如 8000)及运行主机:

1
ceph orch apply rgw site-rgw --realm=default --zone=default --placement="2 ceph-node1 ceph-node2" --port=8000

方法一:通过 CLI 部署

使用 ceph orch apply rgw 命令指定服务名称、绑定的 Realm/Zone、节点选择器及端口:

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
1. 将 Zonegroup 关联到 default Realm
# 将默认区域组 default 关联到 默认领域default 并设置主
# 相当于 global region zone的关系

radosgw-admin zonegroup modify --rgw-zonegroup=default --rgw-realm=default --master --default

2. 将 Zone 关联到 default Realm 与 Zonegroup


radosgw-admin zone modify --rgw-zonegroup=default --rgw-zone=default --rgw-realm=default --master --default
3. 重新提交 Period 配置(关键)

radosgw-admin period update --commit
root@ceph-node1:~# radosgw-admin zonegroup modify --rgw-zonegroup=default --rgw-realm=default --master --default
{
"id": "df2cd05f-464f-45b0-afb2-95e5c3ea4e43",
"name": "default",
"api_name": "default",
"is_master": true,
"endpoints": [],
"hostnames": [],
"hostnames_s3website": [],
"master_zone": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"zones": [
{
"id": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"name": "default",
"endpoints": [],
"log_meta": false,
"log_data": false,
"bucket_index_max_shards": 11,
"read_only": false,
"tier_type": "",
"sync_from_all": true,
"sync_from": [],
"redirect_zone": "",
"supported_features": [
"compress-encrypted",
"notification_v2",
"resharding"
]
}
],
"placement_targets": [
{
"name": "default-placement",
"tags": [],
"storage_classes": [
"STANDARD"
]
}
],
"default_placement": "default-placement",
"realm_id": "0a0b9442-1f77-4ba1-8dc4-f73155fe5539",
"sync_policy": {
"groups": []
},
"enabled_features": [
"notification_v2",
"resharding"
]
}
root@ceph-node1:~# radosgw-admin zone modify --rgw-zonegroup=default --rgw-zone=default --rgw-realm=default --master --default
{
"id": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"name": "default",
"domain_root": "default.rgw.meta:root",
"control_pool": "default.rgw.control",
"dedup_pool": "default.rgw.dedup",
"gc_pool": "default.rgw.log:gc",
"lc_pool": "default.rgw.log:lc",
"log_pool": "default.rgw.log",
"intent_log_pool": "default.rgw.log:intent",
"usage_log_pool": "default.rgw.log:usage",
"roles_pool": "default.rgw.meta:roles",
"reshard_pool": "default.rgw.log:reshard",
"user_keys_pool": "default.rgw.meta:users.keys",
"user_email_pool": "default.rgw.meta:users.email",
"user_swift_pool": "default.rgw.meta:users.swift",
"user_uid_pool": "default.rgw.meta:users.uid",
"otp_pool": "default.rgw.otp",
"notif_pool": "default.rgw.log:notif",
"topics_pool": "default.rgw.meta:topics",
"account_pool": "default.rgw.meta:accounts",
"group_pool": "default.rgw.meta:groups",
"bucket_logging_pool": "default.rgw.log:logging",
"system_key": {
"access_key": "",
"secret_key": ""
},
"placement_pools": [
{
"key": "default-placement",
"val": {
"index_pool": "default.rgw.buckets.index",
"storage_classes": {
"STANDARD": {
"data_pool": "default.rgw.buckets.data"
}
},
"data_extra_pool": "default.rgw.buckets.non-ec",
"index_type": 0,
"inline_data": true
}
}
],
"realm_id": "0a0b9442-1f77-4ba1-8dc4-f73155fe5539",
"restore_pool": "default.rgw.log:restore"
}
root@ceph-node1:~# radosgw-admin period update --commit
{
"id": "4846c6fd-4086-4cae-b098-9cc28ba8d2ff",
"epoch": 1,
"predecessor_uuid": "353326ef-bb40-480d-a859-e19ea227332f",
"sync_status": [],
"period_map": {
"id": "4846c6fd-4086-4cae-b098-9cc28ba8d2ff",
"zonegroups": [
{
"id": "df2cd05f-464f-45b0-afb2-95e5c3ea4e43",
"name": "default",
"api_name": "default",
"is_master": true,
"endpoints": [],
"hostnames": [],
"hostnames_s3website": [],
"master_zone": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"zones": [
{
"id": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"name": "default",
"endpoints": [],
"log_meta": false,
"log_data": false,
"bucket_index_max_shards": 11,
"read_only": false,
"tier_type": "",
"sync_from_all": true,
"sync_from": [],
"redirect_zone": "",
"supported_features": [
"compress-encrypted",
"notification_v2",
"resharding"
]
}
],
"placement_targets": [
{
"name": "default-placement",
"tags": [],
"storage_classes": [
"STANDARD"
]
}
],
"default_placement": "default-placement",
"realm_id": "0a0b9442-1f77-4ba1-8dc4-f73155fe5539",
"sync_policy": {
"groups": []
},
"enabled_features": [
"notification_v2",
"resharding"
]
}
],
"short_zone_ids": [
{
"key": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"val": 792671700
}
]
},
"master_zonegroup": "df2cd05f-464f-45b0-afb2-95e5c3ea4e43",
"master_zone": "e7571b98-2dc3-4d57-87b8-c35a1bd15bd4",
"period_config": {
"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
},
"user_ratelimit": {
"max_read_ops": 0,
"max_write_ops": 0,
"max_read_bytes": 0,
"max_write_bytes": 0,
"enabled": false
},
"bucket_ratelimit": {
"max_read_ops": 0,
"max_write_ops": 0,
"max_read_bytes": 0,
"max_write_bytes": 0,
"enabled": false
},
"anonymous_ratelimit": {
"max_read_ops": 0,
"max_write_ops": 0,
"max_read_bytes": 0,
"max_write_bytes": 0,
"enabled": false
}
},
"realm_id": "0a0b9442-1f77-4ba1-8dc4-f73155fe5539",
"realm_epoch": 2
}
root@ceph-node1:~# ceph orch restart rgw.site-rgw
Error EINVAL: Invalid service name "rgw.site-rgw". View currently running services using "ceph orch ls"
root@ceph-node1:~# ceph orch apply rgw site-rgw --realm=default --zone=default --placement="2 ceph-node1 ceph-node2" --port=8000
Scheduled rgw.site-rgw update...


ceph orch apply rgw <service_id> <realm> <zone> --placement="<节点策略>" --port=<端口号>
# 在主控节点上执行,部署名为 rgw.realm.zone 的服务实例,副本数为 2

root@ceph-node1:~# curl localhost:8000
\<?xml version="1.0" encoding="UTF-8"?><ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>anonymous</ID></Owner><Buckets></Buckets></ListAllMyBucketsResult>root@ceph-node1:~#

方法二:通过 YAML 规范文件部署(推荐)

  1. 创建规范文件 rgw-spec.yaml:
1
2
3
4
5
6
7
8
9
10
11
12
service_type: rgw
service_id: site-rgw
service_name: rgw.site-rgw
placement:
hosts:
- node1
- node2
count: 2
spec:
rgw_realm: default
rgw_zone: default
rgw_frontend_port: 8000
  1. 应用规范文件:
1
ceph orch apply -i rgw-spec.yaml

4.1.2:验证radosgw服务

部署完成后,检查 cephadm 管理的服务状态以及运行中的容器容器状态。

  1. 查看 RGW 服务列表:
1
ceph orch ls --service_type=rgw

预期输出:

1
2
NAME           PORTS   RUNNING  REFRESHED  AGE  PLACEMENT
rgw.site-rgw *:8000 2/2 10s ago 2m node1;node2
  1. 查看守护进程运行状态:
1
ceph orch ps --daemon_type=rgw
  1. 测试 HTTP 响应:

使用 curl 验证 RGW 服务端点:

1
curl http://node1:8000

预期返回 XML 格式响应(如 <ListAllMyBucketsResult>),说明 RGW 接口服务已成功响应 HTTP 请求。

  1. 创建对象存储用户与密钥(测试用):
1
2
3
ceph orchestrator daemon restart rgw.site-rgw.node1.xxxxxx
# 创建管理员账户
radosgw-admin user create --uid="admin" --display-name="Admin User" --system

4.1.3:验证ceph状态

确认添加 RGW 服务后,集群整体健康状态正常。

1
ceph -s

预期输出示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cluster:
id: a7f1b2c3-4d5e-6f7a-8b9c-0d1e2f3a4b5c
health: HEALTH_OK

services:
mon: 3 daemons, quorum node1,node2,node3
mgr: node1(active, since 2h), standbys: node2
osd: 6 osds: 6 up, 6 in
rgw: 2 daemons active (2 hosts, 1 zone)

data:
pools: 6 pools, 128 pgs
objects: 187 objects, 4.2 MiB
usage: 1.2 GiB used, 60 GiB / 61.2 GiB avail
pgs: 128 active+clean

确保 health 显示为 HEALTH_OK,且 rgw 字段显示正确的活跃 Daemon 数量。


4.1.4:验证radosgw存储池

RGW 服务初始化时会自动创建一系列默认的系统存储池(Pools)。

  1. 列出所有 RADOS 存储池:
1
2
3
ceph df
# 或
ceph osd pool ls detail
  1. 自动生成的 RGW 存储池包含:

    • .rgw.root:存储全局配置与 Realm/Zonegroup/Zone 元数据
    • default.rgw.main.pools
    • default.rgw.control:控制流通知
    • default.rgw.meta:用户与 Bucket 元数据
    • default.rgw.log:日志与操作审计
    • default.rgw.buckets.data:实际存储对象数据的默认池
    • default.rgw.buckets.index:Bucket 索引与清册
  2. 检查存储池 PG 状态与应用类型:

1
ceph osd pool application get default.rgw.buckets.data

预期输出:

1
2
3
4
5
{
"default.rgw.buckets.data": {
"rgw": {}
}
}

4.2 Ceph-FS文件存储

Ceph File System (CephFS) 是一个符合 POSIX 标准的文件系统,依赖 MDS (Metadata Server) 守护进程来管理目录树和文件元数据。构建于 Ceph 的分布式对象存储 RADOS 之上。CephFS 致力于为各种应用提供一个先进、多用途、高可用且高性能的文件存储,包括共享主目录、HPC 暂存空间和分布式工作流共享存储等传统用例。

可以实现文件系统共享功能,客户端通过ceph协议挂载并使用,ceph 集群作为数据存储服务器。

ephFS 通过新颖的架构选择实现了这些目标。值得注意的是,文件元数据存储在与文件数据分开的 RADOS 存储池中,并通过一个可调整大小的元数据服务器(简称 MDS)集群提供服务,该集群可以扩展以支持更高吞吐量的工作负载。文件系统的客户端可以直接访问 RADOS 来读取和写入文件数据块。这使得工作负载能够随着底层 RADOS 对象存储的大小线性扩展。没有网关或代理来协调客户端的数据 I/O。

对数据的访问由 MDS 集群协调,该集群充当分布式元数据缓存状态的权威机构,该缓存由客户端和 MDS 共同维护。对元数据的修改由每个 MDS 聚合到一系列高效写入到 RADOS 上的日志中;MDS 本地不存储元数据状态。这种模型允许客户端在 POSIX 文件系统的上下文中实现连贯且快速的协作。image-20260806104352742

4.2.1:部署MDS服务

使用 cephadm 部署 MDS 服务,为 CephFS 提供元数据处理能力。

方法一:通过 CLI 直接应用

1
2
# 在指定节点上部署 2 个 MDS 实例(1个主,1个热备)
ceph orch apply mds myfs --placement="2 node1 node2"

方法二:通过 YAML 规范文件部署

  1. 创建 mds-spec.yaml:
1
2
3
4
5
6
7
service_type: mds
service_id: myfs
placement:
hosts:
- node1
- node2
count: 2
  1. 应用配置:
1
ceph orch apply -i mds-spec.yaml

4.2.2:验证MDS服务

检查 MDS 守护进程的启动和运行状态。

  1. 查看 MDS 服务汇总状态:
1
2
3
4
5
6
ceph orch ls --service_type=mds

root@ceph-node1:~# ceph orch ls --service_type=mds
NAME PORTS RUNNING REFRESHED AGE PLACEMENT
mds.myfs 2/2 85s ago 95s ceph-node2;ceph-node3;count:2

  1. 查看 MDS 容器进程详情:
1
2
3
4
5
6
ceph orch ps --daemon_type=mds
root@ceph-node1:~# ceph orch ps --daemon_type=mds
NAME HOST PORTS STATUS REFRESHED AGE MEM USE MEM LIM VERSION IMAGE ID CONTAINER ID
mds.myfs.ceph-node2.unogmh ceph-node2 running (119s) 113s ago 119s 17.9M - 20.2.2 6b4b5ae33acd 3537c3485381
mds.myfs.ceph-node3.ydxqjg ceph-node3 running (2m) 113s ago 2m 12.8M - 20.2.2 6b4b5ae33acd 776125a3c7c7

查看状态:

1
2
3
root@ceph-node1:~# ceph mds stat
2 up:standby
# 当前为备用状态,需要分配存储池才可以使用

4.2.3:创建CephFS metadata和data存储池

CephFS 需要至少两个独立的 RADOS 存储池:一个用于存储文件系统元数据 (Metadata Pool),另一个用于存储实际文件数据 (Data Pool)。

  1. 创建元数据存储池 (CephFS Metadata Pool):
1
2
# 创建名为 cephfs.myfs.meta 的存储池,指定 PG 数量为 32
ceph osd pool create cephfs.myfs.meta 32 32
  1. 创建数据存储池 (CephFS Data Pool):
1
2
# 创建名为 cephfs.myfs.data 的存储池,指定 PG 数量为 64
ceph osd pool create cephfs.myfs.data 64 64
  1. 禁用 pg_autoscale(可选,根据生产需要调整):
1
2
ceph osd pool set cephfs.myfs.meta pg_autoscale_mode on
ceph osd pool set cephfs.myfs.data pg_autoscale_mode on

4.2.4:创建cephFS并验证

利用创建好的存储池关联并初始化 CephFS 文件系统。

  1. 创建 CephFS 文件系统:
1
2
3
4
5
6
7
8
9
10
11
# 格式: ceph fs new <fs_name> <metadata_pool> <data_pool>
ceph fs new myfs cephfs.myfs.meta cephfs.myfs.data


root@ceph-node1:~# ceph fs new myfs cephfs.myfs.meta cephfs.myfs.data
Pool 'cephfs.myfs.data' (id '9') has pg autoscale mode 'on' but is not marked as bulk.
Consider setting the flag by running
# ceph osd pool set cephfs.myfs.data bulk true
new fs with metadata pool 8 and data pool 9
root@ceph-node1:~# ceph mds stat
myfs:1 {0=myfs.ceph-node2.unogmh=up:active} 1 up:standby
  1. 验证文件系统创建结果:
1
2
3
4
5
ceph fs ls

root@ceph-node1:~# ceph fs ls
name: myfs, metadata pool: cephfs.myfs.meta, data pools: [cephfs.myfs.data ]


4.2.5:验证cephFS服务状态

检查 CephFS 的健康状况及 MDS 的主备(Active/Standby)角色状态。

  1. 查看 CephFS 详细状态:
1
2
3
4
5
6
7
8
9
10
11
12
13
ceph fs status myfs
root@ceph-node1:~# ceph fs status myfs
myfs - 0 clients
====
RANK STATE MDS ACTIVITY DNS INOS DIRS CAPS
0 active myfs.ceph-node2.unogmh Reqs: 0 /s 10 13 12 0
POOL TYPE USED AVAIL
cephfs.myfs.meta metadata 126k 37.7G
cephfs.myfs.data data 0 37.7G
STANDBY MDS
myfs.ceph-node3.ydxqjg
MDS version: ceph version 20.2.2 (0fcffee29411e3a38036764817b6e1afc59741cc) tentacle (stable - RelWithDebInfo)

  1. 通过 ceph status 查看:
1
ceph -s

在 services 字段中应看到类似 mds: 1/1 daemons up, 1 standby 的提示。


4.2.6:客户端挂载cephFS

支持通过 内核客户端 (Kernel Client) 或 用户态 FUSE 客户端 (ceph-fuse) 进行挂载。

准备工作:客户端密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
# 
root@client:~# cat /etc/ceph/ceph.client.admin.keyring
[client.admin]
key = AQC8VnFqFrr3ExAAzqAQpdfBta7gAPk7yC5/5A==
caps mds = "allow *"
caps mgr = "allow *"
caps mon = "allow *"
caps osd = "allow *"


# 提取密钥字符串(内核挂载用)
ceph auth get-key client.myfs > /etc/ceph/myfs.secret
chmod 600 /etc/ceph/myfs.secret

方式 1:Linux 内核客户端挂载 (Kernel Mount)

  1. 创建挂载目录:
1
mkdir -p /mnt/cephfs
  1. 使用 mount 命令挂载:
1
2
3
mount -t ceph ceph-node2:6789,ceph-node3:6789,node3:6789:/ /data   -o name=admin,secret=AQC8VnFqFrr3ExAAzqAQpdfBta7gAPk7yC5/5A==

root@client:~# mount -t ceph 10.10.0.231:6789,10.10.0.232:6789:/ /data -o name=admin,secret=AQC8VnFqFrr3ExAAzqAQpdfBta7gAPk7yC5/5A==
  1. 验证挂载与读写测试:
1
2
3
4
5
6
7
8
9
10
root@client:~# df -hT /data
Filesystem Type Size Used Avail Use% Mounted on
10.10.0.231:6789,10.10.0.232:6789:/ ceph 38G 0 38G 0% /data

echo "CephFS Test v20.2.2" > /data/text

root@client:/data# dd if=/dev/zero of=/data/test.2 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 9.01306 s, 119 MB/s

方式 2:Ceph-FUSE 用户态挂载

  1. 安装 ceph-fuse 软件包:
1
2
3
apt-get install -y ceph-fuse # Debian/Ubuntu
# 或
dnf install -y ceph-fuse # RHEL/CentOS/Rocky
  1. 执行挂载:
1
ceph-fuse -n client.myfs -m node1:6789,node2:6789,node3:6789 /data

命令总结

下表梳理了在 Ceph v20.2.2 (Cephadm) 环境中管理 RGW 与 CephFS 的常用运维命令:

分类 操作需求 核心命令 / 配置示例
RGW 管理 部署 RGW 服务 ceph orch apply rgw site-rgw default default --placement="2 node1 node2" --port=8000
查看 RGW 状态 ceph orch ls --service_type=rgw
创建 RGW 用户 radosgw-admin user create --uid="<user_id>" --display-name="<name>"
列出 RGW 存储池 ceph df (观察 .rgw.root / *.buckets.data 等)
MDS 管理 部署 MDS 服务 ceph orch apply mds <fs_name> --placement="2 node1 node2"
查看 MDS 守护进程 ceph orch ps --daemon_type=mds
CephFS 管理 创建元数据与数据池 ceph osd pool create <meta_pool> <pg_num>
ceph osd pool create <data_pool> <pg_num>
创建 CephFS 文件系统 ceph fs new <fs_name> <meta_pool> <data_pool>
查看 CephFS 列表与状态 ceph fs ls
ceph fs status <fs_name>
查看集群整体状态 ceph -s
客户端挂载 生成客户端密钥 ceph auth get-or-create client.<user> ... -o /etc/ceph/keyring
内核挂载 (Kernel Mount) mount -t ceph <MON_IP>:/ /mnt/cephfs -o name=<user>,secretfile=<path>
FUSE 挂载 ceph-fuse -n client.<user> -m <MON_IP>:6789 /mnt/cephfs

Share 

 Previous post: ceph_cluster_maintenance Next post: LLM了解 

© 2026 Hekang

Theme Typography by Makito

Proudly published with Hexo