天天看點

ceph rados指令使用

文章目錄

  • ​​Pool相關​​
  • ​​Object相關​​
  • ​​導出資源池資料​​

最近了解了rados指令的使用,感覺在對象操作這塊還是非常實用。因為rados是屬于底層存儲核心,是以關于rados的指令針對對象的操作較多。

環境中執行

​rados -h​

​可以看到指令集分為幾個大的子產品:資源池、對象、以及一些全局選項 該指令用來做對象相關測試較為友善,可以操作單個對象,同時使用

​rados bench​

​指令進行叢集io性能測試較多。本文不對

​rados bench​

​進行講解,詳細可以參考

​​io性能工具​

目前rados指令是基于ceph 12.2.1 版本描述的,如過更高版本有更新的指令,歡迎大家補充。
Pool相關
  • 顯示資源池清單

    ​​

    ​rados lspools​

  • 建立資源池

    ​rados mkpool pool1 auid rule_id​

rados mkpool pool1 12 2 #建立一個名稱為pool1的資源池,執行該資源池的rule編号為2,使用者編号為1 
setting auid:12
using crush rule 2
successfully created pool test      
  • 資源池資料拷貝

    ​​

    ​rados cppool pool1 pool2​

    ​,将pool1的資源池資料拷貝到pool2的資料資源池
  • 删除資源池

    ​​

    ​rados rmpool pool1 pool1 --yes-i-really-really-mean-it​

  • 清除資源池資料

    ​​

    ​rados purge pool1 --yes-i-really-really-mean-it​

  • 檢視資源池資訊

    ​rados df -p pool1​

    ​ -p參數是指定具體資源池,如果不加,則顯示所有
[root@node1 ~]# rados df -p data
POOL_NAME USED OBJECTS CLONES COPIES MISSING_ON_PRIMARY UNFOUND DEGRADED RD_OPS RD    WR_OPS  WR    
data      662G   51636      0 619632                  0       0        0  48547 7745M 1653358 1274G 

total_objects    51883
total_used       2195G
total_avail      215T
total_space      217T      
  • 列出資源池對象編号

    ​rados ls -p poo1​

    ​,同樣指定列出pool1資源池對象,否則列出所有
[root@node1 ~]# rados ls -p data|less
10000004481.00000002
10000001b2f.00000000
100000042f9.00000006
10000004f62.00000001
10000003e8c.00000003      
  • 修改資源池的使用者編号,即auid

    ​​

    ​rados chown auid​

Object相關
  • 擷取對象内容​

    ​get​

    ​​

    ​rados -p data get 10000006b70.00000005 test.txt​

    ​該指令需要指定資源池以及對象内容的輸出檔案,對象名稱可以通過​

    ​rados ls​

    ​指令擷取
[root@node1 ~]# rados -p data get 10000006b70.00000005 test.txt
[root@node1 ~]# cat test.txt  #該對象内容是一些時間戳
161-20:45:49:35
162-20:45:49:536
163-20:45:50:53
164-20:45:50:575
165-20:45:51:83
166-20:45:51:602
167-20:45:52:114
168-20:45:52:623
169-20:45:53:129
170-20:45:53:636
171-20:45:54:150      
  • 将指定檔案作為對象寫入到資源池 ​

    ​put​

    ​​

    ​rados -p test_rep_pool put obj_name test.txt​

    ​将test.txt以obj_name為名稱
#寫入之前的對象數
 data:
pools:   2 pools, 256 pgs
objects: 2 objects, 19B
usage:   15.0GiB used, 96.4TiB / 96.4TiB avail
pgs:     256 active+clean

#寫入之後的對象數
data:
pools:   2 pools, 256 pgs
objects: 3 objects, 2.78MiB
usage:   15.0GiB used, 96.4TiB / 96.4TiB avail
pgs:     256 active+clean
#檢視對象清單如下
[root@node1 ~]# rados -p test_rep_pool ls
obj_name      

此外,該指令可以指定寫入對象的偏移量,預設是從0開始,我可以指定具體的偏移量,機關為B

​​

​rados -p test_rep_pool put obj_name test.txt --offset 1048576​

​,我設定的是從起始位址偏移1M,執行結果如下

