ceph添加&删除mon&osd

本次主要是使用ceph-deploy工具和使用ceph的相关命令实现集群Monitor&osd的增加和删除。

添加monitor
修改配置文件
添加新的mon,逗号分隔不要有空格:

cat /root/cluster/ceph.conf |grep mon

mon_initial_members = test3, test4, test5
mon_host = 10.0.0.3,10.0.0.4,10.0.0.5

推送配置

ceph-deploy --overwrite-conf config push  test3 test4 test5

……
若干log
……
添加MON

ceph-deploy mon create test4 test5

……
若干log
……

查看
ceph -s可以看到新的MON已经添加进来了。

[root@test3 ~]# ceph -s
cluster e40207d9-d9a8-43ba-8d3c-45fb79bfa0f4
 health HEALTH_OK
 monmap e1: 3 mons at {test3=10.0.0.3:6789/0,test4=10.0.0.4:6789/0,test5=10.0.0.5:6789/0}
        election epoch 14, quorum 0,1,2 test3,test4,test5
        ……

需要注意的是,如果新增节点ceph-3上之前部署过MON,必须清理干净之前的MON数据库,否则会有异常发生,因为ceph会在创建MON之前检测/var/lib/ceph/mon/$CLUSTER-$HOSTNAME目录下是否有done文件,如果有的话,就不会新建而沿用原来的

ps aux|grep ceph-mon |awk '{print $2}'|xargs kill -9

