ceph rdb限制权限挂载到客户端

发布时间 2023-10-27 16:31:04作者: 坚强的小蚂蚁

https://blog.51cto.com/u_13788458/3659476 --重点看
https://www.cnblogs.com/cnblo/p/15178328.html 重点看
https://blog.csdn.net/weixin_36290220/article/details/112373660
https://docs.ceph.com/en/latest/rados/operations/user-management/#user-management

一. 创建授权用户(管理端)

1.添加一个tom用户,对mon有读取权限,对testPool池的osd有读、写、调用的权限。
ceph auth add client.tom mon 'allow r' osd 'allow rwx pool=testPool'
2.查看tom当前权限
root@k8s-master1:/etc/ceph# ceph auth get client.tom
exported keyring for client.tom
[client.tom]
     key = AQBu27phHdglOxAAR5TNrk9KG5RvyqxQAtJycg==
     caps mon = "allow r"
     caps osd = "allow rwx pool=testPool"
3.添加用户的另外一种方式,ceph auth get-or-create
root@k8s-master1:/etc/ceph# ceph auth get-or-create client.jack mon 'allow r' osd 'allow rwx pool=testPool'
[client.jack]
     key = AQDs3Lph4IJvGhAAkicD5C5wMDNDGSZMleTmyQ==

它会返回包含用户名(在方 括号中)和密钥的密钥文

4.删除用户tom
ceph auth del client.tom
ceph auth ls 查看用户列表

二. 创建rbd

1.首先创建一个pool,用原先的testPool也行,这里复习一下
ceph osd pool create testPool2 64 64

rbd 存储池并不能直接用于块设备,而是需要事先在其中按需创建映像(image), 并把映像文件作为块设备使用,rbd 命令可用于创建、查看及删除块设备相在的映像(image), 以及克隆映像、创建快照、将映像回滚到快照和查看快照等管理操作

2. 在testPool2中创建一个myimage1的映像,也可以用之前创建的testPool/image1 镜像
rbd create myimage1 --size 2G --pool testPool2  --image-format 2 --image-feature layering 
或者
rbd create --pool testPool2 --image myimage1 --image-format 2 --image-feature layering --size 2G
3.查看指定rbd的信息
rbd --image image1 --pool testPool info
或者
rbd info testPool/image1

三. 客户端使用块存储

1.客户端写入上面授权用户jack的信息
root@hong:/etc/ceph# cat keyring 
[client.jack]
key = AQDs3Lph4IJvGhAAkicD5C5wMDNDGSZMleTmyQ==
caps mon = "allow r"
caps osd = "allow rwx pool=testPool"

ceph.conf直接拷贝master节点上的,不需要修改

root@hong:/etc/ceph# cat ceph.conf 
[global]
mon_host = 10.5.86.10:6789

[client.admin]
keyring = /etc/ceph/keyring
2.查看用户jack的授权信息
ceph --user jack -s
3.对镜像进行映射
root@hong:/etc/ceph# rbd --id jack -p testPool map image1
/dev/rbd0
4. 对磁盘格式化
mkfs -t xfs /dev/rbd0
5. 挂载
mkdir -p /mnt/myimage1 && mount /dev/rbd0 /mnt/myimage1
6. rbd image 空间扩展
管理端进行操作
rbd resize --pool testPool --image image1 --size 10G
客户端进行操作
xfs_growfs -d /mnt/myimage1, 如果上面格式化为ext4  需要执行resize2fs /dev/rbd0

四. rdb回收

1.取消挂载
unmount /mnt/myimage1
2. 取消映射
rbd --id jack -p testPool unmap image1
3.镜像删除和移至回收站
rbd rm --pool testPool --image image1      删除
rbd trash move --pool testPool --image image1  移动到回收站
rbd trash restore --pool testPool --image image1 --image-id `rbd trash list --pool testPool | awk '/image1/{print $1}'` 从回收站中恢复