• 高级运维学习(八)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地址
    ceph1192.168.88.11/24
    ceph2192.168.88.12/24
    ceph3192.168.88.13/24
    client1192.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环境
    1. [root@pubserver ~]# mkdir ceph
    2. [root@pubserver ~]# cd ceph
    3. [root@pubserver ceph]# vim ansible.cfg
    4. [defaults]
    5. inventory = inventory
    6. host_key_checking = false
    7. [root@pubserver ceph]# vim inventory
    8. [ceph] # 定义ceph组
    9. ceph1 ansible_host=192.168.88.11
    10. ceph2 ansible_host=192.168.88.12
    11. ceph3 ansible_host=192.168.88.13
    12. [clients] # 定义客户端组
    13. client1 ansible_host=192.168.88.10
    14. [all:vars]
    15. ansible_ssh_user=root
    16. ansible_ssh_pass=a
    17. [root@pubserver ceph]# mkdir files/
    18. [root@pubserver ceph]# vim files/local88.repo
    19. [BaseOS]
    20. name = BaseOS
    21. baseurl = ftp://192.168.88.240/dvd/BaseOS
    22. enabled = 1
    23. gpgcheck = 0
    24. [AppStream]
    25. name = AppStream
    26. baseurl = ftp://192.168.88.240/dvd/AppStream
    27. enabled = 1
    28. gpgcheck = 0
    29. [rpms]
    30. name = rpms
    31. baseurl = ftp://192.168.88.240/rpms
    32. enabled = 1
    33. gpgcheck = 0
    34. # 配置yum
    35. [root@pubserver ceph]# vim 01-upload-repo.yml
    36. ---
    37. - name: config repos.d
    38. hosts: all
    39. tasks:
    40. - name: delete repos.d
    41. file:
    42. path: /etc/yum.repos.d
    43. state: absent
    44. - name: create repos.d
    45. file:
    46. path: /etc/yum.repos.d
    47. state: directory
    48. mode: '0755'
    49. - name: upload local88
    50. copy:
    51. src: files/local88.repo
    52. dest: /etc/yum.repos.d/
    53. [root@pubserver ceph]# ansible-playbook 01-upload-repo.yml
    • 配置名称解析
    1. # 配置三台主机实现名称解析,解析的名字务必与主机实际名字一致
    2. [root@pubserver ceph]# vim 02-modify-hosts.yml
    3. ---
    4. - name: add names
    5. hosts: ceph
    6. tasks:
    7. - name: add block
    8. blockinfile: # 类似于lineinfile模块,可在目标文件中加多行
    9. path: /etc/hosts
    10. block: |
    11. 192.168.88.11 ceph1
    12. 192.168.88.12 ceph2
    13. 192.168.88.13 ceph3
    14. 192.168.88.240 quay.io
    15. [root@pubserver ceph]# ansible-playbook 02-modify-hosts.yml
    16. # 查看结果,以ceph1为例
    17. [root@ceph1 ~]# tail -6 /etc/hosts
    18. # BEGIN ANSIBLE MANAGED BLOCK
    19. 192.168.88.11 ceph1
    20. 192.168.88.12 ceph2
    21. 192.168.88.13 ceph3
    22. 192.168.88.240 quay.io
    23. # END ANSIBLE MANAGED BLOCK
    • 配置pubserver为NTP服务器
    1. # 1. 查看pubserver自己的时区,如果时区不正确需要改正
    2. [root@pubserver ~]# timedatectl
    3. [root@pubserver ~]# timedatectl set-timezone Asia/Shanghai
    4. # 2. 查看时间,如果时间不正确,需要调整时间
    5. [root@pubserver ~]# date
    6. [root@pubserver ~]# date -s "年-月-日 时:分:秒"
    7. # 3. 配置chronyd服务
    8. [root@pubserver ~]# yum install -y chrony
    9. [root@pubserver ~]# vim /etc/chrony.conf # 打开2326行的注释
    10. ...略...
    11. 24 # Allow NTP client access from local network.
    12. 25 allow 192.168.0.0/16 # 为192.168开头的客户端提供时间服务
    13. 26
    14. 27 # Serve time even if not synchronized to a time source.
    15. 28 local stratum 10 # 即使自己没有时间源,也为客户端提供时间服务
    16. ...略...
    17. [root@pubserver ~]# systemctl enable chronyd --now
    18. [root@pubserver ~]# ss -ulnp | grep :123 # ntp使用udp 123端口
    • 配置ceph1-ceph3使用pubserver提供的时间服务
    1. [root@pubserver ceph]# vim 03-config-ntp.yml
    2. ---
    3. - name: config ntp
    4. hosts: ceph
    5. tasks:
    6. - name: install chrony # 安装chrony
    7. yum:
    8. name: chrony
    9. state: present
    10. - name: modify config # 替换以pool开头的行
    11. lineinfile:
    12. path: /etc/chrony.conf
    13. regexp: '^pool'
    14. line: "pool 192.168.88.240 iburst"
    15. notify: restart ntp # 如果该任务的状态是CHANGED,则执行restart ntp任务
    16. handlers:
    17. - name: restart ntp # 只有notify通知时,才执行重启任务
    18. service:
    19. name: chronyd
    20. state: restarted
    21. enabled: yes
    22. [root@pubserver ceph]# ansible-playbook 03-config-ntp.yml
    23. # 以ceph1为例,查看结果
    24. [root@ceph1 ~]# chronyc sources -v
    25. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
    26. / .- Source state '*' = current best, '+' = combined, '-' = not combined,
    27. | / 'x' = may be in error, '~' = too variable, '?' = unusable.
    28. || .- xxxx [ yyyy ] +/- zzzz
    29. || Reachability register (octal) -. | xxxx = adjusted offset,
    30. || Log2(Polling interval) --. | | yyyy = measured offset,
    31. || \ | | zzzz = estimated error.
    32. || | | \
    33. MS Name/IP address Stratum Poll Reach LastRx Last sample
    34. ===============================================================================
    35. ^* 192.168.88.240 10 6 37 4 -8731ns[-6313us] +/- 7118us
    • 准备容器仓库服务器
    1. # 1. 将真机/linux-soft/s2/zzg/ceph_soft/ceph-server/docker-distribution-2.6.2-2.git48294d9.el7.x86_64.rpm拷贝到pubserver的/root目录并安装
    2. [root@pubserver ~]# yum install -y docker-distribution-2.6.2-2.git48294d9.el7.x86_64.rpm
    3. # 2. 启动服务
    4. [root@pubserver ~]# systemctl enable docker-distribution --now
    • 安装软件包,并导入镜像
    1. # 1. 在ceph集群节点上安装软件包
    2. [root@pubserver ceph]# vim 04-install-ceph.yml
    3. ---
    4. - name: install pkg
    5. hosts: ceph
    6. tasks:
    7. - name: install pkg # 安装软件包
    8. yum:
    9. name: python39,podman,lvm2
    10. state: present
    11. [root@pubserver ceph]# ansible-playbook 04-install-ceph.yml
    12. # 2. 将真机/linux-soft/s2/zzg/ceph_soft/ceph-server目录拷贝到ceph各节点,并导入镜像
    13. [root@ceph1 ~]# cd ceph-server/
    14. [root@ceph1 ceph-server]# for c in *.tar
    15. > do
    16. > podman load -i $c
    17. > done
    18. [root@ceph2 ~]# cd ceph_soft/
    19. [root@ceph2 ceph-server]# for c in *.tar
    20. > do
    21. > podman load -i $c
    22. > done
    23. [root@ceph3 ~]# cd ceph_soft/
    24. [root@ceph3 ceph-server]# for c in *.tar
    25. > do
    26. > podman load -i $c
    27. > done
    28. # 3. 查看执行结果
    29. [root@ceph1 ceph-server]# podman images
    30. REPOSITORY TAG IMAGE ID CREATED SIZE
    31. quay.io/ceph/ceph v17 cc65afd6173a 7 weeks ago 1.4 GB
    32. quay.io/ceph/ceph-grafana 8.3.5 dad864ee21e9 8 months ago 571 MB
    33. quay.io/prometheus/prometheus v2.33.4 514e6a882f6e 9 months ago 205 MB
    34. quay.io/prometheus/node-exporter v1.3.1 1dbe0e931976 12 months ago 22.3 MB
    35. quay.io/prometheus/alertmanager v0.23.0 ba2b418f427c 15 months ago 58.9 MB
    36. # 4. 配置ceph1-ceph3使用pubserver作为仓库服务器
    37. [root@pubserver ceph]# vim 05-config-registry.yml
    38. ---
    39. - name: config registry
    40. hosts: ceph
    41. tasks:
    42. - name: modify config
    43. blockinfile:
    44. path: /etc/containers/registries.conf
    45. block: |
    46. [[registry]]
    47. location = "quay.io:5000" # 指定服务器地址
    48. insecure = true # 允许使用http协议
    49. [root@pubserver ceph]# ansible-playbook 05-config-registry.yml
    50. # 5. 以ceph1为例,查看执行结果
    51. [root@ceph1 ceph_soft]# tail -5 /etc/containers/registries.conf
    52. # BEGIN ANSIBLE MANAGED BLOCK
    53. [[registry]]
    54. location = "quay.io:5000"
    55. insecure = true
    56. # END ANSIBLE MANAGED BLOCK
    57. # 5. 修改镜像名称,以便可以将其推送到自建镜像服务器
    58. [root@ceph1 ceph-server]# podman tag quay.io/ceph/ceph:v17 quay.io:5000/ceph/ceph:v17
    59. [root@ceph1 ceph-server]# podman tag quay.io/ceph/ceph-grafana:8.3.5 quay.io:5000/ceph/ceph-grafana:8.3.5
    60. [root@ceph1 ceph-server]# podman tag quay.io/prometheus/prometheus:v2.33.4 quay.io:5000/prometheus/prometheus:v2.33.4
    61. [root@ceph1 ceph-server]# podman tag quay.io/prometheus/node-exporter:v1.3.1 quay.io:5000/prometheus/node-exporter:v1.3.1
    62. [root@ceph1 ceph-server]# podman tag quay.io/prometheus/alertmanager:v0.23.0 quay.io:5000/prometheus/alertmanager:v0.23.0
    63. # 6. 将镜像推送到镜像服务器,以便其他节点可以通过服务器下载镜像
    64. [root@ceph1 ceph-server]# podman push quay.io:5000/ceph/ceph:v17
    65. [root@ceph1 ceph-server]# podman push quay.io:5000/ceph/ceph-grafana:8.3.5
    66. [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/prometheus:v2.33.4
    67. [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/node-exporter:v1.3.1
    68. [root@ceph1 ceph-server]# podman push quay.io:5000/prometheus/alertmanager:v0.23.0
    • 完成此步骤,给ceph1-ceph3打快照

    安装ceph

    • 所有Ceph集群都需要至少一个监视器Monitor,以及至少与存储在集群上的对象副本一样多的OSD。引导初始监视器是部署Ceph存储集群的第一步。
    • Monitor部署还为整个集群设置了重要的标准,例如池的副本数量、每个OSD的放置组数量、心跳间隔、是否需要身份验证等。这些值中的大部分是默认设置的。
    • 创建集群
    1. # 1. 在ceph1上初始化集ceph集群。
    2. # 集群初始化完成后,将自动生成ssh免密密钥,存放在/etc/ceph/目录下
    3. [root@ceph1 ceph-server]# ./cephadm bootstrap --mon-ip 192.168.88.11 --initial-dashboard-password=123456 --dashboard-password-noupdate
    4. # 2. ceph将会以容器化的方式部署,查看生成了6个容器。
    5. [root@ceph1 ceph-server]# podman ps
    6. # 3. 拷贝密钥文件至其他节点
    7. [root@ceph1 ceph-server]# ssh-copy-id -f -i /etc/ceph/ceph.pub ceph2
    8. [root@ceph1 ceph-server]# ssh-copy-id -f -i /etc/ceph/ceph.pub ceph3
    9. # 4. 进入管理容器,查看ceph状态
    10. [root@ceph1 ceph-server]# ./cephadm shell # 进入管理容器
    11. [ceph: root@ceph1 /]# ceph -s # 查看ceph状态
    12. cluster:
    13. id: 1ddfccf2-77b4-11ed-8941-000c2953b002
    14. health: HEALTH_WARN
    15. OSD count 0 < osd_pool_default_size 3
    16. services:
    17. mon: 1 daemons, quorum ceph1 (age 11m)
    18. mgr: ceph1.vnoivz(active, since 10m)
    19. osd: 0 osds: 0 up, 0 in
    20. data:
    21. pools: 0 pools, 0 pgs
    22. objects: 0 objects, 0 B
    23. usage: 0 B used, 0 B / 0 B avail
    24. pgs:
    25. # 5. 查看相关容器状态,显示所有容器均已启动
    26. [ceph: root@ceph1 /]# ceph orch ls
    27. NAME PORTS RUNNING REFRESHED AGE PLACEMENT
    28. alertmanager ?:9093,9094 1/1 91s ago 3m count:1
    29. crash 1/3 91s ago 4m *
    30. grafana ?:3000 1/1 91s ago 4m count:1
    31. mgr 1/2 91s ago 4m count:2
    32. mon 1/5 91s ago 4m count:5
    33. node-exporter ?:9100 1/3 91s ago 4m *
    34. prometheus ?:9095 1/1 91s ago 4m count:1
    35. # 6. 查看集群中现有主机
    36. [ceph: root@ceph1 /]# ceph orch host ls
    37. HOST ADDR LABELS STATUS
    38. ceph1 192.168.88.11 _admin
    39. 1 hosts in cluster
    40. # 7. 向集群中添加其他主机
    41. [ceph: root@ceph1 /]# ceph orch host add ceph2 192.168.88.12
    42. [ceph: root@ceph1 /]# ceph orch host add ceph3 192.168.88.13
    43. # 注:删除错误的主机命令为:ceph orch host rm 主机名 --force
    44. # 8. 查看集群中主机
    45. [ceph: root@ceph1 /]# ceph orch host ls
    46. HOST ADDR LABELS STATUS
    47. ceph1 192.168.88.11 _admin
    48. ceph2 192.168.88.12
    49. ceph3 192.168.88.13
    50. 3 hosts in cluster
    51. # 9. 扩容MON节点。一共有3台MON,位于ceph1-ceph3
    52. [ceph: root@ceph1 /]# ceph orch apply mon --placement="3 ceph1 ceph2 ceph3"
    53. # 10. 查看mon状态
    54. [ceph: root@ceph1 /]# ceph -s
    55. cluster:
    56. id: a4b69ab4-79dd-11ed-ae7b-000c2953b002
    57. health: HEALTH_WARN
    58. OSD count 0 < osd_pool_default_size 3
    59. services:
    60. mon: 3 daemons, quorum ceph1,ceph3,ceph2 (age 2m)
    61. mgr: ceph1.gmqorm(active, since 15m), standbys: ceph3.giqaph
    62. osd: 0 osds: 0 up, 0 in
    63. data:
    64. pools: 0 pools, 0 pgs
    65. objects: 0 objects, 0 B
    66. usage: 0 B used, 0 B / 0 B avail
    67. pgs:
    68. [ceph: root@ceph1 /]# ceph mon stat
    69. 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
    70. # 11. ceph2和ceph3上也将会出现相关容器
    71. [root@ceph2 ~]# podman ps
    72. [root@ceph3 ~]# podman ps
    • 添加OSD硬盘
    1. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdb
    2. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdc
    3. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph1:/dev/vdd
    4. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdb
    5. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdc
    6. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph2:/dev/vdd
    7. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdb
    8. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdc
    9. [ceph: root@ceph1 /]# ceph orch daemon add osd ceph3:/dev/vdd
    10. # 2. 在节点上查询容器信息,将会发现又有新的osd容器出现
    11. [root@ceph1 ~]# podman ps
    12. # 3. 此时ceph的状态将会是HEALTH_OK,ceph集群搭建完成。
    13. [ceph: root@ceph1 /]# ceph -s
    14. cluster:
    15. id: a4b69ab4-79dd-11ed-ae7b-000c2953b002
    16. health: HEALTH_OK
    17. services:
    18. mon: 3 daemons, quorum ceph1,ceph3,ceph2 (age 2m)
    19. mgr: ceph1.gmqorm(active, since 2h), standbys: ceph3.giqaph
    20. osd: 9 osds: 9 up (since 35s), 9 in (since 59s)
    21. data:
    22. pools: 1 pools, 1 pgs
    23. objects: 2 objects, 449 KiB
    24. usage: 186 MiB used, 180 GiB / 180 GiB avail
    25. pgs: 1 active+clean

    故障排除:

    查看服务状态:

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

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

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

    然后重新配置:

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

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

    1. [ceph: root@ceph1 /]# ceph orch daemon reconfig mgr ceph2
    2. # 或
    3. [ceph: root@ceph1 /]# ceph orch daemon redeploy mgr ceph2

  • 相关阅读:
    【计算机网络】P1 计算机网络概念、组成、功能、分类、标准化工作以及性能评估指标
    深度图的方法实现加雾,Synscapes数据集以及D455相机拍摄为例
    Javascript知识【JS方法和事件&正则&JS注册案例】
    yolov5 C++部署学习笔记
    Java中动态执行数学表达式
    可视化图形原理
    简化对象和函数写法
    【C++模拟实现】哈希与unorder_set和unorder_map关联式容器的模拟实现
    vue+flv.js+SpringBoot+websocket实现视频监控与回放
    Docker容器教程 - 从入门安装 --> Compose编排Java服务 --> 重量级监控(建议收藏)
  • 原文地址:https://blog.csdn.net/2301_79227925/article/details/133064105