高级运维学习(八)Ceph 概述与部署

ceph概述

  • ceph可以实现的存储方式:

    • 块存储:提供像普通硬盘一样的存储,为使用者提供"硬盘"
    • 文件系统存储:类似于NFS的共享方式,为使用者提供共享文件夹
    • 对象存储:像百度云盘一样,需要使用单独的客户端
  • Ceph存储集群至少需要一个Ceph监视器、Ceph管理器和Ceph OSD(对象存储守护程序)。运行Ceph文件系统客户端时,需要Ceph元数据服务器。

    • 监视器:Ceph Monitor(ceph-mon)维护集群状态图,包括监视器图、管理器图、OSD图、MDS图和CRUSH图。这些映射是Ceph守护进程相互协调所需的关键集群状态。监视器还负责管理守护程序和客户端之间的身份验证。为了冗余和高可用性,通常至少需要三台Monitor。
    • 管理器:Ceph Manager(ceph-mgr)负责跟踪ceph集群的运行时指标和当前状态,包括存储利用率、当前性能指标和系统负载。Ceph Manager守护进程还托管基于python的模块来管理和公开Ceph集群信息,包括基于web的Ceph仪表板和REST API。高可用性通常需要至少两台Manager。
    • Ceph OSD:ceph-osd存储数据,处理数据复制、恢复、重新平衡,并通过检查其他Ceph OSD守护进程的心跳来为Ceph监视器和管理器提供一些监视信息。为了实现冗余和高可用性,通常至少需要三个Ceph OSD。
    • MDS:ceph-mds代表Ceph文件系统存储元数据(即,Ceph块设备和Ceph对象存储不使用MDS)。Ceph元数据服务器允许POSIX文件系统用户执行基本命令(如ls、find等)。)而不会给Ceph存储集群带来巨大的负担。
    • RGW:Rados Gateway,是一个提供对象存储功能的组件,可以通过RESTful接口向外部应用程序提供可扩展和高可用的存储服务。
  • Ceph将数据作为对象存储在逻辑存储池中。使用CRUSH算法,Ceph计算哪个归置组(PG)应该包含该对象,以及哪个OSD应该存储该归置组。CRUSH算法支持Ceph存储集群动态扩展、重新平衡和恢复。

  • 部署ceph集群需要python3、podman或docker、时间服务(如chrony)、lvm2

部署Ceph

节点准备

  • ceph1、ceph2、ceph3内存至少需要2GB
主机名 IP地址
ceph1 192.168.88.11/24
ceph2 192.168.88.12/24
ceph3 192.168.88.13/24
client1 192.168.88.10/24
  • 关机,为ceph1-ceph3各额外再添加3块20GB的硬盘

cephadm

  • Cephadm使用容器和systemd安装和管理Ceph集群,并与CLI(命令行)和dashboard GUI紧密集成。

  • cephadm与新的编排API完全集成,并完全支持新的CLI和仪表板功能来管理集群部署。

  • cephadm需要容器支持(podman或docker)和Python 3。

  • cephadm是一个用于管理Ceph集群的实用程序。可以使用它:

    • 将Ceph容器添加到集群中
    • 从群集中删除一个Ceph容器
    • 更新Ceph容器

