一、rbd块存储挂载
1 创建一个OSD pool
| # ceph osd pool create rbd1 128 | 
 
 查询存储空间使用
| # ceph df GLOBAL:  SIZE AVAIL RAW USED %RAW USED   480GiB 474GiB 6.12GiB 1.28  POOLS:  NAME ID USED %USED MAX AVAIL OBJECTS   volumes 1 134B 0 150GiB 5   vms 2 0B 0 150GiB 0   images 3 0B 0 150GiB 0   rbd1 4 14.3MiB 0 150GiB 19   rbd 5 0B 0 150GiB 0 | 
 
 
2 创建一个名为ceph-client1-rbd1、大小为1024
| rbd create ceph-client1-rbd1 --size 1024 -p rdb1 | 
 
要列出RBD镜像,输入下列的命令
| # rbd -p rbd1 ls ceph-client1-rbd1 ceph-client1-rbd2 | 
 
 检看一个RBD镜像的详细信息
| # rbd --image ceph-client1-rbd1 info rbd: error opening image ceph-client1-rbd1: (2) No such file or directory # rbd --image ceph-client1-rbd1 -p rbd1 info rbd image ‘ceph-client1-rbd1‘:  size 1GiB in 256 objects  order 22 (4MiB objects)  block_name_prefix: rbd_data.5b5756b8b4567  format: 2  features: layering, exclusive-lock, object-map, fast-diff, deep-flatten  flags:   create_timestamp: Tue Oct 1 12:03:52 2019 | 
 
 
3 客户端查看linux版本
| [root@centos7 mnt]# uname -r 3.10.0-862.el7.x86_64 [root@centos7 mnt]# modprobe rbd [root@centos7 mnt]# | 
 
4 客户端安装ceph-common
| # yum install –y ceph-common | 
 
5 客户端挂载rbd硬盘并使用
 
6客户端查看挂载情况
 
| [root@centos7 mnt]# rbd showmapped id pool image snap device  0 rbd1 ceph-client1-rbd2 - /dev/rbd0 | 
 
 
协助ceph块存储
 
二、文件存储建立
 
1 检查客户端的linux内核版本:
| [root@centos7 ceph]# uname -r 3.10.0-862.el7.x86_64 | 
 
2 客户端创建挂载点目录:
| [root@centos7 ceph]#mkdir /cephfs | 
 
 跟使用块存储服务一样,客户端需要从服务器端拷贝以下2个文件到/etc/ceph/
| [root@centos7 ceph]# ls ceph.client.admin.keyring ceph.conf | 
 
 
3 服务器端及客户端,修改管理员密钥(生产环境需要创建普通账号并给予权限,这里例子暂时以管理员账号测试)
| vi /etc/ceph/ceph.client.admin.keyring [client.admin]  key = AQC6mmJdfBzyHhAAE1GazlHqH2uD35vpL6Do1w==  auid = 0  caps mds = "allow"  caps mon = "allow *"  caps osd = "allow *" | 
 
4 在服务器端创建cephfs OSD pool,保护数据及元数据2个pool
| [root@ceph1 ceph]#ceph osd pool create cephfs_metadata 32 [root@ceph1 ceph]#ceph osd pool create cephfs_metadata 16 | 
 
 服务器端启动cephfs
| [root@ceph1 ceph]#ceph fs new leadorfs cephfs_metadata cephfs | 
 
 验证数据生成
| [root@ceph1 ceph]# ceph mds stat leadorfs-1/1/1 up {0=ceph1=up:active} | 
 
 
5 客户端挂载文件存储(目标地址可以输入集群mon多个地址)
| [root@ceph1 ceph]# mount -t ceph 172.16.3.61:6789:/ /cephfs -o name=admin,secret=AQC6mmJdfBzyHhAAE1GazlHqH2uD35vpL6Do1w== | 
 
6 客户端检查挂载情况
| [root@centos7 ceph]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 17G 1.2G 16G 7% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 12M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 378M 0 378M 0% /run/user/0 172.16.3.61:6789:/ 150G 0 150G 0% /cephfs | 
 
7 客户端在/cephfs创建文件
| [root@centos7 ceph]# cd /cephfs/ [root@centos7 cephfs]# echo "Utopa 2019" > Utopa.txt [root@centos7 cephfs]# ls Utopa.txt | 
 
 检查服务器端使用情况
| [root@ceph1 ceph]# ceph df GLOBAL:  SIZE AVAIL RAW USED %RAW USED   480GiB 474GiB 6.12GiB 1.28  POOLS:  NAME ID USED %USED MAX AVAIL OBJECTS   volumes 1 134B 0 150GiB 5   vms 2 0B 0 150GiB 0   images 3 0B 0 150GiB 0   rbd1 4 14.3MiB 0 150GiB 19   rbd 5 0B 0 150GiB 0   cephfs 6 11B 0 150GiB 1   cephfs_metadata 7 5.73KiB 0 150GiB 21 | 
 
 
三、rdb map出錯rbd sysfs write failed
 
創建了一個rbd鏡像1
然後,在Ceph client端將該rbd鏡像映射為本地設備時出錯。
- $ rbd map docker_test --name client.admin
- rbd: sysfs write failed
- RBD image feature set mismatch. You can disable features unsupported by the kernel with "rbd feature disable".
- In some cases useful info is found in syslog - try "dmesg | tail" or so.
原因: 
rbd鏡像的一些特性,OS kernel並不支持,所以映射失敗。我們查看下該鏡像支持了哪些特性。可以看到特性feature一欄,由於我OS的kernel只支持layering,其他都不支持,所以需要把部分不支持的特性disable掉。 
方法一: 
直接diable這個rbd鏡像的不支持的特性:
$ rbd feature disable docker_test exclusive-lock object-map fast-diff deep-flatten
方法二: 
創建rbd鏡像時就指明需要的特性,如:
$ rbd create --size 4096 docker_test --image-feature layering
方法三: 
如果還想一勞永逸,那麽就在執行創建rbd鏡像命令的服務器中,修改Ceph配置文件/etc/ceph/ceph.conf,在global section下,增加
rbd_default_features = 1
再創建rdb鏡像。
$ rbd create --size 4096 docker_test
通過上述三種方法後,查看rbd鏡像的信息。
- $ rbd info docker_test
- rbd image ‘docker_test‘:
-  size 4096 MB in 1024 objects
-  order 22 (4096 kB objects)
-  block_name_prefix: rbd_data.43a22ae8944a
-  format: 2
-  features: layering
-  flags:
次嘗試映射rdb鏡像到本地塊設備,成功!
- $ rbd map docker_test --name client.admin
- /dev/rbd0
ceph rbd块存储挂载及文件存储建立
原文:https://www.cnblogs.com/cloud-datacenter/p/12231030.html