Ubuntu 22.04安装Ceph单机版(reef)

小柒博客 评论13字数 2629阅读8分45秒阅读模式

一、Ceph概述

Ceph是一种高性能、高可靠性的分布式存储系统,由Sage Weil于2004年开发,旨在解决大规模数据存储的扩展性、可靠性和性能问题。随着OpenStack日渐成为开源云计算的标准软件栈,Ceph也已经成为OpenStack的首选后端存储。

1)Ceph支持

对象存储:即radosgw,兼容S3接口。通过rest api上传、下载文件。

文件系统:posix接口。可以将Ceph集群看做一个共享文件系统挂载到本地。

块存储:即rbd。有kernel rbd和librbd两种使用方式。支持快照、克隆。相当于一块硬盘挂到本地,用法和用途和硬盘一样。比如在OpenStack项目里,Ceph的块设备存储可以对接OpenStack的后端存储。

2)Ceph相比其它分布式存储有哪些优点?

统一存储:虽然Ceph底层是一个分布式文件系统,但由于在上层开发了支持对象和块的接口。所以在开源存储软件中,能够一统江湖。

高扩展性:扩容方便、容量大。能够管理上千台服务器、EB级的容量。

可靠性强:支持多份强一致性副本,EC。副本能够垮主机、机架、机房、数据中心存放。所以安全可靠。存储节点可以自管理、自动修复。无单点故障,容错性强。

高性能:因为是多个副本,因此在读写操作时候能够做到高度并行化。理论上,节点越多,整个集群的IOPS和吞吐量越高。另外一点Ceph客户端读写数据直接与存储设备(osd)交互。

3)Ceph各组件介绍

Ceph OSD: Ceph OSD守护进程(Ceph OSD)的功能是存储数据,处理数据的复制、恢复、回填、再均衡,并通过检查其他OSD守护进程的心跳来向Ceph Monitors提供一些监控信息。

Monitors: Ceph Monitor维护着展示集群状态的各种图表,包括监视器图、OSD 图、归置组(PG )图和CRUSH图。 Ceph保存着发生在Monitors、OSD和PG上的每一次状态变更的历史信息(称为epoch)。

MDS: Ceph元数据服务器(MDS)为Ceph文件系统存储元数据(也就是说,Ceph 块设备和Ceph对象存储不使用MDS)。元数据服务器使得POSIX文件系统的用户们,可以在不对Ceph存储集群造成负担的前提下,执行诸如ls、find等基本命令。

二、Ceph集群部署

1、系统环境

操作系统

IP地址

CPU/内存/磁盘

主机名

主机角色

Ubuntu 22.04.5

192.168.10.220

4C、8G、200G、1TB

ceph

mon、mgr、mds、osd

Ubuntu 22.04.5

192.168.10.221

2C、4G、200G

ceph-client

Ceph客户端

2、基础配置

1)配置hosts、主机名

root@localhost:~# hostnamectl set-hostname ceph

root@localhost:~# hostnamectl set-hostname ceph-client

root@ceph:~# cat >>/etc/hosts <<EOF

192.168.10.220 ceph

192.168.10.221 ceph-client

EOF

2)配置SSH免密钥

root@ceph:~# ssh-keygen

root@ceph:~# ssh-copy-id root@ceph

root@ceph:~# ssh-copy-id root@ceph-client

Ubuntu 22.04安装Ceph单机版(reef)-图片1

3)配置时间同步

root@ceph:~# apt -y update

root@ceph:~# apt -y install chrony

root@ceph:~# systemctl restart chronyd

root@ceph:~# systemctl enable chrony

root@ceph:~# chronyc sources -v

Ubuntu 22.04安装Ceph单机版(reef)-图片2

Ubuntu 22.04安装Ceph单机版(reef)-图片3

4)安装Docker

root@ceph:~# apt -y install docker docker.io

Ubuntu 22.04安装Ceph单机版(reef)-图片4

Ubuntu 22.04安装Ceph单机版(reef)-图片5

# 重启Docker并配置开机自启动

root@ceph:~# systemctl restart docker

root@ceph:~# systemctl enable docker

3、安装Ceph

# Ceph官方的仓库:https://download.ceph.com/

1)配置官方Ceph源

root@ceph:~# curl -fSsL https://download.ceph.com/keys/release.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/ceph.gpg

root@ceph:~# echo "deb https://download.ceph.com/debian-reef $(lsb_release -sc) main" >/etc/apt/sources.list.d/ceph.list

2)安装cephadm工具(ceph节点)

root@ceph:~# apt -y update

root@ceph:~# apt -y install cephadm

Ubuntu 22.04安装Ceph单机版(reef)-图片6