准备基础环境

  • 在pubserver上配置ansible环境

    [root@pubserver ~]# mkdir ceph
    [root@pubserver ~]# cd ceph
    [root@pubserver ceph]# vim ansible.cfg
    [defaults]
    inventory = inventory
    host_key_checking = false

    [root@pubserver ceph]# vim inventory
    [ceph] # 定义ceph组
    ceph1 ansible_host=192.168.88.11
    ceph2 ansible_host=192.168.88.12
    ceph3 ansible_host=192.168.88.13

    [clients] # 定义客户端组
    client1 ansible_host=192.168.88.10

    [all:vars]
    ansible_ssh_user=root
    ansible_ssh_pass=a

    [root@pubserver ceph]# mkdir files/
    [root@pubserver ceph]# vim files/local88.repo
    [BaseOS]
    name = BaseOS
    baseurl = ftp://192.168.88.240/dvd/BaseOS
    enabled = 1
    gpgcheck = 0

    [AppStream]
    name = AppStream
    baseurl = ftp://192.168.88.240/dvd/AppStream
    enabled = 1
    gpgcheck = 0

    [rpms]
    name = rpms
    baseurl = ftp://192.168.88.240/rpms
    enabled = 1
    gpgcheck = 0

    配置yum

    [root@pubserver ceph]# vim 01-upload-repo.yml

    • name: config repos.d
      hosts: all
      tasks:
      • name: delete repos.d
        file:
        path: /etc/yum.repos.d
        state: absent

      • name: create repos.d
        file:
        path: /etc/yum.repos.d
        state: directory
        mode: '0755'

      • name: upload local88
        copy:
        src: files/local88.repo
        dest: /etc/yum.repos.d/
        [root@pubserver ceph]# ansible-playbook 01-upload-repo.yml

  • 配置名称解析

    配置三台主机实现名称解析,解析的名字务必与主机实际名字一致

    [root@pubserver ceph]# vim 02-modify-hosts.yml

    • name: add names
      hosts: ceph
      tasks:
      • name: add block
        blockinfile: # 类似于lineinfile模块,可在目标文件中加多行
        path: /etc/hosts
        block: |
        192.168.88.11 ceph1
        192.168.88.12 ceph2
        192.168.88.13 ceph3
        192.168.88.240 quay.io
        [root@pubserver ceph]# ansible-playbook 02-modify-hosts.yml

    查看结果,以ceph1为例

    [root@ceph1 ~]# tail -6 /etc/hosts

    BEGIN ANSIBLE MANAGED BLOCK

    192.168.88.11 ceph1
    192.168.88.12 ceph2
    192.168.88.13 ceph3
    192.168.88.240 quay.io

    END ANSIBLE MANAGED BLOCK

  • 配置pubserver为NTP服务器

    1. 查看pubserver自己的时区,如果时区不正确需要改正

    [root@pubserver ~]# timedatectl
    [root@pubserver ~]# timedatectl set-timezone Asia/Shanghai

    2. 查看时间,如果时间不正确,需要调整时间

    [root@pubserver ~]# date
    [root@pubserver ~]# date -s "年-月-日 时:分:秒"

    3. 配置chronyd服务

    [root@pubserver ~]# yum install -y chrony
    [root@pubserver ~]# vim /etc/chrony.conf # 打开23、26行的注释
    ...略...
    24 # Allow NTP client access from local network.
    25 allow 192.168.0.0/16 # 为192.168开头的客户端提供时间服务
    26
    27 # Serve time even if not synchronized to a time source.
    28 local stratum 10 # 即使自己没有时间源,也为客户端提供时间服务
    ...略...
    [root@pubserver ~]# systemctl enable chronyd --now
    [root@pubserver ~]# ss -ulnp | grep :123 # ntp使用udp 123端口

  • 配置ceph1-ceph3使用pubserver提供的时间服务

    [root@pubserver ceph]# vim 03-config-ntp.yml

    • name: config ntp
      hosts: ceph
      tasks:

      • name: install chrony # 安装chrony
        yum:
        name: chrony
        state: present

      • name: modify config # 替换以pool开头的行
        lineinfile:
        path: /etc/chrony.conf
        regexp: '^pool'
        line: "pool 192.168.88.240 iburst"
        notify: restart ntp # 如果该任务的状态是CHANGED,则执行restart ntp任务

      handlers:

      • name: restart ntp # 只有notify通知时,才执行重启任务
        service:
        name: chronyd
        state: restarted
        enabled: yes
        [root@pubserver ceph]# ansible-playbook 03-config-ntp.yml

    以ceph1为例,查看结果

    [root@ceph1 ~]# chronyc sources -v

    .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
    

    / .- Source state '*' = current best, '+' = combined, '-' = not combined,
    | / 'x' = may be in error, '~' = too variable, '?' = unusable.
    || .- xxxx [ yyyy ] +/- zzzz
    || Reachability register (octal) -. | xxxx = adjusted offset,
    || Log2(Polling interval) --. | | yyyy = measured offset,
    || \ | | zzzz = estimated error.
    || | |
    MS Name/IP address Stratum Poll Reach LastRx Last sample

    ^* 192.168.88.240 10 6 37 4 -8731ns[-6313us] +/- 7118us

  • 准备容器仓库服务器

    1. 将真机/linux-soft/s2/zzg/ceph_soft/ceph-server/docker-distribution-2.6.2-2.git48294d9.el7.x86_64.rpm拷贝到pubserver的/root目录并安装

    [root@pubserver ~]# yum install -y docker-distribution-2.6.2-2.git48294d9.el7.x86_64.rpm

    2. 启动服务

    [root@pubserver ~]# systemctl enable docker-distribution --now

  • 安装软件包,并导入镜像

    1. 在ceph集群节点上安装软件包

    [root@pubserver ceph]# vim 04-install-ceph.yml

    • name: install pkg
      hosts: ceph
      tasks:
      • name: install pkg # 安装软件包
        yum:
        name: python39,podman,lvm2
        state: present
        [root@pubserver ceph]# ansible-playbook 04-install-ceph.yml

    2. 将真机/linux-soft/s2/zzg/ceph_soft/ceph-server目录拷贝到ceph各节点,并导入镜像

    [root@ceph1 ~]# cd ceph-server/
    [root@ceph1 ceph-server]# for c in *.tar

    do
    podman load -i $c
    done
    [root@ceph2 ~]# cd ceph_soft/
    [root@ceph2 ceph-server]# for c in *.tar
    do
    podman load -i $c
    done
    [root@ceph3 ~]# cd ceph_soft/
    [root@ceph3 ceph-server]# for c in *.tar
    do
    podman load -i $c
    done

    3. 查看执行结果

    [root@ceph1 ceph-server]# podman images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    quay.io/ceph/ceph v17 cc65afd6173a 7 weeks ago 1.4 GB
    quay.io/ceph/ceph-grafana 8.3.5 dad864ee21e9 8 months ago 571 MB
    quay.io/prometheus/prometheus v2.33.4 514e6a882f6e 9 months ago 205 MB
    quay.io/prometheus/node-exporter v1.3.1 1dbe0e931976 12 months ago 22.3 MB
    quay.io/prometheus/alertmanager v0.23.0 ba2b418f427c 15 months ago 58.9 MB

    4. 配置ceph1-ceph3使用pubserver作为仓库服务器

    [root@pubserver ceph]# vim 05-config-registry.yml

    • name: config registry
      hosts: ceph
      tasks:
      • name: modify config
        blockinfile:
        path: /etc/containers/registries.conf
        block: |
        [[registry]]
        location = "quay.io:5000" # 指定服务器地址
        insecure = true # 允许使用http协议
        [root@pubserver ceph]# ansible-playbook 05-config-registry.yml

    5. 以ceph1为例,查看执行结果

    [root@ceph1 ceph_soft]# tail -5 /etc/containers/registries.conf

    BEGIN ANSIBLE MANAGED BLOCK

    [[registry]]
    location = "quay.io:5000"
    insecure = true

    END ANSIBLE MANAGED BLOCK

    5. 修改镜像名称,以便可以将其推送到自建镜像服务器

    [root@ceph1 ceph-server]# podman tag quay.io/ceph/ceph:v17 quay.io:5000/ceph/ceph:v17
    [root@ceph1 ceph-server]# podman tag quay.io/ceph/ceph-grafana:8.3.5 quay.io:5000/ceph/ceph-grafana:8.3.5
    [root@ceph1 ceph-server]# podman tag quay.io/prometheus/prometheus:v2.33.4 quay.io:5000/prometheus/prometheus:v2.33.4
    [root@ceph1 ceph-server]# podman tag quay.io/prometheus/node-exporter:v1.3.1 quay.io:5000/prometheus/node-exporter:v1.3.1
    [root@ceph1 ceph-server]# podman tag quay.io/prometheus/alertmanager:v0.23.0 quay.io:5000/prometheus/alertmanager:v0.23.0

    6. 将镜像推送到镜像服务器,以便其他节点可以通过服务器下载镜像

    [root@ceph1 ceph-server]# podman push quay.io:5000/ceph/ceph:v17
    [root@ceph1 ceph-server]# podman push quay.io:5000/ceph/ceph-grafana:8.3.5
    [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/prometheus:v2.33.4
    [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/node-exporter:v1.3.1
    [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/alertmanager:v0.23.0

  • 完成此步骤,给ceph1-ceph3打快照

安装ceph

  • 所有Ceph集群都需要至少一个监视器Monitor,以及至少与存储在集群上的对象副本一样多的OSD。引导初始监视器是部署Ceph存储集群的第一步。

  • Monitor部署还为整个集群设置了重要的标准,例如池的副本数量、每个OSD的放置组数量、心跳间隔、是否需要身份验证等。这些值中的大部分是默认设置的。

  • 创建集群

    1. 在ceph1上初始化集ceph集群。

    集群初始化完成后,将自动生成ssh免密密钥,存放在/etc/ceph/目录下

    [root@ceph1 ceph-server]# ./cephadm bootstrap --mon-ip 192.168.88.11 --initial-dashboard-password=123456 --dashboard-password-noupdate

    2. ceph将会以容器化的方式部署,查看生成了6个容器。

    [root@ceph1 ceph-server]# podman ps

    3. 拷贝密钥文件至其他节点

    [root@ceph1 ceph-server]# ssh-copy-id -f -i /etc/ceph/ceph.pub ceph2
    [root@ceph1 ceph-server]# ssh-copy-id -f -i /etc/ceph/ceph.pub ceph3

    4. 进入管理容器,查看ceph状态

    [root@ceph1 ceph-server]# ./cephadm shell # 进入管理容器
    [ceph: root@ceph1 /]# ceph -s # 查看ceph状态
    cluster:
    id: 1ddfccf2-77b4-11ed-8941-000c2953b002
    health: HEALTH_WARN
    OSD count 0 < osd_pool_default_size 3

    services:
      mon: 1 daemons, quorum ceph1 (age 11m)
      mgr: ceph1.vnoivz(active, since 10m)
      osd: 0 osds: 0 up, 0 in
    
    data:
      pools:   0 pools, 0 pgs
      objects: 0 objects, 0 B
      usage:   0 B used, 0 B / 0 B avail
      pgs: 
    

    5. 查看相关容器状态,显示所有容器均已启动

    [ceph: root@ceph1 /]# ceph orch ls
    NAME PORTS RUNNING REFRESHED AGE PLACEMENT
    alertmanager ?:9093,9094 1/1 91s ago 3m count:1
    crash 1/3 91s ago 4m *
    grafana ?:3000 1/1 91s ago 4m count:1
    mgr 1/2 91s ago 4m count:2
    mon 1/5 91s ago 4m count:5
    node-exporter ?:9100 1/3 91s ago 4m *
    prometheus ?:9095 1/1 91s ago 4m count:1

    6. 查看集群中现有主机

    [ceph: root@ceph1 /]# ceph orch host ls
    HOST ADDR LABELS STATUS
    ceph1 192.168.88.11 _admin
    1 hosts in cluster

    7. 向集群中添加其他主机

    [ceph: root@ceph1 /]# ceph orch host add ceph2 192.168.88.12
    [ceph: root@ceph1 /]# ceph orch host add ceph3 192.168.88.13

    注:删除错误的主机命令为:ceph orch host rm 主机名 --force

    8. 查看集群中主机

    [ceph: root@ceph1 /]# ceph orch host ls
    HOST ADDR LABELS STATUS
    ceph1 192.168.88.11 _admin
    ceph2 192.168.88.12
    ceph3 192.168.88.13
    3 hosts in cluster

    9. 扩容MON节点。一共有3台MON,位于ceph1-ceph3

    [ceph: root@ceph1 /]# ceph orch apply mon --placement="3 ceph1 ceph2 ceph3"

    10. 查看mon状态

    [ceph: root@ceph1 /]# ceph -s
    cluster:
    id: a4b69ab4-79dd-11ed-ae7b-000c2953b002
    health: HEALTH_WARN
    OSD count 0 < osd_pool_default_size 3

    services:
      mon: 3 daemons, quorum ceph1,ceph3,ceph2 (age 2m)
      mgr: ceph1.gmqorm(active, since 15m), standbys: ceph3.giqaph
      osd: 0 osds: 0 up, 0 in
    
    data:
      pools:   0 pools, 0 pgs
      objects: 0 objects, 0 B
      usage:   0 B used, 0 B / 0 B avail
      pgs:     
    

    [ceph: root@ceph1 /]# ceph mon stat
    e3: 3 mons at {ceph1=[v2:192.168.88.11:3300/0,v1:192.168.88.11:6789/0],ceph2=[v2:192.168.88.12:3300/0,v1:192.168.88.12:6789/0],ceph3=[v2:192.168.88.13:3300/0,v1:192.168.88.13:6789/0]}, election epoch 14, leader 0 ceph1, quorum 0,1,2 ceph1,ceph3,ceph2

    11. ceph2和ceph3上也将会出现相关容器

    [root@ceph2 ~]# podman ps
    [root@ceph3 ~]# podman ps

  • 添加OSD硬盘

    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdb
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdc
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdd
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdb
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdc
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdd
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdb
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdc
    [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdd

    2. 在节点上查询容器信息,将会发现又有新的osd容器出现

    [root@ceph1 ~]# podman ps

    3. 此时ceph的状态将会是HEALTH_OK,ceph集群搭建完成。

    [ceph: root@ceph1 /]# ceph -s
    cluster:
    id: a4b69ab4-79dd-11ed-ae7b-000c2953b002
    health: HEALTH_OK

    services:
      mon: 3 daemons, quorum ceph1,ceph3,ceph2 (age 2m)
      mgr: ceph1.gmqorm(active, since 2h), standbys: ceph3.giqaph
      osd: 9 osds: 9 up (since 35s), 9 in (since 59s)
    
    data:
      pools:   1 pools, 1 pgs
      objects: 2 objects, 449 KiB
      usage:   186 MiB used, 180 GiB / 180 GiB avail
      pgs:     1 active+clean
    

故障排除:

查看服务状态:

[ceph: root@ceph1 /]# ceph orch ps

如果有error(比如node-exporter.ceph2),则把相应的服务删除:

[ceph: root@ceph1 /]# ceph orch daemon rm node-expoter.ceph2

然后重新配置:

[ceph: root@ceph1 /]# ceph orch daemon reconfig node-exporter.ceph2
# 或
[ceph: root@ceph1 /]# ceph orch daemon redeploy node-exporter.ceph2

如果是mgr这样的服务出故障,删除后,部署的命令是:

[ceph: root@ceph1 /]# ceph orch daemon reconfig mgr ceph2
# 或
[ceph: root@ceph1 /]# ceph orch daemon redeploy mgr ceph2
相关推荐
爱吃龙利鱼2 小时前
网络基础知识笔记(五)接口管理
运维·网络·笔记·云原生·智能路由器
陈小肚2 小时前
DNS 反向解析导致 ssh 连接缓慢
运维·ssh
zbdx不知名菜鸡2 小时前
linux基础 超级笔记
linux·运维·服务器
wellnw2 小时前
【IPv6】IPv6地址格式及地址分类(组播、单播、任播)整理
运维·服务器·网络
wanhengwangluo2 小时前
高防服务器的优劣势有哪些?
运维·服务器
limengshi1383923 小时前
通信工程学习:什么是IP网际协议
网络·网络协议·学习·tcp/ip·信息与通信
总是学不会.3 小时前
SpringBoot项目:前后端打包与部署(使用 Maven)
java·服务器·前端·后端·maven
shelby_loo4 小时前
在Ubuntu下通过Docker部署NAS服务器
服务器·ubuntu·docker
IM_DALLA5 小时前
【Verilog学习日常】—牛客网刷题—Verilog快速入门—VL70
学习·fpga开发·verilog学习
李的阿洁5 小时前
OSPF的不规则区域
运维·服务器·网络