data:
pools:   2 pools, 256 pgs
objects: 3 objects, 3.78MiB #本應該是2.78M,我偏移了1M開始寫,現在變為3.78M  
usage:   15.0GiB used, 96.4TiB / 96.4TiB avail
pgs:     256 active+clean      

這個指令極大得友善我們去測試分析bluestore 的io流程

  • 向指定對象追加内容​

    ​append​

    ​​

    ​rados -p test_rep_pool append obj_name ceph-osd.16.log​

  • 删除指定長度對象内容​

    ​truncate​

    ​​

    ​rados -p test_rep_pool truncate obj_name 524288​

    ​ 删除obj_name 對象512kb的容量
  • 建立對象​

    ​create​

    ​​

    ​rados -p test_rep_pool create obj_name2​

    ​這裡是建立了一個空對象
[root@node1 ~]# rados -p test_rep_pool ls
obj_name2
obj_name
[root@node1 ~]# rados -p test_rep_pool stat obj_name2 #顯示對象資訊,包括所在資源池。修改修改時間,大小
test_rep_pool/obj_name2 mtime 2019-05-10 21:12:40.000000, size 0      
  • 删除指定對象​

    ​rm​

    ​​

    ​rados -p test_rep_pool rm obj_name2​

    ​ 或者加​

    ​--force-full​

    ​時強制删除一個對象,不在乎對象此時狀态
  • 拷貝對象​

    ​cp​

    ​​

    ​rados -p test_rep_pool cp obj_name test_cp_obj​

[root@node1 ~]# rados -p test_rep_pool cp obj_name test_cp_obj
[root@node1 ~]# rados -p test_rep_pool ls
obj_name2
test_cp_obj
obj_name
#檢視這兩個對象的資訊,可以看到已經成功拷貝
[root@node1 ~]# rados -p test_rep_pool stat obj_name 
test_rep_pool/obj_name mtime 2019-05-10 21:08:49.000000, size 524288
[root@node1 ~]# rados -p test_rep_pool stat test_cp_obj
test_rep_pool/test_cp_obj mtime 2019-05-10 21:17:29.000000, size 524288      
  • 檢視對象的屬性 ​

    ​listxattr​

    ​​

    ​rados -p data listxattr obj_name​

  • 擷取對象指定屬性​

    ​getxattr​

    ​​

    ​rados -p data getxattr obj_name attr​

  • 設定對象屬性值​

    ​setxattr​

    ​​

    ​rados -p data setxattr obj_name attr val​

  • 删除對象指定屬性​

    ​rmxattr​

    ​​

    ​rados -p data rmxattr obj_name attr​

#先設定對象屬性值
rados -p test_rep_pool setxattr obj_name test_attr true
rados -p test_rep_pool setxattr obj_name test_attr2 false
#列出對象屬性值
[root@node1 ~]# rados -p test_rep_pool listxattr obj_name
test_attr
test_attr2
#擷取對象指定屬性值
[root@node1 ~]# rados -p test_rep_pool getxattr obj_name test_attr
true
#删除test_attr屬性,隻剩下一個屬性
[root@node1 ~]# rados -p test_rep_pool rmxattr obj_name test_attr
[root@node1 ~]# rados -p test_rep_pool listxattr obj_name
test_attr2      

可以了解這幾個指令可以為對象打标,來标記我們自己操作過的對象

  • 檢視對象資訊

    ​rados -p test_rep_pool stat obj_name​

[root@node1 ~]# rados -p test_rep_pool stat obj_name
test_rep_pool/obj_name mtime 2019-05-10 21:33:48.000000, size 524288      
  • 設定對象頭部内容 ​

    ​setomapheader​

    ​​

    ​[root@node1 ~]# rados -p test_rep_pool setomapheader obj_name 1​

  • 擷取對象頭部内容​

    ​getomapheader​

    ​​

    ​rados -p test_rep_pool getomapheader obj_name​

