Ceph搭建

简介: ceph

Ceph搭建

一、系统环境初始化

时间同步

关闭selinux和防火墙(Centos)

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

所有节点安装podman

apt install -y podman lvm2
主机名 ip
ceph1 192.168.11.10 \ 192.168.75.10
ceph2 192.168.11.11 \ 192.168.75.11
ceph3 192.168.11.12 \ 192.168.75.12
root@ceph3:~# cat /etc/hosts
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.11.10 ceph1
192.168.11.11 ceph2
192.168.11.12 ceph3

配置时间同步 使用自带的timedate

timedatectl set-timezone Asia/Shanghai

二、部署RADOS集群

https://mirrors.aliyun.com/ceph/
https://mirrors.163.com/ceph/
https://mirrors.tuna.tsinghua.edu.cn/ceph/

2.1仓库准备

各节点配置ceph 仓库

aliyun默认带了ceph

root@ceph3:~# apt-cache madison ceph
      ceph | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-updates/main amd64 Packages
      ceph | 19.2.3-0ubuntu0.24.04.3 | http://mirrors.aliyun.com/ubuntu noble-security/main amd64 Packages
      ceph | 19.2.0~git20240301.4c76c50-0ubuntu6 | http://mirrors.aliyun.com/ubuntu noble/main amd64 Packages
root@ceph3:~#