3)初始化Mon节点

root@ceph:~# cephadm bootstrap --mon-ip 192.168.10.220

Ubuntu 22.04安装Ceph单机版(reef)-图片7

Ubuntu 22.04安装Ceph单机版(reef)-图片8

4)查看镜像和容器

root@ceph:~# docker images

root@ceph:~# docker ps -a

Ubuntu 22.04安装Ceph单机版(reef)-图片9

5)Shell命令

# 切换模式

root@ceph:~# cephadm shell

# 查看Ceph集群状态

root@ceph:/# ceph -s

# 查看集群内运行组件(包括其他节点)

root@ceph:/# ceph orch ps

# 查看集群内某个组件运行状态

root@ceph:/# ceph orch ps --daemon-type mon

Ubuntu 22.04安装Ceph单机版(reef)-图片10

# 第二种运行方式

root@ceph:~# cephadm shell -- ceph -s

Ubuntu 22.04安装Ceph单机版(reef)-图片11

6)安装ceph-common

root@ceph:~# cephadm install ceph-common

或者

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

Ubuntu 22.04安装Ceph单机版(reef)-图片12

Ubuntu 22.04安装Ceph单机版(reef)-图片13

# 查看Ceph版本

root@ceph:~# ceph -v

ceph version 18.2.7 (6b0e988052ec84cf2d4a54ff9bbbc5e720b621ad) reef (stable)

7)配置MGR和Mon

# 查看集群节点

root@ceph:~# ceph orch host ls

# Ceph集群默认会允许存在5个mon和2个mgr,可以使用ceph orch apply手动修改

root@ceph:~# ceph orch ls

root@ceph:~# ceph orch apply mon --placement="1 ceph"

Scheduled mon update...

root@ceph:~# ceph orch apply mgr --placement="1 ceph"

Scheduled mgr update...

# 列出集群中所有服务状态

root@ceph:~# ceph orch ls

Ubuntu 22.04安装Ceph单机版(reef)-图片14

8)创建OSD

# 列出集群内的存储设备

root@ceph:~# ceph orch device ls

# 创建OSD

root@ceph:~# ceph orch daemon add osd ceph:/dev/sdb

root@ceph:~# cephadm shell -- ceph -s

Ubuntu 22.04安装Ceph单机版(reef)-图片15

# 提示OSD count 1 < osd_pool_default_size 3(当前只有1个OSD小于默认副本数3个)

# 修改OSD副本数

root@ceph:~# ceph config set global osd_pool_default_size 1

root@ceph:~# cephadm shell -- ceph -s

Ubuntu 22.04安装Ceph单机版(reef)-图片16

4、Ceph文件存储

1)创建MDS

# 创建存储池(集群中单个池的PG数计算公式如下:PG总数=(OSD数*100)/最大副本数/池数)

root@ceph:~# ceph osd pool create cephfs-data 64

root@ceph:~# ceph osd pool create cephfs-metadata 64

root@ceph:~# ceph osd pool ls

Ubuntu 22.04安装Ceph单机版(reef)-图片17

2)创建文件系统

root@ceph:~# ceph fs new cephfs cephfs-metadata cephfs-data

# 出现Pool 'cephfs-data' (id '2') has pg autoscale mode 'on' but is not marked as bulk(此消息表明您的cepfs数据池启用了PG自动伸缩,但未将其标记为"批量"池)

# 将存储池标记为Bulk(如果存储大数据,建议使用)

root@ceph:~# ceph osd pool set cephfs-data bulk true

root@ceph:~# ceph fs ls

root@ceph:~# ceph df

# 开启MDS组件(设置MDS副本数为1)

root@ceph:~# ceph orch apply mds cephfs --placement="1 ceph"

# 查看各节点是否已启用mds容器

root@ceph:~# ceph orch ps --daemon-type mds

Ubuntu 22.04安装Ceph单机版(reef)-图片18

3)创建RGW(可选)

# 创建领域

root@ceph:~# radosgw-admin realm create --rgw-realm=org --default

# 创建区域组

root@ceph:~# radosgw-admin zonegroup create --rgw-zonegroup=default --master --default

Ubuntu 22.04安装Ceph单机版(reef)-图片19

# 创建区域

root@ceph:~# radosgw-admin zone create --rgw-zonegroup=default --rgw-zone=cn-east-1 --master --default

Ubuntu 22.04安装Ceph单机版(reef)-图片20

# 特定领域和区域部署radosgw守护程序

root@ceph:~# ceph orch apply rgw org cn-east-1 --placement="1 ceph"

# 验证各节点是否启动rgw容器

root@ceph:~# ceph orch ps --daemon-type rgw

