ceph可以实现的存储方式:
Ceph存储集群至少需要一个Ceph监视器、Ceph管理器和Ceph OSD(对象存储守护程序)。运行Ceph文件系统客户端时,需要Ceph元数据服务器。
Ceph将数据作为对象存储在逻辑存储池中。使用CRUSH算法,Ceph计算哪个归置组(PG)应该包含该对象,以及哪个OSD应该存储该归置组。CRUSH算法支持Ceph存储集群动态扩展、重新平衡和恢复。
部署ceph集群需要python3、podman或docker、时间服务(如chrony)、lvm2
| 主机名 | 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 |
Cephadm使用容器和systemd安装和管理Ceph集群,并与CLI(命令行)和dashboard GUI紧密集成。
cephadm与新的编排API完全集成,并完全支持新的CLI和仪表板功能来管理集群部署。
cephadm需要容器支持(podman或docker)和Python 3。
cephadm是一个用于管理Ceph集群的实用程序。可以使用它:
- [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
- # 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端口
- [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
- # 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
- [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