有时候需要删除大量的rbd设备,使用rbd rm 删除会很慢,其实可以采用多线程的方法来删除。
time rbd ls |xargs -P 50 -I {} rbd snap ls {} ##50是并发进程数
快速删除所有卷的快照:
time rbd ls |xargs -P 50 -I {} rbd snap rm rbd/{}@{}_snap ##50是并发进程数
快速删除rbd 设备:
1、rados -p rbd ls|egrep 'rbd_id.|rbd_header.|rbd_data.'>delobject
2、运行脚本sh delrbd.sh
1 #!/bin/bash 2 3 #####config 4 process=50 5 objectlistfile="./delobject" 6 deletepool=rbd 7 ##### 8 9 delete_fun() 10 { 11 date "+%Y-%m-%d %H:%M:%S" 12 rados -p $deletepool rm $1 13 #sleep 1 14 } 15 16 concurrent() 17 { 18 start=$1 && end=$2 && cur_num=$3 19 mkfifo ./fifo.$$ && exec 4<> ./fifo.$$ && rm -f ./fifo.$$ 20 for ((i=$start; i<$cur_num+$start; i++)); do 21 echo "init start delete process $i" >&4 22 done 23 24 for((i=$start; i<=$end; i++)); do 25 read -u 4 26 { 27 echo -e "-- current delete: [:delete $i/$objectnum $REPLY]" 28 delob=`sed -n "${i}p" $objectlistfile` 29 delete_fun $delob 30 echo "delete $delob done" 1>&4 # write to $ff_file 31 } & 32 done 33 wait 34 } 35 36 objectnum=`cat $objectlistfile|wc -l` 37 concurrent 1 $objectnum $process
3、time rbd ls |xargs -P 50 -I {} rbd rm {} ##50是并发进程数
1、rbd info testrbd_290
2、rados -p rbd listwatchers rbd_header.2393ee6b8b4567
或
rbd status testrbd_290
解除被挂载的卷:
for i in rbd showmapped |awk '{print $3}'
;do rbd unmap $i;done
delrbd.sh脚本来源:https://www.cnblogs.com/zphj1987/p/13575449.