root@ceph:~# cephadm shell -- ceph -s

Ubuntu 22.04安装Ceph单机版(reef)-图片21

4)生成客户端访问存储池密钥

# clientfs

root@ceph:~# cd /etc/ceph

root@ceph:/etc/ceph# ceph auth get-or-create client.clientfs mon 'allow r' mds 'allow rw' osd 'allow * pool=cephfs-data,allow * pool=cephfs-metadata' -o ceph.client.clientfs.keyring

root@ceph:/etc/ceph# ceph auth get client.clientfs

root@ceph:/etc/ceph# ceph auth print-key client.clientfs >/etc/ceph/clientfs.key

# 客户端

root@ceph-client:~# mkdir -p /etc/ceph

root@ceph:/etc/ceph# scp /etc/ceph/ceph.client.clientfs.keyring /etc/ceph/ceph.conf /etc/ceph/clientfs.key root@ceph-client:/etc/ceph/

5)客户端挂载

# 客户端通过内核中的cephfs文件系统接口即可挂载使用cephfs文件系统或者通过FUSE接口与文件系统进行交互。

# 内核文件系统

root@ceph-client:~# apt -y install ceph-common ceph-fuse

Ubuntu 22.04安装Ceph单机版(reef)-图片22

Ubuntu 22.04安装Ceph单机版(reef)-图片23

root@ceph-client:~# mkdir -p /mnt/fs/

root@ceph-client:~# ls -l /etc/ceph/

root@ceph-client:~# cat /etc/hosts

root@ceph-client:~# mount.ceph ceph:6789:/ /mnt/fs/ -o name=clientfs,secretfile=/etc/ceph/clientfs.key

root@ceph-client:~# df -h

Ubuntu 22.04安装Ceph单机版(reef)-图片24

# 写入测试数据

root@ceph-client:~# echo 'hello fs' >/mnt/fs/index.html

root@ceph-client:~# cat /mnt/fs/index.html

# 配置开机自动挂载

root@ceph-client:~# echo "ceph:6789:/ /mnt/fs ceph name=clientfs,secretfile=/etc/ceph/clientfs.key,_netdev,noatime 0 0" >>/etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片25

# 用户空间文件系统(Fuse)

root@ceph-client:~# mkdir -p /mnt/fuse

root@ceph-client:~# ceph-fuse -n client.clientfs -m ceph:6789 /mnt/fuse

root@ceph-client:~# df -h

# 写入测试数据

root@ceph-client:~# echo 'hello fuse' >/mnt/fuse/index.html

root@ceph-client:~# cat /mnt/fuse/index.html

# 配置开机自动挂载

root@ceph-client:~# echo "none /mnt/fuse fuse.ceph ceph.id=clientfs,ceph.conf=/etc/ceph/ceph.conf,_netdev,defaults 0 0" >>/etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片26

5、Ceph块存储

1)创建块存储

root@ceph:/etc/ceph# ceph osd pool create rbd_pool 32

root@ceph:/etc/ceph# ceph osd pool ls

Ubuntu 22.04安装Ceph单机版(reef)-图片27

2)创建客户端账号

root@ceph:/etc/ceph# ceph auth get-or-create client.rbd mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=rbd_pool'

root@ceph:/etc/ceph# ceph auth get client.rbd

3)生成客户端keyring

root@ceph:/etc/ceph# ceph auth get client.rbd -o /etc/ceph/ceph.client.rbd.keyring

root@ceph:/etc/ceph# ls -l /etc/ceph/ceph.client.rbd.keyring

# 拷贝keyring到客户端

root@ceph:/etc/ceph# scp /etc/ceph/ceph.client.rbd.keyring root@ceph-client:/etc/ceph/

4)启动RBD

root@ceph:/etc/ceph# ceph osd pool application enable rbd_pool rbd_pool

Ubuntu 22.04安装Ceph单机版(reef)-图片28

5)客户端操作

# 查看Ceph集群状态

root@ceph-client:~# ceph -s --id rbd

Ubuntu 22.04安装Ceph单机版(reef)-图片29

# 创建image

root@ceph-client:~# rbd create rbd -p rbd_pool --size 1G --id rbd

root@ceph-client:~# rbd ls -l rbd_pool --id rbd

root@ceph-client:~# rbd info -p rbd_pool rbd --id rbd

Ubuntu 22.04安装Ceph单机版(reef)-图片30

# 禁用镜像特性(作为rbd一般只需要layering,需要把其他的特性全部禁止掉)

root@ceph-client:~# rbd feature disable -p rbd_pool rbd exclusive-lock, object-map, fast-diff, deep-flatten --id rbd

