Ceph 是支持块存储(RBD)、对象存储(RGW)、文件存储(CephFS)的统一分布式存储。使用官方 cephadm 以容器(Docker 或者 Podman + Containerd)编排各守护进程。部署见《容器部署 Ceph》。
1. 架构
1.1 拓扑与数据路径
Ceph 角色不要求每台机器都跑齐。下图是五节点常见拓扑(3 MON + 2 MGR + 5 OSD):MON 只需奇数个,五节点部署 3 个即可(容忍 1 个 MON 故障);5 个 MON 能容忍 2 个故障,但元数据开销更大,一般不必每台都跑 MON。单节点验证时 MON、MGR、OSD 均在本机。
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
| +------------------------+
| bootstrap 节点 |
| cephadm / ceph CLI |
+-----------+------------+
|
SSH 22 纳管节点 / 起容器
|
+--------+ +--------+ +--------+ +--------+ +--------+
| node1 | | node2 | | node3 | | node4 | | node5 |
| MON |<->| MON |<->| MON | | | | |
| MGR | | MGR | | | | | | |
| active | |standby | | | | | | |
|RGW(可选)| | | | | | | | |
| OSD |<->| OSD |<->| OSD |<->| OSD |<->| OSD |
+--------+ +--------+ +--------+ +--------+ +--------+
^ ^ ^ ^ ^
+-------- OSD 复制 / 恢复:6800-7300 ------------------+
RBD / CSI 数据链路:
librbd / K8s CSI --> MON 3300/6789 --> CRUSH / PG --> OSD 6800-7300
RGW / S3 数据链路:
S3 客户端 --> RGW 7480 --> CRUSH / PG --> OSD 6800-7300
管理与监控链路:
MGR active --> Dashboard 8080
MGR active --> Prometheus metrics 9283
|
数据路径:
- RBD / CSI:客户端 → MON(获取集群地图)→ CRUSH(计算落点)→ PG(逻辑分片)→ OSD(实际读写)
- RGW / S3:S3 客户端 → RGW(对象网关)→ CRUSH → PG → OSD
CRUSH 是 Ceph 的数据放置算法,PG 是存储池到 OSD 之间的逻辑分片。
1.2 组件用途与部署要求
| 组件 | 用途 | 连接 / 端口 | 部署要求 |
|---|
| cephadm | 编排集群、纳管节点 | SSH 22 | bootstrap 节点安装;各节点需 Docker 或 Podman |
| MON | 集群地图、仲裁、客户端入口 | 3300 / 6789 | 奇数个;生产通常 3 个(5 节点也够用),分散到不同节点 |
| MGR | 管理 API、Dashboard、指标模块 | 8080 / 9283 | 通常 2 个(active + standby) |
| OSD | 存储数据、复制、恢复 | 6800-7300 | 仅有块设备的节点需要;3 副本至少 3 块 OSD |
| RBD | 块存储镜像 | 客户端连 MON/OSD | 无独立守护进程,创建池与镜像即可 |
| RGW | S3 / Swift 对象网关 | 7480 | 可选,按需多实例 |
| MDS | CephFS 元数据服务 | 6800-7300 | 部署 CephFS 时需要 |
1.3 网络端口
集群节点间需互通以下端口:
| 端口 | 组件 | 用途 |
|---|
| 3300 | mon | Monitor v2 |
| 6789 | mon | Monitor v1(兼容) |
| 6800–7300 | osd / mds | OSD 心跳、复制与恢复 |
| 9283 | mgr | Prometheus /metrics |
| 8080 | dashboard | Ceph Dashboard(HTTP) |
| 7480 | rgw | S3 / Swift 对象网关 |
| 9100 | node-exp | 主机指标(监控栈) |
1.4 五节点规划示例
3 MON 分布在 node1–3,5 台均跑 OSD;MON 不必每台都有。
| 节点 | 主机名 | IP | 角色 |
|---|
| node1 | ceph-node-01 | 10.0.0.11 | MON + MGR(active)+ OSD(bootstrap) |
| node2 | ceph-node-02 | 10.0.0.12 | MON + MGR(standby)+ OSD |
| node3 | ceph-node-03 | 10.0.0.13 | MON + OSD |
| node4 | ceph-node-04 | 10.0.0.14 | OSD |
| node5 | ceph-node-05 | 10.0.0.15 | OSD |
1.5 版本时间线
| 版本号 | 开发代号 | 首版发布日期 | 当前状态 | 推荐操作系统 |
|---|
| v17 | Quincy | 2022 年 4 月 | 维护状态(即将 EOL) | RHEL/EL 8、9;Ubuntu 22.04 |
| v18 | Reef | 2023 年 8 月 | 长期支持(LTS) | RHEL/EL 8、9;Ubuntu 22.04 |
| v19 | Squid | 2024 年 7 月 | 当前主推稳定版 | RHEL/EL 9;Ubuntu 24.04 |
| v20 | Tentacle | 2025 年 | 开发中 / 预览阶段 | RHEL/EL 9;Ubuntu 24.04 |
| v21 | U 字头 | 2026 年计划 | 规划中 | 待官方发布 |
2. 功能测试
2.1 块存储(RBD)
1
2
3
4
5
6
7
8
| export RBD_POOL=test_rbd
export RBD_IMAGE=test_image
export RBD_SIZE=10G
ceph osd pool create $RBD_POOL 32 32
ceph osd pool application enable $RBD_POOL rbd
rbd create --size $RBD_SIZE $RBD_POOL/$RBD_IMAGE
rbd ls -p $RBD_POOL
|
多节点时在客户端机器安装 ceph-common,从管理节点复制配置;单节点跳过 scp,直接在本机执行后续命令。
1
2
3
4
5
6
7
8
9
10
11
12
13
| scp root@$CEPH_NODE1_IP:/etc/ceph/ceph.conf /etc/ceph/
scp root@$CEPH_NODE1_IP:/etc/ceph/ceph.client.admin.keyring /etc/ceph/
modprobe rbd
rbd map $RBD_POOL/$RBD_IMAGE
lsblk | grep rbd
mkfs.xfs /dev/rbd0
mkdir -p /mnt/ceph-rbd
mount /dev/rbd0 /mnt/ceph-rbd
echo "rbd test ok" > /mnt/ceph-rbd/test.txt
cat /mnt/ceph-rbd/test.txt
|
1
2
| umount /mnt/ceph-rbd
rbd unmap $RBD_POOL/$RBD_IMAGE
|
2.2 对象存储(RGW)
1
2
3
4
5
6
| export RGW_UID=testuser
export RGW_DISPLAY_NAME="Test User"
cephadm shell -- radosgw-admin user create \
--uid=$RGW_UID \
--display-name="$RGW_DISPLAY_NAME"
|
1
2
3
4
5
6
7
8
| export AWS_ACCESS_KEY_ID=<access_key>
export AWS_SECRET_ACCESS_KEY=<secret_key>
export RGW_ENDPOINT=http://$CEPH_NODE1_IP:$RGW_HTTP_PORT
echo "rgw test ok" > /tmp/rgw-test.txt
aws --endpoint-url $RGW_ENDPOINT s3 mb s3://test-bucket
aws --endpoint-url $RGW_ENDPOINT s3 cp /tmp/rgw-test.txt s3://test-bucket/
aws --endpoint-url $RGW_ENDPOINT s3 ls s3://test-bucket/
|
2.3 文件存储(CephFS)
1
2
3
4
5
6
7
| export CEPHFS_NAME=test_cephfs
ceph fs volume create $CEPHFS_NAME
ceph orch apply mds $CEPHFS_NAME --placement="1 $CEPH_NODE1_HOST"
ceph fs status
ceph orch ps | grep mds
|
单节点将 $CEPH_NODE1_HOST 换为 $(hostname)。
1
2
3
4
5
| mkdir -p /mnt/ceph-cephfs
ceph-fuse /mnt/ceph-cephfs
echo "cephfs test ok" > /mnt/ceph-cephfs/test.txt
cat /mnt/ceph-cephfs/test.txt
|
1
| fusermount -u /mnt/ceph-cephfs
|
3. 日常巡检
1
2
3
4
5
6
| ceph -s
ceph health detail
ceph osd stat
ceph osd tree
ceph df
ceph orch ps
|
关注项:
| 检查项 | 正常状态 | 异常处理方向 |
|---|
health | HEALTH_OK | ceph health detail 查看 WARN/ERR 原因 |
| OSD | 全部 up 且 in | 检查磁盘、容器、ceph orch daemon restart osd.<id> |
| PG | active+clean | 等待恢复;长期异常查 ceph pg stat |
| MGR | 1 个 active、其余 standby | ceph mgr dump 确认主备切换 |
| 容量 | 使用率 < 85% | 扩容 OSD 或清理数据 |
查看近期告警与日志:
1
2
| ceph log last 20
cephadm logs --name mon.$(hostname) --follow # 替换为具体 daemon 名
|
4. 配置管理
bootstrap 后执行(环境变量见部署文档):
1
| ceph config set global public_network $CEPH_PUBLIC_NETWORK
|
- 设置集群内网访问,OSD 复制、恢复、回填数据使用;小规模环境可与公网相同
1
| ceph config set global cluster_network $CEPH_CLUSTER_NETWORK
|
1
| ceph orch daemon reconfig mon.*
|
1
| ceph config set mgr mgr/dashboard/ssl false
|
1
| ceph config set mgr mgr/dashboard/server_port $CEPH_DASHBOARD_PORT
|
1
2
| ceph mgr module disable dashboard
ceph mgr module enable dashboard
|
- 查看 Dashboard 访问地址和 admin 用户
1
2
| ceph dashboard get-url
ceph dashboard ac-user-show admin
|
查看与回滚配置:
1
2
3
| ceph config dump
ceph config get mon public_network
ceph config rm global some_key # 删除误设项
|
5. 池与 OSD 管理
5.1 存储池
1
2
3
4
5
| ceph osd pool ls detail
ceph osd pool create <pool> 32 32
ceph osd pool application enable <pool> rbd # 或 rgw / cephfs
ceph osd pool set <pool> size 3 # 副本数
ceph osd pool set <pool> min_size 2 # 最小可写副本
|
删除池(需加保护标志,操作不可逆):
1
| ceph osd pool rm <pool> <pool> --yes-i-really-really-mean-it
|
5.2 扩容 OSD
新节点准备裸盘后:
1
2
3
4
| ceph orch host add <hostname> <ip>
ceph orch daemon add osd <hostname>:/dev/nvme0n1
# 或自动发现
ceph orch apply osd --all-available-devices
|
5.3 下线 OSD
1
2
3
4
5
| ceph osd out <osd-id> # 标记 out,数据迁移走
watch -n 5 ceph -s # 等待 PG 恢复完成
ceph osd crush remove osd.<id>
ceph auth del osd.<id>
ceph osd rm <osd-id>
|
5.4 OSD 维护模式
更换磁盘或宿主机维护前:
1
2
3
| ceph osd ok-out <osd-id> # 优雅迁出
# 维护完成后
ceph osd in <osd-id>
|
6. 守护进程与节点纳管
1
2
3
4
5
6
| ceph orch host ls
ceph orch ps
ceph orch device ls # 可用块设备
ceph orch daemon restart osd.0
ceph orch daemon reconfig mon.*
ceph orch daemon status <daemon-name>
|
从集群移除节点(需先迁空其上 OSD):
1
2
| ceph orch host drain <hostname>
ceph orch host rm <hostname>
|
查看编排事件(部署失败时):
1
2
| ceph orch ls
ceph -W cephadm # 实时 watch cephadm 事件
|
7. RGW 对象网关
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| export RGW_SERVICE=rgw
export RGW_HTTP_PORT=7480
# 多节点:2 实例高可用
ceph orch apply rgw $RGW_SERVICE \
--placement="2 $CEPH_NODE1_HOST $CEPH_NODE2_HOST" \
--port=$RGW_HTTP_PORT
# 单节点
ceph orch apply rgw $RGW_SERVICE \
--placement="1 $(hostname)" \
--port=$RGW_HTTP_PORT
ceph orch ps --service-type=rgw
|
用户与桶管理:
1
2
3
| radosgw-admin user list
radosgw-admin user info --uid=<uid>
radosgw-admin user rm --uid=<uid>
|
8. 指标监控
Ceph MGR 内置 Prometheus exporter(:9283),在 Prometheus 中增加 scrape job 即可。
8.1 启用 MGR Prometheus 模块
1
2
| ceph mgr module enable prometheus
ceph mgr services | grep prometheus
|
8.2 Prometheus job 配置
在 prometheus.yml 的 scrape_configs 下追加:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| - job_name: ceph-mgr
metrics_path: /metrics
static_configs:
- targets:
- 10.0.0.11:9283
- 10.0.0.12:9283
labels:
cluster: ceph_cluster_3n
component: mgr
- job_name: node-exporter
static_configs:
- targets:
- 10.0.0.11:9100
- 10.0.0.12:9100
- 10.0.0.13:9100
labels:
cluster: ceph_cluster_3n
|
单节点时 targets 只保留本机 IP。修改后 reload Prometheus 配置:
1
2
| curl -X POST http://<prometheus-ip>:9090/-/reload # 需启用 --web.enable-lifecycle
# 或重启 Prometheus 进程 / 容器
|
验证:
1
| curl -s http://$CEPH_NODE1_IP:9283/metrics | grep ceph_cluster_total_bytes
|
在 Prometheus UI 的 Status → Targets 中确认 ceph-mgr、node-exporter 为 UP。
8.3 关注指标
| 指标 | 含义 |
|---|
ceph_cluster_total_bytes | 集群总容量 |
ceph_cluster_total_used_bytes | 已用容量 |
ceph_osd_up | OSD 是否在线(1=正常) |
ceph_osd_in | OSD 是否在 CRUSH 树内 |
ceph_pg_active | 活跃 PG 数量 |
ceph_health_status | 集群健康(0=OK) |
8.4 导入 Grafana 面板
Grafana Dashboards → Import,推荐面板:
9. 对接 Grafana / Dashboard
9.1 Ceph Dashboard
1
2
| ceph dashboard get-url
ceph dashboard ac-user-show admin
|
9.2 外部 Grafana 数据源
| 数据源 | URL |
|---|
| MGR Prometheus | http://<active-mgr-ip>:9283/ |
| cephadm Prometheus | http://<prometheus-ip>:9095/(若未 skip monitoring stack) |
| Prometheus | http://<prometheus-ip>:9090/ |
10. 升级与卸载
10.1 切换镜像版本
1
2
3
| ceph orch upgrade ls # 查看可用版本
ceph orch upgrade start --image quay.io/ceph/ceph:v20.2.2
ceph orch upgrade status
|
10.2 卸载集群
仅在测试环境执行,会删除全部数据:
1
2
3
4
5
| ceph orch rm --force rgw
ceph orch rm --force mds
ceph osd purge <id> --yes-i-really-mean-it
# 全部 OSD 清理完毕后
cephadm rm-cluster --fsid $(ceph fsid) --force
|
11. 常见问题
- Docker 的 Seccomp 限制导致 pthread_create 报错
1
2
3
| docker run --rm --ipc=host --net=host \
--entrypoint /usr/bin/ceph-authtool \
$CEPH_IMAGE --gen-print-key
|
会报错
1
2
| /usr/bin/ceph-authtool: stderr Thread::try_create(): pthread_create failed with error 1/ceph/rpmbuild/BUILD/ceph-20.2.2/src/common/Thread.cc: In function 'void Thread::create(const char*, size_t)' thread 7f2c842500c0 time 2026-07-12T01:12:23.852165+0000
/usr/bin/ceph-authtool: stderr /ceph/rpmbuild/BUILD/ceph-20.2.2/src/common/Thread.cc: 165: FAILED ceph_assert(ret == 0)
|
禁用 Seccomp
1
2
3
4
| docker run --rm --ipc=host --net=host \
--security-opt seccomp=unconfined \
--entrypoint /usr/bin/ceph-authtool \
$CEPH_IMAGE --gen-print-key
|
持久修复:编辑 /usr/sbin/cephadm,在
1
2
| if self.host_network:
cmd_args.append('--net=host')
|
后追加
1
| cmd_args.extend(['--security-opt', 'seccomp=unconfined'])
|
bootstrap 报 Cannot assign requested address:--mon-ip 必须是当前主机的对外 IP,不能在别的节点上执行 bootstrap。
unrecognized arguments: --single-host-defaults:cephadm 20.2.2 已移除该参数,单节点通过 single-node.conf 设置副本数为 1。
容器内 pthread_create failed exit 139:Ascend 等环境的 Docker seccomp 限制,见上文;也可尝试 Podman 或降级至 v19.2.4。
Command 'ceph' not found:安装 ceph-common,或在管理节点使用 cephadm shell -- ceph ...。
HEALTH_WARN 且 OSD_DOWN:检查对应节点 Docker/Podman 与磁盘,ceph orch daemon restart osd.<id>。
PG 长期处于 degraded / recovering:等待回填完成;若卡死查 ceph pg dump_stuck。
12. 参考