rm -rf /var/run/ceph/*
rm -rf /var/lib/ceph/mon/*
rm -rf /var/lib/ceph/bootstrap-mon/*
rm -rf /etc/ceph/*

删除monitor
修改配置文件
去除需要删除的节点host

cat /root/cluster/ceph.conf |grep mon

mon_initial_members = test3
mon_host = 10.0.0.3

推送配置

ceph-deploy --overwrite-conf config push test3 test4 test5

……
若干log
……

删除MON
通过ceph-deploy移除test4\test5

ceph-deploy mon create test4 test5

……
若干log
……

从集群中删除 monitor。

ceph mon remove {mon-id}

查看
ceph -s可以发现test4\test5这两个个MON已经被删除了

ceph-deploy删除MON的时候调用的指令是ceph mon remove ceph-3同时需要keyring,如果某个时候把cephx设置成了none这个MON的keyring是不会生成的。
删除的MON的文件夹被移到了/var/lib/ceph/mon-removed,并不是真的删除了,有时候这个文件夹能救ceph一命

添加osd
添加TEST5节点上SDB\SDC\SDD

ceph-deploy osd create test5:/dev/sda test5:/dev/sdb test5:/dev/sdc --zap-disk

……
若干log
……
检查
ceph -s检查集群状态

查看磁盘分区和挂载情况

[root@test5 ~]# lsblk
NAME                                                                                              MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                                                                                                 8:0    0 447.1G  0 disk
├─sda1                                                                                              8:1    0 437.1G  0 part /var/lib/ceph/osd/ceph-6
└─sda2                                                                                              8:2    0    10G  0 part
sdb                                                                                                 8:16   0 447.1G  0 disk
├─sdb1                                                                                              8:17   0 437.1G  0 part /var/lib/ceph/osd/ceph-7
└─sdb2                                                                                              8:18   0    10G  0 part
sdc                                                                                                 8:32   0 447.1G  0 disk
├─sdc1                                                                                              8:33   0 437.1G  0 part /var/lib/ceph/osd/ceph-8
└─sdc2                                                                                              8:34   0    10G  0 part

查看journal分区是否链接好了

[root@test5 ~]# ll /var/lib/ceph/osd/*
/var/lib/ceph/osd/ceph-6:
total 60
-rw-r--r--   1 root root  481 Jun 16 14:17 activate.monmap
-rw-r--r--   1 ceph ceph    3 Jun 16 14:17 active
-rw-r--r--   1 ceph ceph   37 Jun 16 14:17 ceph_fsid
drwxr-xr-x 292 ceph ceph 8192 Jun 17 19:20 current
-rw-r--r--   1 ceph ceph   37 Jun 16 14:17 fsid
lrwxrwxrwx   1 ceph ceph   58 Jun 16 14:17 journal -> /dev/disk/by-partuuid/ac8846a1-e867-40d7-9bba-fa610160277a
-rw-r--r--   1 ceph ceph   37 Jun 16 14:17 journal_uuid
-rw-------   1 ceph ceph   56 Jun 16 14:17 keyring
-rw-r--r--   1 ceph ceph   21 Jun 16 14:17 magic
-rw-r--r--   1 ceph ceph    6 Jun 16 14:17 ready
-rw-r--r--   1 ceph ceph    4 Jun 16 14:17 store_version
-rw-r--r--   1 ceph ceph   53 Jun 16 14:17 superblock
-rw-r--r--   1 root root    0 Jun 16 15:16 sysvinit
-rw-r--r--   1 ceph ceph   10 Jun 16 14:17 type
-rw-r--r--   1 ceph ceph    2 Jun 16 14:17 whoami

异常处理
本次添加后新添加的osd并没有被拉起来,手动重启test5上的新增OSD,启动后weight(权重)为0

[root@test5 ~]# systemctl restart ceph-osd@6
[root@test5 ~]# systemctl restart ceph-osd@7
[root@test5 ~]# systemctl restart ceph-osd@8
[root@test5 ~]# ceph osd tree
ID WEIGHT  TYPE NAME      UP/DOWN REWEIGHT PRIMARY-AFFINITY
-1 2.58955 root default                                     
-2 1.29477     host test3                                   
 1 0.43159         osd.1       up  1.00000          1.00000
 2 0.43159         osd.2       up  1.00000          1.00000
 0 0.43158         osd.0       up  1.00000          1.00000
-3 1.29478     host test4                                   
 3 0.43159         osd.3       up  1.00000          1.00000
 4 0.43159         osd.4       up  1.00000          1.00000
 5 0.43159         osd.5       up  1.00000          1.00000
 6       0 osd.6               up  1.00000          1.00000
 7       0 osd.7               up  1.00000          1.00000
 8       0 osd.8               up  1.00000          1.00000

添加Bucket test5

 [root@test5 ~]# ceph osd crush add-bucket test5 host
added bucket test5 type host to crush map
[root@test5 ~]# ceph osd tree
ID WEIGHT  TYPE NAME      UP/DOWN REWEIGHT PRIMARY-AFFINITY
-4       0 host test5                                       
-1 2.58955 root default                                     
-2 1.29477     host test3                                   
 1 0.43159         osd.1       up  1.00000          1.00000
 2 0.43159         osd.2       up  1.00000          1.00000
 0 0.43158         osd.0       up  1.00000          1.00000
-3 1.29478     host test4                                   
 3 0.43159         osd.3       up  1.00000          1.00000
 4 0.43159         osd.4       up  1.00000          1.00000
 5 0.43159         osd.5       up  1.00000          1.00000
 6       0 osd.6               up  1.00000          1.00000
 7       0 osd.7               up  1.00000          1.00000
 8       0 osd.8               up  1.00000          1.00000

将OSD移到test5的host下面
注意添加OSD时的weight是该OSD的实际大小(2T为2 ,800G为0.8),切勿随意填写!!!

[root@test5 ~]# ceph osd crush add osd.6 0.43159 host=test5
add item id 6 name 'osd.6' weight 0.43159 at location {host=test5} to crush map
[root@test5 ~]# ceph osd tree
ID WEIGHT  TYPE NAME      UP/DOWN REWEIGHT PRIMARY-AFFINITY
-4 0.43158 host test5                                       
 6 0.43158     osd.6           up  1.00000          1.00000
-1 2.58955 root default                                     
-2 1.29477     host test3                                   
 1 0.43159         osd.1       up  1.00000          1.00000
 2 0.43159         osd.2       up  1.00000          1.00000
 0 0.43158         osd.0       up  1.00000          1.00000
-3 1.29478     host test4                                   
 3 0.43159         osd.3       up  1.00000          1.00000
 4 0.43159         osd.4       up  1.00000          1.00000
 5 0.43159         osd.5       up  1.00000          1.00000
 7       0 osd.7               up  1.00000          1.00000
 8       0 osd.8               up  1.00000          1.00000
[root@test5 ~]# ceph osd crush add osd.7 0.43159 host=test5
add item id 7 name 'osd.7' weight 0.43159 at location {host=test5} to crush map
[root@test5 ~]# ceph osd crush add osd.8 0.43159 host=test5
add item id 8 name 'osd.8' weight 0.43159 at location {host=test5} to crush map
[root@test5 ~]# ceph osd tree
ID WEIGHT  TYPE NAME      UP/DOWN REWEIGHT PRIMARY-AFFINITY
-4 1.29474 host test5                                       
 6 0.43158     osd.6           up  1.00000          1.00000
 7 0.43158     osd.7           up  1.00000          1.00000
 8 0.43158     osd.8           up  1.00000          1.00000
-1 2.58955 root default                                     
-2 1.29477     host test3                                   
 1 0.43159         osd.1       up  1.00000          1.00000
 2 0.43159         osd.2       up  1.00000          1.00000
 0 0.43158         osd.0       up  1.00000          1.00000
-3 1.29478     host test4                                   
 3 0.43159         osd.3       up  1.00000          1.00000
 4 0.43159         osd.4       up  1.00000          1.00000
 5 0.43159         osd.5       up  1.00000          1.00000

这个时候看起来就顺眼多了,但是存储还是不会调用的,需要将对应的host(test5)移到root下

[root@test5 ~]# ceph osd crush move test5 root=default
moved item id -4 name 'test5' to location {root=default} in crush map
[root@test5 ~]# ceph osd tree
ID WEIGHT  TYPE NAME      UP/DOWN REWEIGHT PRIMARY-AFFINITY
-1 3.88429 root default                                     
-2 1.29477     host test3                                   
 1 0.43159         osd.1       up  1.00000          1.00000
 2 0.43159         osd.2       up  1.00000          1.00000
 0 0.43158         osd.0       up  1.00000          1.00000
-3 1.29478     host test4                                   
 3 0.43159         osd.3       up  1.00000          1.00000
 4 0.43159         osd.4       up  1.00000          1.00000
 5 0.43159         osd.5       up  1.00000          1.00000
-4 1.29474     host test5                                   
 6 0.43158         osd.6       up  1.00000          1.00000
 7 0.43158         osd.7       up  1.00000          1.00000
 8 0.43158         osd.8       up  1.00000          1.00000

查看存储状态,由于新添加了三块OSD所以集群会做backfilling等pg迁移操作,等待集群OK即可。

[root@test5 ~]# ceph -s
    cluster 12741d27-7fbb-4a15-90a8-a73d78f0172d
     health HEALTH_WARN
            clock skew detected on mon.test5
            127 pgs backfill_wait
            2 pgs backfilling
            2 pgs degraded
            1 pgs peering
            1 pgs recovery_wait
            57 pgs stuck unclean
            recovery 4/670906 objects degraded (0.001%)
            recovery 379815/670906 objects misplaced (56.612%)
            crush map has legacy tunables (require argonaut, min is firefly)
            crush map has straw_calc_version=0
            Monitor clock skew detected
     monmap e3: 3 mons at {test3=10.0.0.3:6789/0,test4=10.0.0.4:6789/0,test5=10.0.0.5:6789/0}
            election epoch 36, quorum 0,1,2 test3,test4,test5
     osdmap e2477: 9 osds: 9 up, 9 in; 360 remapped pgs
            flags sortbitwise
      pgmap v3791033: 1088 pgs, 3 pools, 932 GB data, 234 kobjects
            1891 GB used, 2085 GB / 3977 GB avail
            4/670906 objects degraded (0.001%)
            379815/670906 objects misplaced (56.612%)
                 724 active+clean
                 232 active+remapped
                 127 active+remapped+wait_backfill
                   2 active+remapped+backfilling
                   1 peering
                   1 active+degraded
                   1 active+recovery_wait+degraded
recovery io 330 MB/s, 82 objects/s

删除osd
正常处理流程:
停止osd进程——将节点状态标记为out——从crush中移除节点——删除节点——删除节点认证
根据这个方法会触发两次迁移,一次是在节点osd out以后,一次是在crush remove以后。参考磨渣-删除OSD的正确方式,调整处理步骤能够减少一次数据迁移。

在ceph的集群当中关于节点的替换的问题,一直按照以前的方式进行的处理,处理的步骤如下:

调整OSD的CRUSH WEIGHT

ceph osd crush reweight osd.0 0.1

说明:这个地方如果想慢慢的调整就分几次将crush 的weight 减低到0 ,这个过程实际上是让数据不分布在这个节点上,让数据慢慢的分布到其他节点上,直到最终为没有分布在这个osd,并且迁移完成
这个地方不光调整了osd 的crush weight ,实际上同时调整了host 的 weight ,这样会调整集群的整体的crush 分布,在osd 的crush 为0 后, 再对这个osd的任何删除相关操作都不会影响到集群的数据的分布

停止OSD进程

systemctl stop ceph-osd@0

停止到osd的进程,这个是通知集群这个osd进程不在了,不提供服务了,因为本身没权重,就不会影响到整体的分布,也就没有迁移

将节点状态标记为out

ceph osd out osd.0

停止到osd的进程,这个是通知集群这个osd不再映射数据了,不提供服务了,因为本身没权重,就不会影响到整体的分布,也就没有迁移

从CRUSH中移除节点

ceph osd crush remove osd.0

这个是从crush中删除,因为已经是0了 所以没影响主机的权重,也就没有迁移了

删除节点

ceph osd rm osd.0

这个是从集群里面删除这个节点的记录

删除节点认证(不删除编号会占住)

ceph auth del osd.0

删除HOST节点
将OSD全部删除后,如果还需要在集群中删除该osd的host节点,可以使用该命令。

ceph osd crush rm test5
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 集群管理 每次用命令启动、重启、停止Ceph守护进程(或整个集群)时,必须指定至少一个选项和一个命令,还可能要指定...
    Arteezy_Xie阅读 19,833评论 0 19
  • 系统环境: centos73.10.0-514.26.2.el7.x86_64 机器数量:五台 硬盘:四块一块为系...
    think_lonely阅读 10,306评论 0 5
  • 一、概述 Ceph是一个分布式存储系统,诞生于2004年,最早致力于开发下一代高性能分布式文件系统的项目。随着云计...
    魏镇坪阅读 49,762评论 3 54
  • ceph简介 Ceph是一个分布式存储系统,诞生于2004年,是最早致力于开发下一代高性能分布式文件系统的项目。随...
    爱吃土豆的程序猿阅读 11,267评论 0 21
  • 在ceph中,数据是以PG为单位保存在osd中的,一般情况下一个osd会对应一块磁盘,在osd节点挂掉的情况下,如...
    羽煊阅读 6,872评论 0 0

友情链接更多精彩内容