root@ceph-client:~# rbd info -p rbd_pool rbd --id rbd

Ubuntu 22.04安装Ceph单机版(reef)-图片31

# 挂载image

root@ceph-client:~# lsblk

root@ceph-client:~# rbd ls -l rbd_pool --id rbd

root@ceph-client:~# rbd map -p rbd_pool rbd --id rbd

root@ceph-client:~# lsblk

Ubuntu 22.04安装Ceph单机版(reef)-图片32

# 初始化文件系统及挂载

# 格式化磁盘

root@ceph-client:~# mkfs.xfs /dev/rbd0

# 创建挂载目录

root@ceph-client:~# mkdir -p /mnt/rbd

root@ceph-client:~# mount /dev/rbd0 /mnt/rbd/

root@ceph-client:~# df -h

Ubuntu 22.04安装Ceph单机版(reef)-图片33

# 写入测试数据

root@ceph-client:~# echo 'hello rbd' >/mnt/rbd/index.html

root@ceph-client:~# cat /mnt/rbd/index.html

# 配置开机自动挂载

root@ceph-client:~# echo "/dev/rbd0 /mnt/rbd xfs defaults,_netdev 0 0" >>/etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片34

6)客户端卸载

# 块存储

# 卸载

root@ceph-client:~# df -h

root@ceph-client:~# umount /mnt/rbd

root@ceph-client:~# df -h

Ubuntu 22.04安装Ceph单机版(reef)-图片35

# 卸载image

root@ceph-client:~# rbd showmapped --id rbd

root@ceph-client:~# rbd unmap -p rbd_pool rbd --id rbd

root@ceph-client:~# rbd showmapped --id rbd

# 删除image

root@ceph-client:~# rbd ls -l rbd_pool --id rbd

root@ceph-client:~# rbd rm -p rbd_pool rbd --id rbd

# 移除开机自动挂载

root@ceph-client:~# sed -i '/rbd0/d' /etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片36

# 查看存储池

root@ceph:/etc/ceph# ceph osd pool ls

# 删除pool

root@ceph:/etc/ceph# ceph osd pool rm rbd_pool rbd_pool --yes-i-really-really-mean-it

Error EPERM: pool deletion is disabled; you must first set the mon_allow_pool_delete config option to true before you can destroy a pool

# 临时关闭误删除存储池保护

root@ceph:/etc/ceph# ceph config set mon mon_allow_pool_delete true

# 删除pool

root@ceph:/etc/ceph# ceph osd pool rm rbd_pool rbd_pool --yes-i-really-really-mean-it

pool 'rbd_pool' removed

# 查看存储池

root@ceph:/etc/ceph# ceph osd pool ls

# 删除用户keyring

root@ceph:/etc/ceph# ceph auth ls

root@ceph:/etc/ceph# ceph auth rm client.rbd

# 开启误删除存储池保护

root@ceph:/etc/ceph# ceph config set mon mon_allow_pool_delete false

Ubuntu 22.04安装Ceph单机版(reef)-图片37

Ubuntu 22.04安装Ceph单机版(reef)-图片38

# 内核文件系统

root@ceph-client:~# df -h

# 卸载

root@ceph-client:~# umount /mnt/fs

root@ceph-client:~# df -h

# 移除开机自动挂载

root@ceph-client:~# sed -i '/clientfs.key/d' /etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片39

# 用户空间文件系统(Fuse)

root@ceph-client:~# df -h

# 卸载

root@ceph-client:~# umount /mnt/fuse

root@ceph-client:~# df -h

# 移除开机自动挂载

root@ceph-client:~# sed -i '/clientfs/d' /etc/fstab

root@ceph-client:~# cat /etc/fstab

Ubuntu 22.04安装Ceph单机版(reef)-图片40

6、配置Dashboard

# Ceph提供了原生的Dashboard功能,通过ceph dashboard完成对Ceph存储系统可视化监视。

1)登陆验证

# 浏览器输入https://192.168.10.220:8443,如下图所示

Ubuntu 22.04安装Ceph单机版(reef)-图片41

Ubuntu 22.04安装Ceph单机版(reef)-图片42

2)输入用户名密码,前面初始化集群会默认生成用户名密码

Ubuntu 22.04安装Ceph单机版(reef)-图片43

3)更改密码

Ubuntu 22.04安装Ceph单机版(reef)-图片44

4)输入用户名和修改后密码

Ubuntu 22.04安装Ceph单机版(reef)-图片45

5)登陆成功界面

Ubuntu 22.04安装Ceph单机版(reef)-图片46

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
小柒博客
  • 本文由 小柒博客 发表于 2025年11月13日 12:01:40
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/11994.html

发表评论