Ceph 分布式存储 池管理
一、Ceph 数据组织结构
POOL
池是 Ceph 存储集群的逻辑分区,用于在通用名称标签下存储对象。 Ceph 为每个池分配特定数量放置
组 (PG),用于对对象进行分组以进行存储。
每个池具有以下可调整属性:
- 池 ID
- 池名称
- PG 数量
- CRUSH 规则,用于确定此池的 PG 映射
- 保护类型(复本或擦除编码)
- 与保护类型相关的参数
- 影响集群行为的各种标志
Place Group
PG 全称为Placement group, 是构成pool的子集, 也是一系列对象的集合。一个PG仅能属于一个Pool。
Ceph 将每个 PG 映射到一组 OSD。属于同一个 PG 的所有对象都返回相同的哈希结果。
PG 数量会影响ceph的性能:
- 如果pg数量过多,数据移动时,每个PG维护的数据量过少, ceph占用大量的cpu 和内存计算,影响集群正常客户端使用。
- 如果pg数量过少,单个pg存储的数据就越多,移动pg会占用大量带宽,影响集群客户端使用。
在以前版本中, PG的计算公式为:
- Ceph集群PG 总数 = (OSD 数 * 100) / 最大副本数
- 单个资源池PG总数 = (OSD 数 * 100) / 最大副本数 / 池数
以上公式中计算出的结果必须舍入到最接近2的N次幂的值。
一般情况下,PG数量设置遵循以下原则:
- 如果OSD少于5个时, PG 数量设置为128
- OSD数量大于5小于10时, PG数量设置为512
- OSD数量大于10小于50时, PG数量设置为4096
- 如果osd数量大于50,则需要借助工具进行计算,官方工具链接为: https://old.ceph.com/pgcac/。
映射对象到OSD
客户端在进行数据读写时, 仅需向ceph提供资源池(pool)的名称和对象ID。一个完整的对象由三部分
组成:对象ID、二进制数据、对象元数据。
- Ceph 客户端从 MON 获取最新的集群映射复本 。集群映射向客户端提供有关集群中所有 MON、
OSD 和 MDS 的信息,但不向客户提供对象的位置。 - 计算 PG ID。公式:PG ID=hash(Object ID)%(PG number)。
为了计算PG ID,Ceph需要知道对象存储池的名称和对象ID:根据池的名称获取池的PG数量,然后对Ceph对象 ID 做hash运算,最终计算出PG ID。 - Ceph 使用 CRUSH 算法确定PG 负责哪些 OSDs (Acting Set)。 Acting Set 中的 OSD 在 Up Set 中。 Up Set 中的第一个 OSD 是对象归置组的当前主 OSD,Up Set 中的其他 OSD 是辅助 OSD。
- Ceph 客户端直接跟主 OSD 通信以读写对象。
客户端访问ceph流程
- 客户端向MON集群发起连接请求。
- 客户端和MON建立连接后,它将索引最新版本的cluster map,从而获取到MON、 OSD和MDS的
信息,但不包括对象的存储位置。 - client根据CRUSH算法计算出对象对应的PG和OSD。
- client根据上步中计算得出主OSD的位置,然后和其进行通信,完成对象的读写。
Ceph 数据读取流程
- 客户端通过MON获取到cluster map。
- client通过cluster map获取到主OSD节点信息,并向其发送读取请求。
- 主OSD将client请求的数据返回给client。
Ceph 数据写入流程
- 客户端通过 MON 获取到 cluster map。
- 客户端通过cluster map获取到主OSD节点信息,并向其发送写入请求。
- 主OSD收到写入请求后,将数据写入,并向两个备OSD发起数据写入指令。
- 两个备OSD将数据写入后返回确认到主OSD。
- 主OSD收到所有备OSD写入完成后的确认后,向客户端返回写入完成的确认。
- 第一次当所有数据都写入OSD节点的缓存后,向client发送一次确认, client就会认为数据写入完成,继续进行后面操作。
- 第二次当所有数据都从缓存写入到磁盘后,再向client发送一次确认, client就会认为数据彻底写
入,从而根据需要删除对应的本地数据。
数据保护
Ceph 存储支持:复本池和纠删码池。
- replicated pool(复本池),通过将各个对象复本到多个 OSD 来发挥作用。此池类型会创建多个对象复本,需要较多存储空间,但其通过冗余提高了读取操作的可用性。
- Erasure code pool(纠删代码池) ,需要较少的存储空间和网络带宽,但因为要进行奇偶校验计
算,所以会占用较多的 CPU处理时间。
**注意:**池一旦创建完成,池的类型便无法更改。
池类型选择:
- 对于不需要频繁访问且不需要低延迟的数据,推荐使用纠删代码池。
- 对于需要频繁访问并且要具备快速读取性能的数据,推荐使用复本池。
二、创建池
创建复本池
Ceph 为每个对象创建多个复本来保护复本池中的数据。Ceph 使用CRUSH 故障域来确定存储数据的操作集的主要 OSD。然后,主要 OSD 会查找池的当前复本数量,并计算要写入对象的次要 OSD。在主要 OSD 收到写入确认并完成数据写入后,主要 OSD 会向 Ceph 客户端确认写入操作已成功。如果一个或多个 OSD 出现故障,这一过程可保护对象中的数据。
创建复本池语法:
bash
ceph osd pool create pool-name pg-num pgp-num replicated crush-rule-name
其中:
- pool_name,指定新池的名称。
- pg_num,指定池的放置组 (PG) 总数。
- pgp_num,指定池的有效放置组数量。将它设置为与 pg_num 相等。该值可省略。
- replicated,指定池的类型为复本池;如果命令中未包含此参数,这是默认值。
- crush-rule-name,指定池的 CRUSH 规则集的名称。
osd_pool_default_crush_replicated_ruleset 配置参数设置其默认值。
示例:
bash
[root@ceph1 ~]# ceph osd pool create pool_web 32 32 replicated
pool 'pool_web' created
[root@ceph1 ~]# ceph osd pool ls
device_health_metrics
pool_web
创建纠删代码池
纠删代码池使用纠删代码保护对象数据。 在纠删代码池中存储的对象分割为多个数据区块,这些数据区块存储在不同的 OSD 中。编码块的数量是根据数据块计算的,并存储在不同的 OSD 中。当 OSD 出现故障时,可利用编码块重构对象数据。主要 OSD 接收写入操作,然后将载荷编码为 K+M 块,并将它们发给纠删代码池中的次要OSD。
以下概括了纠删代码池的工作方式:
- 每个对象的数据分割为 k 个数据区块,计算出 m 个编码区块。
- 对象存储在总共 k + m 个 OSD 中。
- 编码区块大小与数据区块大小相同。
与复本相比,纠删代码使用存储容量的效率更高。复本池维护对象的 n 个复本,而纠删代码仅维护 k +
m 个区块。
例如,具有 3 个复本的复本池要使用 3 倍存储空间。而 k=4 和 m=2 的纠删代码池仅要使用 1.5 倍存储空
间。
支持以下 k+m 值,其对应的可用与原始比为:
- 4+2(比率为 1:1.5)
- 8+3(比率为 1:1.375)
- 8+4(比率为 1:1.5)
纠删代码池有效容量百分比:k / (k+m)。例如,如果用户有 64 个 OSD(每个 4 TB,总计 256 TB)并且 k=8 和 m=4,那么公式为 8 / (8+4) * 64 * 4 = 170.67。然后,将原始存储容量除以开销就能得出该比率。256 TB/170.67 TB 等于 1.5 比率。
创建纠删代码池语法:
bash
ceph osd pool create pool-name pg-num pgp-num erasure erasure-code-profile crush
rule-name
- **pool-name,**指定新池的名称。
- pg-num,指定池的放置组 (PG) 总数。
- pgp-num,指定池的有效放置组数量。通常而言,这应当与 PG 总数相等。
- erasure,指定池的类型是纠删代码池。
- erasure-code-profile,指定池使用的纠删代码配置文件的名称。默认情况下,Ceph 使用 default 配置文件。
- crush-rule-name 是要用于这个池的 CRUSH 规则集的名称。如果不设置,Ceph 将使用纠删代码
池配置文件中定义的规则集。
**纠删代码池无法使用对象映射功能。**对象映射是对象的一个索引,用于跟踪 rbd 对象的块会被分配到哪
里,可用于提高大小调整、导出、扁平化和其他操作的性能。
示例:
bash
[root@ceph1 ~]# ceph osd pool create pool_era 32 32 erasure
pool 'pool_era' created
[root@ceph1 ~]# ceph osd pool ls
device_health_metrics
pool_web
pool_era
查看默认纠删代码配置
bash
[root@ceph1 ~]# ceph osd erasure-code-profile ls
default
[root@ceph1 ~]# ceph osd erasure-code-profile get default
k=2
m=2
plugin=jerasure
technique=reed_sol_van
管理纠删代码配置文件
纠删代码配置文件可配置纠删代码池用于存储对象的数据区块和编码区块的数量,以及要使用的纠删代
码插件和算法。
创建纠删代码配置文件语法如下:
bash
ceph osd erasure-code-profile set profile-name arguments
可用的参数如下:
- **k,**在不同 OSD 之间拆分的数据区块数量。默认值为 2。
- m,数据变得不可用之前可以出现故障的 OSD 数量。默认值为 1。
- **directory,**此可选参数是插件库的位置。默认值为 /usr/lib64/ceph/erasure-code。
- plugin,此可选参数定义要使用的纠删代码算法。
- crush-failure-domain,此可选参数定义 CRUSH 故障域,它控制区块放置。默认设置为 host,这样可确保对象的区块放置到不同主机的 OSD 上。如果设置为 osd,则对象的区块可以放置到同一主机的 OSD 上。如果主机出现故障,则该主机上的所有 OSD 都会出现故障。故障域可用于确保将区块放置到不同数据中心机架或其他定制的主机上的 OSD 上。
- crush-device-class,此可选参数选择仅将这一类别设备支持的 OSD 用于池。典型的类别可能包括 hdd、ssd 或nvme。
- **crush-root,**此可选参数设置 CRUSH 规则集的根节点。
- key=value,插件可以具有对该插件唯一的键值参数。
- technique ,每个插件提供一组不同的技术来实施不同的算法。
示例:
bash
[root@ceph1 ~]# ceph osd erasure-code-profile set ceph k=4 m=2
列出现有的就删代码配置文件
bash
[root@ceph1 ~]# ceph osd erasure-code-profile ls
ceph
default
Ceph 会在安装期间创建 default 配置文件。这个配置文件已配置为将对象分割为2个数据区块和2个编码区块。
查看现有配置文件的详细信息
bash
[root@ceph1 ~]# ceph osd erasure-code-profile get ceph
crush-device-class=
crush-failure-domain=host
crush-root=default
jerasure-per-chunk-alignment=false
k=4
m=2
plugin=jerasure
technique=reed_sol_van
w=8
删除现有的配置文件
bash
[root@ceph1 ~]# ceph osd erasure-code-profile rm ceph
[root@ceph1 ~]# ceph osd erasure-code-profile ls
default
重要:现有纠删代码配置文件是无法修改或更改,只能创建新的配置文件。
三、管理 池
使用 ceph osd pool ls 命令,可以列出池清单。
bash
[root@ceph1 ~]# ceph osd pool ls
device_health_metrics
pool_web
pool_era
使用 ceph osd pool ls detail 命令,可以列出池清单和池的详细配置。
bash
[root@ceph1 ~]# ceph osd pool ls detail
pool 1 'device_health_metrics' replicated size 3 min_size 2 crush_rule 0
object_hash rjenkins pg_num 1 pgp_num 1 autoscale_mode on last_change 31 flags
hashpspool stripe_width 0 pg_num_max 32 pg_num_min 1 application mgr_devicehealth
pool 2 'pool_web' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins
pg_num 32 pgp_num 32 autoscale_mode on last_change 34 flags hashpspool
stripe_width 0
pool 3 'pool_era' erasure profile default size 4 min_size 3 crush_rule 1
object_hash rjenkins pg_num 32 pgp_num 32 autoscale_mode on last_change 41 flags
hashpspool stripe_width 8192
使用 ceph osd lspools 命令,也可以列出池清单。
bash
[root@ceph1 ~]# ceph osd lspools
1 device_health_metrics
2 pool_web
3 pool_era
使用 ceph osd pool stats 命令,可以列出池状态信息,池被哪些客户端使用。
bash
[root@ceph1 ~]# ceph osd pool stats
pool device_health_metrics id 1
nothing is going on
pool pool_web id 2
nothing is going on
pool pool_era id 3
nothing is going on
使用 ceph df 命令,可以查看池容量使用信息.
bash
[root@ceph1 ~]# ceph df--- RAW STORAGE --
CLASS SIZE hdd AVAIL
USED RAW USED %RAW USED
180 GiB 177 GiB 2.6 GiB 2.6 GiB
TOTAL 180 GiB 177 GiB 2.6 GiB 2.6 GiB
四、管理 池 中对象
管理 池 应用类型
使用 ceph osd pool application 命令,管理池 Ceph 应用类型。应用类型有cephfs(用于 Ceph 文件系统) 、rbd(Ceph 块设备)和 rgw(RADOS 网关)。
bash
[root@ceph1 ~]# ceph osd pool application <tab><tab>
disable enable get
rm
set
# 启用池的类型为rbd
[root@ceph1 ~]# ceph osd pool application enable pool_web rbd
enabled application 'rbd' on pool 'pool_web'
[root@ceph1 ~]# ceph osd pool ls detail | grep pool_web
pool 2 'pool_web' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins
pg_num 32 pgp_num 32 autoscale_mode on last_change 44 flags hashpspool
stripe_width 0 `application rbd` <------ #看这的变化
# 使用set子命令,设置池的应用类型详细配置
[root@ceph1 ~]# ceph osd pool application set pool_web rbd app1 apache
set application 'rbd' key 'app1' to 'apache' on pool 'pool_web'
# 这里添加的设置,app1=apache仅供参考,没有实际意义。
# 使用get子命令,查看池的应用类型详细配置
[root@ceph1 ~]# ceph osd pool application get pool_web
{
"rbd": {
"app1": "apache"
}
}
# 使用rm子命令,删除池的应用类型详细配置
[root@ceph1 ~]# ceph osd pool application rm pool_web rbd app1
removed application 'rbd' key 'app1' on pool 'pool_web'
[root@ceph1 ~]# ceph osd pool application get pool_web
{
"rbd": {}
}
# 禁用池的类型
[root@ceph1 ~]# ceph osd pool application disable pool_web rbd --yes-i-really
mean-it
disable application 'rbd' on pool 'pool_web'
[root@ceph1 ~]# ceph osd pool ls detail | grep pool_web
pool 2 'pool_web' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins
pg_num 32 pgp_num 32 autoscale_mode on last_change 47 flags hashpspool
stripe_width 0
管理 池 配额
使用 ceph osd pool get-quota 命令,获取池配额信息:池中能够存储的最大字节数或最大对象数量。
bash
[root@ceph1 ~]# ceph osd pool get-quota pool_web
quotas for pool 'pool_web':
max objects: N/A
max bytes : N/A
使用 ceph osd pool set-quota 命令,可以设置池配额来限制池中能够存储的最大字节数或最大对象数
量。
当存储对象达到限额是,整个池会无法使用
bash
[root@ceph1 ~]# ceph osd pool set-quota pool_web max_objects 100000
set-quota max_objects = 100000 for pool pool_web
[root@ceph1 ~]# ceph osd pool set-quota pool_web max_bytes 10G
set-quota max_bytes = 10737418240 for pool pool_web
[root@ceph1 ~]# ceph osd pool get-quota pool_web
quotas for pool 'pool_web':
max objects: 100k objects (current num objects: 0 objects)
max bytes : 10 GiB (current num bytes: 0 bytes)
当池使用量达到池配额时,操作将被阻止。用户可通过将该值设置为 0 来删除配额.
bash
[root@ceph1 ~]# ceph osd pool set-quota pool_web max_objects 0
set-quota max_objects = 0 for pool pool_web
[root@ceph1 ~]# ceph osd pool set-quota pool_web max_bytes 0
set-quota max_bytes = 0 for pool pool_web
[root@ceph1 ~]# ceph osd pool get-quota pool_web
quotas for pool 'pool_web':
max objects: N/A
max bytes : N/A
管理 池 配置
查看池配置
使用 ceph osd pool get 命令,查看池配置。
bash
# 查看池所有配置
[root@ceph1 ~]# ceph osd pool get pool_web all
size: 3
min_size: 2
pg_num: 32
pgp_num: 32
crush_rule: replicated_rule
hashpspool: true
nodelete: false
nopgchange: false
nosizechange: false
write_fadvise_dontneed: false
noscrub: false
nodeep-scrub: false
use_gmt_hitset: 1
fast_read: 0
pg_autoscale_mode: on
bulk: false
#副本数3
# 查看池特定配置
[root@ceph1 ~]# ceph osd pool get pool_web nodelete
nodelete: false
# 备用命令
[root@ceph1 ~]# ceph osd pool get pool_web all | grep nodelete
nodelete: false
设置池配置
使用 ceph osd pool set 命令,可以修改池配置选项。
bash
# 设置池不可删除
[root@ceph1 ~]# ceph osd pool set pool_web nodelete true
set pool 2 nodelete to true
[root@ceph1 ~]# ceph osd pool get pool_web nodelete
nodelete: true
# 将 nodelete 重新设置为 FALSE,即可允许删除池
root@ceph1 ~]# ceph osd pool set pool_web nodelete false
set pool 2 nodelete to false
[root@ceph1 ~]# ceph osd pool get pool_web nodelete
nodelete: false
管理 池 复本数
使用以下命令,更改池的复本数量。
bash
[root@ceph1 ~]# ceph osd pool set pool_web size 2
set pool 2 size to 2
#2 size to 2???没变,别闹这里说的时pool2 的size 变成2,
pool2是谁??
[root@ceph1 ~]# ceph osd pool get pool_web all
size: 2
#这里确实从之前的3变成了2
min_size: 1
pg_num: 32
pgp_num: 32
crush_rule: replicated_rule
hashpspool: true
nodelete: false
nopgchange: false
nosizechange: false
write_fadvise_dontneed: false
noscrub: false
nodeep-scrub: false
use_gmt_hitset: 1
fast_read: 0
pg_autoscale_mode: on
bulk: false
池的默认复本数量由 osd_pool_default_size 配置参数定义,默认值为 3。
bash
[root@ceph1 ~]# ceph config get mon osd_pool_default_size
3
使用以下命令定义创建新池的默认复本数量。
bash
[root@ceph1 ~]# ceph config set mon osd_pool_default_size 2
[root@ceph1 ~]# ceph config get mon osd_pool_default_size
2
osd_pool_default_min_size 参数定义集群必须提供多少个对象复本才能接受 I/O 请求。复本数为3的池,该值为2;复本数为2的池,该值为1。
使用以下命令定义池的最小复本数量。
bash
[root@ceph1 ~]# ceph config get mon osd_pool_default_min_size
0
#参数值为0是特殊设置,意味着集群将自动使用存储池
的size值作为最小副本数,举例说明:如果某存储池size=3,那么min_size会自动设为2(即size/2+1取
整)
[root@ceph1 ~]# ceph config set mon osd_pool_default_min_size 1
[root@ceph1 ~]# ceph config get mon osd_pool_default_min_size
1
管理 池 PG 数
使用以下命令,更改池 PG 数量。
bash
[root@ceph1 ~]# ceph osd pool set pool_web pg_num 64
适???
set pool 2 pg_num to 64
[root@ceph1 ~]# ceph osd pool get pool_web all
size: 2
min_size: 1
pg_num: 64
pgp_num: 64
crush_rule: replicated_rule
hashpspool: true
nodelete: false
nopgchange: false
nosizechange: false
write_fadvise_dontneed: false
noscrub: false
nodeep-scrub: false
use_gmt_hitset: 1
fast_read: 0
pg_autoscale_mode: on
bulk: false
**Ceph 存储默认在池上配置放置组自动扩展。**自动扩展允许集群计算放置组的数量,并且自动选择适当的 pg_num 值。
集群中的每个池都有一个 pg_autoscale_mode 选项,其值可以是 on、off 或 warn。
- on:启用自动调整池的 PG 数。
- off:禁用池的 PG 自动扩展。
- warn:在 PG 数需要调整时引发运行状况警报并将集群运行状况更改为 HEALTH_WARN。
集群配置放置组自动扩展,需要在 Ceph MGR 节点上启用 pg_autoscaler 模块 ,并将池的自动扩展模式
设置为 on:
bash
[root@ceph1 ~]# ceph mgr module enable pg_autoscaler
module 'pg_autoscaler' is already enabled (always-on)
[root@ceph1 ~]# ceph osd pool set pool_web pg_autoscale_mode off
pb_autoscale_mode设置为off
set pool 2 pg_autoscale_mode to off
[root@ceph1 ~]# ceph osd pool autoscale-status
[root@ceph1 ~]# ceph osd pool set pool_web pg_autoscale_mode on
set pool 2 pg_autoscale_mode to on
[root@ceph1 ~]# ceph osd pool autoscale-status
POOL SIZE TARGET SIZE RATE RAW CAPACITY RATIO TARGET
RATIO EFFECTIVE RATIO BIAS PG_NUM NEW PG_NUM AUTOSCALE BULK
device_health_metrics 0 3.0 179.9G 0.0000
1.0 1 on False
pool_web 0 2.0 179.9G 0.0000
1.0 64 on False
pool_era 0 2.0 179.9G 0.0000
1.0 32 on False
管理 池 的对象
cephdos命令管理池的对象。
bash
[root@ceph1 ~]# rados -h
usage: rados [options] [commands]
POOL COMMANDS
lspools list pools
cppool <pool-name> <dest-pool> copy content of a pool
purge <pool-name> --yes-i-really-really-mean-it
remove all objects from pool <pool-name>
without removing it
df show per-pool and total usage
ls list objects in pool
POOL SNAP COMMANDS
lssnap list snaps
mksnap <snap-name> create snap <snap-name>
rmsnap <snap-name> remove snap <snap-name>
OBJECT COMMANDS
get <obj-name> <outfile> fetch object
put <obj-name> <infile> [--offset offset]
write object with start offset (default:0)
append <obj-name> <infile> append object
truncate <obj-name> length truncate object
create <obj-name> create object
rm <obj-name> ... [--force-full] remove object(s), --force-full forces remove
when cluster is full
cp <obj-name> [target-obj] copy object
listxattr <obj-name>
getxattr <obj-name> attr
setxattr <obj-name> attr val
rmxattr <obj-name> attr
stat <obj-name> stat the named object
stat2 <obj-name> stat2 the named object (with high precision
time)
touch <obj-name> [timestamp] change the named object modification time
mapext <obj-name>
rollback <obj-name> <snap-name> roll back object to snap <snap-name>
listsnaps <obj-name> list the snapshots of this object
bench <seconds> write|seq|rand [-t concurrent_operations] [--no-cleanup] [--
run-name run_name] [--no-hints] [--reuse-bench]
default is 16 concurrent IOs and 4 MB ops
default is to clean up after write benchmark
default run-name is 'benchmark_last_metadata'
cleanup [--run-name run_name] [--prefix prefix]
clean up a previous benchmark operation
default run-name is 'benchmark_last_metadata'
load-gen [options] generate load on the cluster
listomapkeys <obj-name> list the keys in the object map
listomapvals <obj-name> list the keys and vals in the object map
getomapval <obj-name> <key> [file] show the value for the specified key
in the object's object map
setomapval <obj-name> <key> <val | --input-file file>
rmomapkey <obj-name> <key>
clearomap <obj-name> [obj-name2 obj-name3...] clear all the omap keys for the
specified objects
getomapheader <obj-name> [file]
setomapheader <obj-name> <val>
watch <obj-name> add watcher on this object
notify <obj-name> <message> notify watcher of this object with message
listwatchers <obj-name> list the watchers of this object
set-alloc-hint <obj-name> <expected-object-size> <expected-write-size>
set allocation hint for an object
set-redirect <object A> --target-pool <caspool> <target object A> [--with
reference]
set redirect target
set-chunk <object A> <offset> <length> --target-pool <caspool> <target object
A> <taget-offset> [--with-reference]
convert an object to chunked object
tier-promote <obj-name> promote the object to the base tier
unset-manifest <obj-name> unset redirect or chunked object
tier-flush <obj-name> flush the chunked object
tier-evict <obj-name> evict the chunked object
IMPORT AND EXPORT
export [filename]
Serialize pool contents to a file or standard out.
import [--dry-run] [--no-overwrite] < filename | - >
Load pool contents from a file or standard in
ADVISORY LOCKS
lock list <obj-name>
List all advisory locks on an object
lock get <obj-name> <lock-name> [--lock-cookie locker-cookie] [--lock-tag
locker-tag] [--lock-description locker-desc] [--lock-duration locker-dur] [--
lock-type locker-type]
Try to acquire a lock
lock break <obj-name> <lock-name> <locker-name> [--lock-cookie locker-cookie]
Try to break a lock acquired by another client
lock info <obj-name> <lock-name>
Show lock information
options:
--lock-tag Lock tag, all locks operation should use
the same tag
--lock-cookie Locker cookie
--lock-description Description of lock
--lock-duration Lock duration (in seconds)
--lock-type Lock type (shared, exclusive)
SCRUB AND REPAIR:
list-inconsistent-pg <pool> list inconsistent PGs in given pool
list-inconsistent-obj <pgid> list inconsistent objects in given PG
list-inconsistent-snapset <pgid> list inconsistent snapsets in the given PG
CACHE POOLS: (for testing/development only)
cache-flush <obj-name> flush cache pool object (blocking)
cache-try-flush <obj-name> flush cache pool object (non-blocking)
cache-evict <obj-name> evict cache pool object
cache-flush-evict-all flush+evict all objects
cache-try-flush-evict-all try-flush+evict all objects
GLOBAL OPTIONS:
--object-locator object_locator
set object_locator for operation
-p pool
--pool=pool
select given pool by name
--target-pool=pool
select target pool by name
--pgid PG id
select given PG id
-f [--format plain|json|json-pretty]
--format=[--format plain|json|json-pretty]
-b op_size
set the block size for put/get ops and for write benchmarking
-O object_size
set the object size for put/get ops and for write benchmarking
--max-objects
set the max number of objects for write benchmarking
--obj-name-file file
use the content of the specified file in place of <obj-name>
-s name
--snap name
select given snap name for (read) IO
--input-file file
use the content of the specified file in place of <val>
--create
create the pool or directory that was specified
-N namespace
--namespace=namespace
specify the namespace to use for the object
--all
Use with ls to list objects in all namespaces
Put in CEPH_ARGS environment variable to make this the default
--default
Use with ls to list objects in default namespace
Takes precedence over --all in case --all is in environment
--target-locator
Use with cp to specify the locator of the new object
--target-nspace
Use with cp to specify the namespace of the new object
--striper
Use radostriper interface rather than pure rados
Available for stat, get, put, truncate, rm, ls and
all xattr related operations
BENCH OPTIONS:
-t N
--concurrent-ios=N
Set number of concurrent I/O operations
--show-time
prefix output with date/time
--no-verify
do not verify contents of read objects
--write-object
write contents to the objects
--write-omap
write contents to the omap
--write-xattr
write contents to the extended attributes
LOAD GEN OPTIONS:
--num-objects total number of objects
--min-object-size min object size
--max-object-size max object size
--min-op-len min io size of operations
--max-op-len max io size of operations
--max-ops max number of operations
--max-backlog max backlog size
--read-percent percent of operations that are read
--target-throughput target throughput (in bytes)
--run-length total time (in seconds)
--offset-align at what boundary to align random op offsets
CACHE POOLS OPTIONS:
--with-clones include clones when doing flush or evict
OMAP OPTIONS:
--omap-key-file file read the omap key from a file
GENERIC OPTIONS:
--conf/-c FILE read configuration from the given configuration file
--id ID
set ID portion of my name--name/-n TYPE.ID set name--cluster NAME
set cluster name (default: ceph)--setuser USER
set uid to user or uid (and gid to user's gid)--setgroup GROUP set gid to group or gid--version
show version and quit
这里我们主要讲解池中对象操作。
上传对象到池中
bash
[root@ceph1 ~]# echo laogao1 > hosts1
[root@ceph1 ~]# rados -p pool_web put hosts hosts1 #将host1文件上传到webapp池取名
为hosts
[root@ceph1 ~]# rados -p pool_web ls
hosts
查看池中对象状态
bash
[root@ceph1 ~]# rados -p pool_web stat hosts
pool_web/hosts mtime 2025-08-21T09:52:43.000000+0800, size 8
查看池中对象存储在哪里
bash
[root@ceph1 ~]# ceph osd map pool_web hosts
[root@ceph1 ~]# ceph osd metadata osd.4
[root@ceph1 ~]# ceph pg dump pgs_brief
检索对象到本地
bash
[root@ceph1 ~]# rados -p pool_web get hosts newhosts
[root@ceph1 ~]# cat newhosts
laogao1
追加池中对象
bash
[root@ceph1 ~]# echo laogao2 >> hosts2
[root@ceph1 ~]# rados append -p pool_web hosts hosts2
[root@ceph1 ~]# rados get hosts newhosts -p pool_web
[root@ceph1 ~]# cat newhosts
laogao1
laogao2
删除池中对象
bash
[root@ceph1 ~]# rados put passwd /etc/passwd -p pool_web
[root@ceph1 ~]# rados ls -p pool_web
passwd
hosts
[root@ceph1 ~]# rados rm passwd -p pool_web
[root@ceph1 ~]# rados ls -p pool_web
hosts
管理 池 快照
使用 ceph osd pool mksnap 命令,创建池快照。
bash
[root@ceph1 ~]# ceph osd pool mksnap pool_web snap1 #给池pool_web拍摄快照snap1-
created pool pool_web snap snap1
[root@ceph1 ~]# rados -p pool_web listsnaps hosts
hosts:
cloneid snaps size
head
#拍摄快照后,上传新的内容到hosts中
[root@ceph1 ~]# echo laogao3 > hosts3
[root@ceph1 ~]# rados -p pool_web put hosts hosts3
[root@ceph1 ~]# rados -p pool_web get hosts newhosts
[root@ceph1 ~]# cat newhosts
laogao3
# 查看快照中对象
[root@ceph1 ~]# rados ls -p pool_web -s snap1
selected snap 3 'snap1'
hosts
# 获取快照中对象
[root@ceph1 ~]# rados -p pool_web -s snap1 get hosts hosts-from-snap1
selected snap 3 'snap1'
[root@ceph1 ~]# cat hosts-from-snap1 #发现即使hosts文件拍摄快照后变了,从快照获取的依然没变
laogao1
laogao2
# 恢复对象内容为指定快照时内容
[root@ceph1 ~]# rados -p pool_web rollback hosts snap1
rolled back pool pool_web to snapshot snap1
[root@ceph1 ~]# rados -p pool_web get hosts newhosts
[root@ceph1 ~]# cat newhosts
laogao1
laogao2
**快照是只读文件系统,**无法上传和删除快照中对象。
bash
[root@ceph1 ~]# rados put -p pool_web -s snap1 passwd /etc/passwd
selected snap 3 'snap1'
error putting pool_web/passwd: (30) Read-only file system
[root@ceph1 ~]# rados ls -p pool_web -s snap1
selected snap 3 'snap1'
hosts
[root@ceph1 ~]# rados rm -p pool_web -s snap1 hosts
selected snap 3 'snap1'
error removing pool_web>hosts: (30) Read-only file system
管理 池 命名空间
Ceph可以将整个池提供给特定应用。随着应用增加,池的数量也增加。
建议每个 OSD 关联的PG数量为100-200。由于集群中 OSD 数量是有限的,所以PG的数量也是有限的。创建的池越多,导致池能够分配的PG数量越少,每个PG 将会为更多的对象映射到OSD磁盘,进而导致每个 PG 的计算开销更高(负载更高),从而降低 OSD 性能。
使用命名空间,可以对池中对象进行逻辑分组,还可以限制用户只能存储或检索池中特定命名空间内的对象。借助命名空间,可以让多个应用使用同一个池,而且不必将整个池专用于各个应用,从而确保池的数量不会太多。
命名空间目前仅支持直接使用 librados 的应用。RBD 和 Ceph 对象网关客户端目前不支持此功能。
若要在命名空间内存储对象,客户端应用必须提供池和命名空间的名称。默认情况下,每个池包含一个具有空名称的命名空间,称为默认命名空间。
示例:
bash
[root@ceph1 ~]# rados put -p pool_web -N myns1 hostname1 /etc/hostname
[root@ceph1 ~]# rados ls -p pool_web
hosts
[root@ceph1 ~]# rados ls -p pool_web -N myns1
#上传的hsotname1在namespace
myns1中
hostname1
[root@ceph1 ~]# rados put -p pool_web -N myns2 hostname2 /etc/hostname
[root@ceph1 ~]# rados ls -p pool_web -N myns2
hostname2
[root@ceph1 ~]# rados ls -p pool_web --all
myns1
hostname1
hosts
myns2
hostname2
[root@ceph1 ~]# rados ls -p pool_web --all --format=json-pretty
[
{
"namespace": "myns1",
"name": "hostname1"
},
{
"namespace": "",
"name": "hosts"
},
{
"namespace": "myns2",
"name": "hostname2"
}
]
删除池
使用 ceph osd pool delete 命令,删除池。
bash
[root@ceph1 ~]# ceph osd pool rm pool_apache
Error EPERM: WARNING: this will *PERMANENTLY DESTROY* all data stored in pool
pool_apache. If you are *ABSOLUTELY CERTAIN* that is what you want, pass the
pool name *twice*, followed by --yes-i-really-really-mean-it.
要将pool name输入两次,跟上参数--yes-i-really-really-mean-it
#根据提示需
[root@ceph1 ~]# ceph osd pool rm pool_apache pool_apache --yes-i-really-really
mean-it
Error EPERM: pool deletion is disabled; you must first set the
mon_allow_pool_delete config option to true before you can destroy a pool
#提示需要先将mon_allow_pool_delete选项配置为true才能删除pool
必须将集群级别 mon_allow_pool_delete 设置为 TRUE 才能删除池。
bash
[root@ceph1 ~]# ceph config set mon mon_allow_pool_delete true
[root@ceph1 ~]# ceph config get mon mon_allow_pool_delete
true
[root@ceph1 ~]# ceph osd pool rm pool_apache pool_apache --yes-i-really-really
mean-it
pool 'pool_apache' removed
重要:删除池会删除池中的所有数据,而且不可逆转。
还可以通过设置池 nodelete 属性为 yes ,防止池被误删除。
bash
# ceph osd pool set pool_apache nodelete true