在 Raspberry Pi 4 集群中安装 Ceph

2022年2月24日 Mike Perez (thingee)

Cephadm 在 Octopus 版本中推出,用于部署和管理 Ceph 集群的完整生命周期。

它通过 SSH 在主机上添加或删除 Ceph 守护进程的容器。由于 Cephadm 是在 Octopus 中推出的,因此某些功能可能仍在开发中。

Ceph Dashboard 是一个基于 Web 的管理和监控应用程序,用于管理 Ceph 集群中的各种事务。

在本教程中,我们将

  • 使用 Cephadm 启动一个由 Raspberry Pi 组成的 Ceph 集群。
  • 使用 Ceph Dashboard 完成安装
    • 添加其他主机
    • 添加对象存储守护进程 (OSD)
  • 验证具有可用存储容量的正常集群

硬件清单

  • 4 个 Raspberry PI 4B 4GB 型号
  • 4 个 64GB microSD 卡
  • 8 个 USB 闪存盘
  • 4 个 PoE 帽子
  • 4 个以太网线
  • 一个网络交换机
  • 带有风扇的 Raspberry PI 外壳

镜像

我将使用 Fedora server ARM 镜像,并且在我撰写本文时,它包含最新的 Pacific 版本

为了使此设置更容易,我使用了 arm-image-installer,它会在将镜像写入 SD 卡时注入 SSH 密钥。

$ dnf install arm-image-installer

$ arm-image-installer --image Downloads/Fedora-Server-35-1.2.aarch64.raw.xz --addkey desktop.pub  --resizefs --target rpi4 --media /dev/sda

 ***********************************************************
 ** WARNING: You have requested the image be written to sda.
 ** /dev/sda is usually the root filesystem of the host.
 ***********************************************************
 ** Do you wish to continue? (type 'yes' to continue)
 ***********************************************************
 = Continue? yes

...

= Raspberry Pi 4 Uboot is already in place, no changes needed.
= Adding SSH key to authorized keys.

= Installation Complete! Insert into the rpi4 and boot

初始设置

在对每个 SD 卡进行镜像处理并启动 PI 后,我们需要进行一些初始设置才能使 Cephadm 正常工作。

在每个主机上,我们将

  • 更新软件包
  • 设置主机名
$ dnf update

$ hostnamectl set-hostname <hostname>

$ echo '<host-ip> <hostname>' >> /etc/hosts

在您选择作为管理器的 PI 上安装 Cephadm。

$ dnf install cephadm

启动新集群

启动集群就像一个命令一样简单。我将 mon-ip 设置为管理器主机。

# cephadm bootstrap --mon-ip 192.168.7.122
Creating directory /etc/ceph for ceph.conf
Verifying podman|docker is present...
Verifying lvm2 is present...
Verifying time synchronization is in place...

...

Adding key to root@host1 authorized_keys...
Adding host host1...
Deploying mon service with default placement...
Deploying mgr service with default placement...
Deploying crash 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 9...
mgr epoch 9 is available
Generating a dashboard self-signed certificate...
Creating initial admin user...
Fetching dashboard port number...
firewalld ready
Enabling firewalld port 8443/tcp in current zone...
Ceph Dashboard is now available at:

             URL: https://host1:8443/
            User: admin
        Password: ck4qri2zye

Enabling client.admin keyring and conf on hosts with "admin" label
You can access the Ceph CLI with:

        sudo /usr/sbin/cephadm shell --fsid bc2e207c-8ded-11ec-8986-dca6327c3ae4 -c /etc/ceph/ceph.conf -k /etc/ceph/ceph.client.admin.keyring

Please consider enabling telemetry to help improve Ceph:

        ceph telemetry on

For more information see:

        https://docs.ceph.net.cn/docs/pacific/mgr/telemetry/

Bootstrap complete.

使用生成的 Ceph 公钥,我们可以将其复制到每个主机,以便 cephadm 和 Ceph 模块可以与其他主机通信。

$ ssh-copy-id -f -i /etc/ceph/ceph.pub root@192.168.7.123
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/ceph.pub"

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.7.123'"
and check to make sure that only the key(s) you wanted were added.

使用仪表板扩展集群

现在启动完成,我们有一个主机正在运行管理器、监控器、仪表板模块。

我们还有需要配置的其他 Pi。您可以完成使用 Cephadm 扩展集群,但为了好玩,让我们看看如何使用仪表板来完成此操作。

登录

启动命令的输出为我们提供了仪表板的地址和登录信息。首次登录时,系统会提示我们更改密码。

登录后,仪表板检测到我们还没有做太多事情。让我们构建更多主机来扩展集群。

演练向导

仪表板提供了一个演练向导,以分步扩展我们的集群。

添加其他主机

对于每个 PI,输入其主机名和 IP 地址。此处输入的主机名 必须 与主机上的主机名完全匹配。

添加对象存储守护进程 (OSD)

在第二步中,我们必须添加 OSD。Ceph 中的大部分数据都存储在此处。每个 OSD 都由存储设备(例如 HDD 或 SSD)提供支持。在我们的例子中,它是我们连接的 USB 闪存盘。

一旦 PI 被注册为主机,将显示可由 OSD 提供支持的可用存储设备。仪表板使使用所有可用设备变得容易。

一旦所有 OSD 启动,仪表板将向我们显示它们的活动情况。

检查集群健康状况

现在,我们将跳过向导的第三步以添加其他服务。最终,我们拥有一个在 Raspberry Pi 上运行的正常 Ceph 集群。

还可以通过 Ceph CLI 检查健康状态。

$ cephadm shell
Inferring fsid ab8f0a02-8f59-11ec-807d-dca6327c3ae4
Using recent ceph image quay.io/ceph/ceph@sha256:da66bfcc6259123f9f5d4a55f43d46c55d93a9b8ddd636250de82cd50ee22243
[ceph: root@host1 /]# ceph status
  cluster:
    id:     ab8f0a02-8f59-11ec-807d-dca6327c3ae4
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum main,host1,host3 (age 46s)
    mgr: main.vpowaz(active, since 14s), standbys: host3.wexybt
    osd: 8 osds: 8 up (since 30s), 8 in (since 24h)

  data:
    pools:   5 pools, 105 pgs
    objects: 192 objects, 5.3 KiB
    usage:   67 MiB used, 954 GiB / 954 GiB avail
    pgs:     105 active+clean

  io:
    client:   1.5 KiB/s wr, 0 op/s rd, 0 op/s wr

结论

在本系列博客的下一篇文章中,我们将探索功能丰富的 Ceph 块设备,以创建 RADOS 块设备 (RBD) 镜像,可以从客户端挂载和读/写。