Please enable Javascript to view the contents

Ceph 架构与运维

 ·  ☕ 7 分钟

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 22bootstrap 节点安装;各节点需 Docker 或 Podman
MON集群地图、仲裁、客户端入口3300 / 6789奇数个;生产通常 3 个(5 节点也够用),分散到不同节点
MGR管理 API、Dashboard、指标模块8080 / 9283通常 2 个(active + standby)
OSD存储数据、复制、恢复6800-7300仅有块设备的节点需要;3 副本至少 3 块 OSD
RBD块存储镜像客户端连 MON/OSD无独立守护进程,创建池与镜像即可
RGWS3 / Swift 对象网关7480可选,按需多实例
MDSCephFS 元数据服务6800-7300部署 CephFS 时需要

1.3 网络端口

集群节点间需互通以下端口:

端口组件用途
3300monMonitor v2
6789monMonitor v1(兼容)
6800–7300osd / mdsOSD 心跳、复制与恢复
9283mgrPrometheus /metrics
8080dashboardCeph Dashboard(HTTP)
7480rgwS3 / Swift 对象网关
9100node-exp主机指标(监控栈)

1.4 五节点规划示例

3 MON 分布在 node1–3,5 台均跑 OSD;MON 不必每台都有。

节点主机名IP角色
node1ceph-node-0110.0.0.11MON + MGR(active)+ OSD(bootstrap)
node2ceph-node-0210.0.0.12MON + MGR(standby)+ OSD
node3ceph-node-0310.0.0.13MON + OSD
node4ceph-node-0410.0.0.14OSD
node5ceph-node-0510.0.0.15OSD

1.5 版本时间线

版本号开发代号首版发布日期当前状态推荐操作系统
v17Quincy2022 年 4 月维护状态(即将 EOL)RHEL/EL 8、9;Ubuntu 22.04
v18Reef2023 年 8 月长期支持(LTS)RHEL/EL 8、9;Ubuntu 22.04
v19Squid2024 年 7 月当前主推稳定版RHEL/EL 9;Ubuntu 24.04
v20Tentacle2025 年开发中 / 预览阶段RHEL/EL 9;Ubuntu 24.04
v21U 字头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)

  • 创建 S3 用户
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"
  • 上传验证(需安装 awscli
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)

  • 创建文件系统并部署 MDS
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

关注项:

检查项正常状态异常处理方向
healthHEALTH_OKceph health detail 查看 WARN/ERR 原因
OSD全部 upin检查磁盘、容器、ceph orch daemon restart osd.<id>
PGactive+clean等待恢复;长期异常查 ceph pg stat
MGR1 个 active、其余 standbyceph 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
  • 重新加载 MON 配置
1
ceph orch daemon reconfig mon.*
  • 关闭 Dashboard HTTPS
1
ceph config set mgr mgr/dashboard/ssl false
  • 设置 Dashboard HTTP 端口
1
ceph config set mgr mgr/dashboard/server_port $CEPH_DASHBOARD_PORT
  • 重启 Dashboard 模块,使配置生效
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.ymlscrape_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-mgrnode-exporter 为 UP。

8.3 关注指标

指标含义
ceph_cluster_total_bytes集群总容量
ceph_cluster_total_used_bytes已用容量
ceph_osd_upOSD 是否在线(1=正常)
ceph_osd_inOSD 是否在 CRUSH 树内
ceph_pg_active活跃 PG 数量
ceph_health_status集群健康(0=OK)

8.4 导入 Grafana 面板

Grafana Dashboards → Import,推荐面板:

面板ID说明
Ceph Cluster2842集群容量、OSD、PG、性能
Ceph - RadosGW5336RGW 请求与带宽(部署 RGW 后)

9. 对接 Grafana / Dashboard

9.1 Ceph Dashboard

1
2
ceph dashboard get-url
ceph dashboard ac-user-show admin

9.2 外部 Grafana 数据源

数据源URL
MGR Prometheushttp://<active-mgr-ip>:9283/
cephadm Prometheushttp://<prometheus-ip>:9095/(若未 skip monitoring stack)
Prometheushttp://<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_WARNOSD_DOWN:检查对应节点 Docker/Podman 与磁盘,ceph orch daemon restart osd.<id>

  • PG 长期处于 degraded / recovering:等待回填完成;若卡死查 ceph pg dump_stuck

12. 参考


微信公众号
作者
微信公众号