2. 2安装 Cephadm(仅在主节点 ceph1

apt update
apt install -y podman lvm2
apt install -y cephadm

初始化主节点

root@ceph1:~# cephadm bootstrap --mon-ip 192.168.11.10
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...
podman (/usr/bin/podman) version 4.9.3 is present
systemctl is present
lvcreate is present
Unit systemd-timesyncd.service is enabled and running
Host looks OK
Cluster fsid: 24f2c24c-75e6-11f1-b8f1-000c291acd7f
Verifying IP 192.168.11.10 port 3300 ...
Verifying IP 192.168.11.10 port 6789 ...
Mon IP `192.168.11.10` is in CIDR network `192.168.11.0/24`
Mon IP `192.168.11.10` is in CIDR network `192.168.11.0/24`
Internal network (--cluster-network) has not been provided, OSD replication will default to the public_network
Pulling container image quay.io/ceph/ceph:v19...
Ceph version: ceph version 19.2.4 (7cc0193a616a3333d22b7762037fa5b73a4d06a6) squid (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 192.168.11.0/24 in mon config section
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 not available, waiting (3/15)...
mgr is available
Enabling cephadm module...
Waiting for the mgr to restart...
Waiting for mgr epoch 5...
mgr epoch 5 is available
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 ceph1...
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 9...
mgr epoch 9 is available
Generating a dashboard self-signed certificate...
Creating initial admin user...
Fetching dashboard port number...
Ceph Dashboard is now available at:

             URL: https://ceph1:8443/
            User: admin
        Password: 5vcur62785

Enabling client.admin keyring and conf on hosts with "admin" label
Saving cluster configuration to /var/lib/ceph/24f2c24c-75e6-11f1-b8f1-000c291acd7f/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 24f2c24c-75e6-11f1-b8f1-000c291acd7f -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.

此命令将

  • 在本地主机上为新集群创建一个 Monitor 和一个 Manager 守护程序。
  • 为 Ceph 集群生成一个新的 SSH 密钥,并将其添加到 root 用户的 /root/.ssh/authorized_keys 文件中。
  • 将公钥副本写入 /etc/ceph/ceph.pub
  • 将最小配置文件写入 /etc/ceph/ceph.conf。此文件是与 Ceph 守护程序通信所必需的。
  • client.admin 管理(特权!)密钥副本写入 /etc/ceph/ceph.client.admin.keyring
  • _admin 标签添加到引导主机。默认情况下,任何具有此标签的主机都将(也)获得 /etc/ceph/ceph.conf/etc/ceph/ceph.client.admin.keyring 的副本。

免密失败了 /etc/ceph/ceph.pub

ssh-keygen

重新初始化

root@ceph1:~# cephadm bootstrap \
  --mon-ip 192.168.11.10 \
  --ssh-private-key /root/.ssh/id_ed25519 \
  --ssh-public-key /root/.ssh/id_ed25519.pub \
  --allow-overwrite
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...
podman (/usr/bin/podman) version 4.9.3 is present
systemctl is present
lvcreate is present
Unit systemd-timesyncd.service is enabled and running
Host looks OK
Cluster fsid: 10b97a6a-75ef-11f1-8612-000c291acd7f
Verifying IP 192.168.11.10 port 3300 ...
Verifying IP 192.168.11.10 port 6789 ...
Mon IP `192.168.11.10` is in CIDR network `192.168.11.0/24`
Mon IP `192.168.11.10` is in CIDR network `192.168.11.0/24`
Internal network (--cluster-network) has not been provided, OSD replication will default to the public_network
Pulling container image quay.io/ceph/ceph:v19...
Ceph version: ceph version 19.2.4 (7cc0193a616a3333d22b7762037fa5b73a4d06a6) squid (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 192.168.11.0/24 in mon config section
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 not available, waiting (3/15)...
mgr is available
Enabling cephadm module...
Waiting for the mgr to restart...
Waiting for mgr epoch 5...
mgr epoch 5 is available
Setting orchestrator backend to cephadm...
Using provided ssh keys...
Adding key to root@localhost authorized_keys...
Adding host ceph1...
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 9...
mgr epoch 9 is available
Generating a dashboard self-signed certificate...
Creating initial admin user...
Fetching dashboard port number...
Ceph Dashboard is now available at:

             URL: https://ceph1:8443/
            User: admin
        Password: tvhp9krki9

Enabling client.admin keyring and conf on hosts with "admin" label
Saving cluster configuration to /var/lib/ceph/10b97a6a-75ef-11f1-8612-000c291acd7f/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 10b97a6a-75ef-11f1-8612-000c291acd7f -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.

2.3 安装 Ceph 命令行工具

为了方便直接在终端输入 ceph 命令,在 ceph1 上安装客户端:

root@ceph1:~# apt install -y ceph-common

三、编排三节点集群

3.1 允许主节点免密登录其他节点

Cephadm 需要通过 SSH 管理 ceph2ceph3

3.2 将主机加入集群

node1 上执行命令,把其他两个 Ubuntu 节点拉进集群:

Bash

root@ceph1:~# ceph orch host add ceph2 192.168.11.11
Added host 'ceph2' with addr '192.168.11.11'
root@ceph1:~# ceph orch host add ceph3 192.168.11.12
Added host 'ceph3' with addr '192.168.11.12'

验证节点状态:ceph orch host ls

root@ceph1:~# ceph orch host ls
HOST   ADDR           LABELS  STATUS
ceph1  192.168.11.10  _admin
ceph2  192.168.11.11
ceph3  192.168.11.12
3 hosts in cluster

4. 部署高可用组件(Mon & Mgr)

为了让 3 个节点对等且具备高可用性,将 Monitor 和 Manager 拓扑应用到所有节点:

# 让 3 个节点都运行 mon
root@ceph1:~# ceph orch apply mon --placement="3 ceph1 ceph2 ceph3"
Scheduled mon update...

# 让 3 个节点都运行 mgr
root@ceph1:~# ceph orch apply mgr --placement="3 ceph1 ceph2 ceph3"
Scheduled mgr update...

5. 添加 OSD(存储裸盘)

确保你准备用于存储数据的硬盘没有分区表,没有被挂载过

5.1 检查可用硬盘

root@ceph1:~# ceph orch device ls
HOST   PATH      TYPE  DEVICE ID                                             SIZE  AVAILABLE  REFRESHED  REJECT REASONS
ceph1  /dev/sdb  hdd                                                        40.0G  Yes        15m ago
ceph1  /dev/sr0  hdd   VMware_Virtual_SATA_CDRW_Drive_01000000000000000001  1023M  No         15m ago    Failed to determine if device is BlueStore, Insufficient space (<5GB)
ceph2  /dev/sdb  hdd                                                        40.0G  Yes        4m ago
ceph2  /dev/sr0  hdd   VMware_Virtual_SATA_CDRW_Drive_01000000000000000001  1023M  No         4m ago     Failed to determine if device is BlueStore, Insufficient space (<5GB)
ceph3  /dev/sdb  hdd                                                        40.0G  Yes        5s ago
ceph3  /dev/sr0  hdd   VMware_Virtual_SATA_CDRW_Drive_01000000000000000001  1023M  No         5s ago     Failed to determine if device is BlueStore, Insufficient space (<5GB)
root@ceph1:~#

如果看到各节点的硬盘(如 /dev/sdb)状态为 Available: Insufficient space (0B)False,说明盘不干净,需要用 wipefs -a /dev/sdb 清理。

5.2 自动挂载所有可用裸盘

ceph orch apply osd --all-available-devices

6. 完工检查

node1 上输入:

root@ceph1:~# ceph -s
  cluster:
    id:     10b97a6a-75ef-11f1-8612-000c291acd7f
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum ceph1,ceph3,ceph2 (age 7m)
    mgr: ceph1.uwzqip(active, since 25m), standbys: ceph3.ftoasw, ceph2.wevbmh
    osd: 3 osds: 3 up (since 5m), 3 in (since 5m)

  data:
    pools:   1 pools, 1 pgs
    objects: 2 objects, 449 KiB
    usage:   81 MiB used, 120 GiB / 120 GiB avail
    pgs:     1 active+clean

只要看到 health: HEALTH_OK,且 monmgr 的数量都显示为 3,三节点 Ceph 集群就已经搭建成功了!

image-20260702165445177

相关文章
|
23天前
|
Kubernetes 并行计算 算法框架/工具
|
24天前
|
存储 开发框架 人工智能
阿里云刚发布的 AgentLoop 是什么?
AgentLoop 帮助企业把 Agent 从能用提升到好用。
|
23天前
|
存储 文字识别 安全
2026阿里云最新云产品活动信息汇总:优惠券、特价、扶持政策一览
本文汇总了2026年阿里云全品类最新优惠活动,覆盖新用户专属折扣券、学生300元无门槛券、中小企业最高百万扶持金等福利,同时整理了云安全、云通信、无影云桌面、云原生、数据库、OCR识别等十余条细分产品线的特惠专场,从建站、AI开发到企业数字化转型的各类上云需求都能找到适配的高性价比方案,还补充了优惠券使用规则的常见问题解答,帮助不同类型的用户精准匹配优惠权益,最大化降低上云成本。
|
23天前
|
存储 Kubernetes 调度
|
23天前
|
运维 供应链 安全
面料批发提质增效:API接口落地,解决布行运营人工痛点实战
本方案通过合规API接口,实现面料采购、库存、物流全流程自动化:订单实时同步、智能核验、自动备货;库存价格动态预警;面单自动生成、物流自动回填;打通线上线下数据壁垒,规避人工失误与平台风控。轻量部署,零代码门槛,助力传统布行降本增效、稳健拓客。
95 3
|
23天前
|
存储 Prometheus Kubernetes
Kubeasz 部署 K8s 生产方案
Kubeasz 部署 K8s 生产方案
|
23天前
|
存储 缓存 Linux
KubeVirt 镜像制作
KubeVirt 镜像制作
|
23天前
|
人工智能 JSON 监控
GEO技术原理与实践:从结构化数据到AI引用率的工程化方案
本文深度解析GEO(生成式引擎优化)技术原理与落地实践,涵盖结构化数据标记(FAQ/HowTo/Article Schema)、语义相关性优化(向量检索、同义覆盖、三层内容结构)、可信度工程(E-E-A-T评分、Author/Citation Schema)及效果监测体系,助力内容被AI搜索高频引用。(239字)
|
23天前
|
Shell 开发工具
|
2月前
|
Kubernetes Ubuntu 网络协议