# Ceph commands usage ###### tags: `ceph` ### some commands ``` # get Ceph quorum status ceph quorum_status -f json-pretty # get ceph usage ceph df ceph df detail # get radosgw user info radosgw-admin user info --uid=testuser # list buckets radosgw-admin bucket list # remove shadow objects rados --pool=.rgw.buckets ls rados --pool=.rgw.buckets rm <object name> rados --pool=.rgw.buckets ls | grep __shadow_ | xargs rados --pool=.rgw.buckets rm ``` ### remove all objects in a Ceph pool !!! But it is not good to use in a large number of object pool. ``` Create a script with following to remove all objects in a Ceph pool. #!/usr/bin/bash pool_name=rbd for i in `rados -p $pool_name ls` do echo $i rados -p $pool_name rm $i done rados -p rbd ls ``` ### ronfigure VM to use Ceph RBD as disk ``` [ On Ceph monitor node ] 1. create pool ceph osd pool create <pool name> <number of pg> <number of pgp> ceph osd lspools 2. create a ceph user name as "client.libvirt" and references it to the <pool name> ceph auth get-or-create client.libvirt mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=<pool name>' ceph auth list 3. get the key of the user "client.libvirt" and save it to a file called "client.libvirt.key" ceph auth get-key client.libvirt | tee client.libvirt.key 4. copy the key file "client.libvirt.key" to VM Computer node scp -pr ./client.libvirt.key root@computer:/root/ 5. create 2GB size image file qemu-img create -f rbd rbd:<pool name>/<image name> 2G rbd -p <pool name> ls [ On VM Computer node ] 1. create an VM via virt-manager 2. edit the VM xml file. Add or modify xml as following disk defination, change {monitor-host} to ceph monitor node IP <disk type='network' device='disk'> <source protocol='rbd' name='libvirt-pool/new-libvirt-image'> <host name='{monitor-host}' port='6789'/> </source> <target dev='vda' bus='virtio'/> </disk> 3. generate a secret cat > secret.xml <<EOF <secret ephemeral='no' private='no'> <usage type='ceph'> <name>client.libvirt secret</name> </usage> </secret> EOF 4. define the secret, this will output a uuid of the secret. copy that uuid. virsh secret-define --file secret.xml 5. set the uuid of the secret value virsh secret-set-value --secret <uuid of secret> --base64 $(cat /root/client.libvirt.key) rm -rf ./secret.xml /root/client.libvirt.key 6. edit the secret in VM xml file. add <auth></auth> <disk type='network' device='disk'> <driver name='qemu'/> <auth username='libvirt'> <secret type='ceph' uuid='628f1d68-efa9-494f-b00d-f67b92933395'/> </auth> <source protocol='rbd' name='libvirt-pool/new-libvirt-image'> <host name='192.168.124.11' port='6789'/> </source> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </disk> ```