ceph rados命令使用
文章目錄
- Pool相關
- Object相關
- 導出資源池數(shù)據(jù)
最近了解了rados命令的使用,感覺在對象操作這塊還是非常實用。因為rados是屬于底層存儲核心,所以關于rados的命令針對對象的操作較多。
環(huán)境中執(zhí)行
rados -h可以看到命令集分為幾個大的模塊:資源池、對象、以及一些全局選項 該命令用來做對象相關測試較為方便,可以操作單個對象,同時使用
rados bench命令進行集群io性能測試較多。本文不對
rados bench進行講解,詳細可以參考
io性能工具
當前rados命令是基于ceph 12.2.1 版本描述的,如過更高版本有更新的命令,歡迎大家補充。
Pool相關
- 顯示資源池列表
rados lspools - 創(chuàng)建資源池
rados mkpool pool1 auid rule_idrados mkpool pool1 12 2 #創(chuàng)建一個名稱為pool1的資源池,執(zhí)行該資源池的rule編號為2,用戶編號為1 setting auid:12 using crush rule 2 successfully created pool test - 資源池數(shù)據(jù)拷貝
rados cppool pool1 pool2,將pool1的資源池數(shù)據(jù)拷貝到pool2的數(shù)據(jù)資源池 - 刪除資源池
rados rmpool pool1 pool1 --yes-i-really-really-mean-it - 清除資源池數(shù)據(jù)
rados purge pool1 --yes-i-really-really-mean-it - 查看資源池信息
rados df -p pool1-p參數(shù)是指定具體資源池,如果不加,則顯示所有[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相關
-
獲取對象內(nèi)容
get
rados -p data get 10000006b70.00000005 test.txt該命令需要指定資源池以及對象內(nèi)容的輸出文件,對象名稱可以通過rados ls命令獲取[root@node1 ~]# rados -p data get 10000006b70.00000005 test.txt [root@node1 ~]# cat test.txt #該對象內(nèi)容是一些時間戳 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為名稱#寫入之前的對象數(shù)data: pools: 2 pools, 256 pgs objects: 2 objects, 19B usage: 15.0GiB used, 96.4TiB / 96.4TiB avail pgs: 256 active+clean#寫入之后的對象數(shù) 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,執(zhí)行結果如下data: pools: 2 pools, 256 pgs objects: 3 objects, 3.78MiB #本應該是2.78M,我偏移了1M開始寫,現(xiàn)在變?yōu)?.78M usage: 15.0GiB used, 96.4TiB / 96.4TiB avail pgs: 256 active+clean這個命令極大得方便我們?nèi)y試分析bluestore 的io流程
-
向指定對象追加內(nèi)容
append
rados -p test_rep_pool append obj_name ceph-osd.16.log -
刪除指定長度對象內(nèi)容
truncate
rados -p test_rep_pool truncate obj_name 524288刪除obj_name 對象512kb的容量 -
創(chuàng)建對象
create
rados -p test_rep_pool create obj_name2這里是創(chuàng)建了一個空對象[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時強制刪除一個對象,不在乎對象此時狀態(tài) -
拷貝對象
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 #查看這兩個對象的信息,可以看到已經(jīng)成功拷貝 [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 -
設置對象頭部內(nèi)容
setomapheader
[root@node1 ~]# rados -p test_rep_pool setomapheader obj_name 1 -
獲取對象頭部內(nèi)容
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 -
監(jiān)控對象操作,并且向監(jiān)控者發(fā)送消息 有點類似與局域網(wǎng)通信
#終端一 :監(jiān)聽該對象 [root@node1 ~]# rados -p test_rep_pool watch obj_name press enter to exit...#終端二:發(fā)送消息到終端一的該對象監(jiān)聽者 [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 -
查看有多少個對象監(jiān)控者
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
導出資源池數(shù)據(jù)
該命令方便數(shù)據(jù)備份
- 將資源池內(nèi)容輸出或者寫入指定文件
rados -p test_rep_pool export pool_content
因為導出的文件為數(shù)據(jù)文件,所以查看內(nèi)容需使用hexdum -C pool_content格式化輸出或者使用vim進入一般模式輸入:%!xxd從而將該文件轉(zhuǎn)換為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
導入之前,我們對以上資源池數(shù)據(jù)進行清除,操作如下[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#
因為rados命令集較為龐大,本文主要介紹的時rados對象操作相關的命令,還有一些其他命令未介紹,各位可以通過rados -h幫助信息進行查看。
總結
以上是生活随笔為你收集整理的ceph rados命令使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 托运行李多少钱啊?
- 下一篇: 使用rpmbuild对ceph的源码包进