#設定對象頭部資訊為1
[root@node1 ~]# rados -p test_rep_pool setomapheader obj_name 1
#擷取對象頭部資訊
[root@node1 ~]# rados -p test_rep_pool getomapheader obj_name 
header (1 bytes) :
00000000  31                                                |1|
00000001      
  • 設定對象的鍵值屬性 ​

    ​setomapval​

    ​​

    ​rados -p test_rep_pool setomapval obj_name key val​

  • 列出omap的鍵​

    ​listomapkeys​

    ​​

    ​rados -p test_rep_pool listomapkeys obj_name key val​

  • 列出omap的鍵​

    ​listomapvals​

    ​​

    ​rados -p test_rep_pool listomap obj_name keys​

  • 擷取對象的指定鍵的值 ​

    ​getomap val​

    ​​

    ​rados -p test_rep_pool getomapval obj_name key​

  • 删除對象的指定鍵和值 ​

    ​rmomapkey​

    ​​

    ​rados -p test_rep_pool rmomapkey obj_name key​

  • 監控對象操作,并且向監控者發送消息 有點類似與區域網路通信
#終端一 :監聽該對象
[root@node1 ~]# rados -p test_rep_pool watch obj_name
press enter to exit...

#終端二:發送消息到終端一的該對象監聽者
[root@node1 ~]# rados -p test_rep_pool notify obj_name message
reply client.86788 cookie 140047050446368 : 11 bytes
00000000  07 00 00 00 6d 65 73 73  61 67 65                 |....message|
0000000b

#此時終端一接收到消息如下
NOTIFY cookie 140047050446368 notify_id 940597837824 from 86797
00000000  07 00 00 00 6d 65 73 73  61 67 65                 |....message|
0000000b      
  • 檢視有多少個對象監控者

    ​rados -p test_rep_pool listwatchers obj_name​

[root@node1 ~]# rados -p test_rep_pool listwatchers obj_name
watcher=192.168.122.1:0/3015025283 client.86788 cookie=140047050446368      
  • 設定一個對象的大小以及寫粒度,但是目前并未分析清除該設定所起的作用

    ​rados -p test_rep_pool set-alloc-hint 4194304 4194304​

    ​大小為4M ,寫粒度為4M
導出資源池資料
  • 将資源池内容輸出或者寫入指定檔案

    ​​

    ​rados -p test_rep_pool export pool_content​

    ​​ 因為導出的檔案為資料檔案,是以檢視内容需使用​

    ​hexdum -C pool_content​

    ​​格式化輸出或者使用vim進入一般模式輸入​

    ​:%!xxd​

    ​ 進而将該檔案轉換為16進制可讀檔案
[root@node1 ~]# vim pool_content 
0000000: ceff ceff 0200 0000 1200 0000 0a00 0000  ................
0000010: 0101 0c00 0000 ceff 0a0a 0000 0000 0000  ................
0000020: 0000 0101 0c00 0000 ceff 0303 2701 0000  ............'...
0000030: 0000 0000 0301 2101 0000 0403 2a00 0000  ......!.....*...
0000040: 0000 0000 0900 0000 6f62 6a5f 6e61 6d65  ........obj_name
0000050: 32fe ffff ffff ffff ff00 0000 0000 0000  2...............
...
00001b0: ec01 010c 0000 00ce ff04 0400 0000 0000  ................
00001c0: 0000 0001 010c 0000 00ce ff03 0328 0100  .............(..
00001d0: 0000 0000 0003 0122 0100 0004 032b 0000  .......".....+..
00001e0: 0000 0000 000a 0000 006f 626a 5f63 7265  .........obj_cre
00001f0: 6174 65fe ffff ffff ffff ff00 0000 0000  ate.............      
  • 将資源檔案導入指定資源池

    ​​

    ​rados -p test_rep_pool import pool_content​

    ​ 導入之前,我們對以上資源池資料進行清除,操作如下
[root@node1 ~]# rados purge test_rep_pool --yes-i-really-really-mean-it
Warning: using slow linear search
Removed 5 objects
successfully purged pool test_rep_pool
[root@node1 ~]# rados -p test_rep_pool import pool_content 
Importing pool
Write #-9223372036854775808:00000000:::obj_name2:head#
Write #-9223372036854775808:00000000:::obj_create:head#
Write #-9223372036854775808:00000000:::test_cp_obj:head#
Write #-9223372036854775808:00000000:::obj_name:head#
Write #-9223372036854775808:00000000:::obj_test:head#