Ceph 常用命令行汇总

ceph 基础命令

查看版本:

# ceph -v
ceph version 15.2.4 (7447c15c6ff58d7fce91843b705a268a1917325c) octopus (stable)

查看集群状态:

# ceph -s
  cluster:
    id:     dacae2ee-013b-413c-83c9-7c1b96ec84f1
    health: HEALTH_WARN
            Degraded data redundancy: 32 pgs undersized

  services:
    mon: 2 daemons, quorum a,b (age 6d)
    mgr: a(active, since 2w)
    osd: 3 osds: 3 up (since 2w), 3 in (since 5w); 1 remapped pgs

  data:
    pools:   2 pools, 33 pgs
    objects: 3 objects, 0 B
    usage:   3.1 GiB used, 11 TiB / 11 TiB avail
    pgs:     3/9 objects misplaced (33.333%)
             32 active+undersized
             1  active+clean+remapped

查看磁盘占用:

$ ceph df
--- RAW STORAGE ---
CLASS  SIZE    AVAIL   USED    RAW USED  %RAW USED
hdd    11 TiB  11 TiB  69 MiB   3.1 GiB       0.03
TOTAL  11 TiB  11 TiB  69 MiB   3.1 GiB       0.03

--- POOLS ---
POOL                   ID  STORED  OBJECTS  USED     %USED  MAX AVAIL
device_health_metrics   1  30 KiB        3   90 KiB      0    3.5 TiB
test                    2     0 B        0      0 B      0    3.5 TiB
kcha                    3   691 B        4  256 KiB      0    5.2 TiB

ceph auth 命令

获取 Ceph ceph.client.admin.keyring 并生成 secret key:

# ceph auth get client.admin
exported keyring for client.admin
[client.admin]
        key = AQAKThlfDW+2IxAApUzJ34ftDmNMUaDiV/SB0A==
        caps mds = "allow *"
        caps mgr = "allow *"
        caps mon = "allow *"
        caps osd = "allow *"

k8s secret 认证 key 需要使用 base64 编码:

# echo "AQAKThlfDW+2IxAApUzJ34ftDmNMUaDiV/SB0A==" | base64
QVFBS1RobGZEVysySXhBQXBVekozNGZ0RG1OTVVhRGlWL1NCMEE9PQo=

以上两步可以合并为:

# ceph auth get-key client.admin |base64
QVFBS1RobGZEVysySXhBQXBVekozNGZ0RG1OTVVhRGlWL1NCMEE9PQ==

ceph osd 命令

OSD 全称 Object Storage Device,也就是负责响应客户端请求返回具体数据的进程。

查看 osd 状态

# ceph osd status
ID  HOST   USED  AVAIL  WR OPS  WR DATA  RD OPS  RD DATA  STATE
 0  host1  1045M  3724G      0        0       0        0   exists,up
 1  host2  1045M  3724G      0        0       0        0   exists,up
 2  host3  1045M  3724G      0        0       0        0   exists,up

查看 osd 目录树

# ceph osd tree
ID  CLASS  WEIGHT    TYPE NAME                    STATUS  REWEIGHT  PRI-AFF
-1         10.91460  root default
-3          7.27640      host host1
 0    hdd   3.63820          osd.0                    up   1.00000  1.00000
 1    hdd   3.63820          osd.1                    up   1.00000  1.00000
-5          3.63820      host host2
 2    hdd   3.63820          osd.2                    up   1.00000  1.00000

列出存储池

$ ceph osd lspools
1 device_health_metrics
2 test
3 kcha

ceph mon 命令

查看 mon 状态:

# ceph mon stat
e2: 2 mons at {a=[v2:172.18.32.119:3300/0,v1:172.18.32.119:6789/0],b=[v2:172.18.83.170:3300/0,v1:172.18.83.170:6789/0]}, election epoch 16, leader 0 a, quorum 0,1 a,b

ceph pg 命令

查看 pg 状态:

# ceph pg stat
33 pgs: 1 active+clean+remapped, 32 active+undersized; 0 B data, 63 MiB used, 11 TiB / 11 TiB avail; 3/9 objects misplaced (33.333%)

rados 命令

# rados df
POOL_NAME                USED  OBJECTS  CLONES  COPIES  MISSING_ON_PRIMARY  UNFOUND  DEGRADED  RD_OPS       RD  WR_OPS       WR  USED COMPR  UNDER COMPR
device_health_metrics  90 KiB        3       0       9                   0        0         0     104  104 KiB     108  108 KiB         0 B          0 B
test                      0 B        0       0       0                   0        0         0       0      0 B       0      0 B         0 B          0 B

total_objects    3
total_used       3.1 GiB
total_avail      11 TiB
total_space      11 TiB