Ceph基于普通用于挂载块存储、实现对块存储的动态空间拉伸

  客户端使用普通账户挂载并使用 RBD

  测试客户端使用普通账户挂载并使用 RBD

 

  创建普通账户并授权

  创建普通账户

cephadmin@ceph-deploy:~/ceph-cluster$ ceph auth add client.lxh mon 'allow r' osd 'allow rwx pool=rbd-data'
added key for client.lxh

 

  验证用户信息

cephadmin@ceph-deploy:~/ceph-cluster$ ceph auth get client.lxh
[client.lxh]
	key = AQDNPoxjqGNpLxAAoBJOZKOiNg/MFMsS8x2VSg==
	caps mon = "allow r"
	caps osd = "allow rwx pool=rbd-data"
exported keyring for client.lxh

 

  创建keyring文件

cephadmin@ceph-deploy:~/ceph-cluster$ ceph-authtool --create-keyring ceph.client.lxh.keyring 
creating ceph.client.lxh.keyring

 

  导出用户 keyring

cephadmin@ceph-deploy:~/ceph-cluster$ ceph auth get client.lxh -o ceph.client.lxh.keyring 
exported keyring for client.lxh

 

  查看用户keyring

cephadmin@ceph-deploy:~/ceph-cluster$ cat ceph.client.lxh.keyring 
[client.lxh]
	key = AQDNPoxjqGNpLxAAoBJOZKOiNg/MFMsS8x2VSg==
	caps mon = "allow r"
	caps osd = "allow rwx pool=rbd-data"

 

  同步普通用户认证文件

cephadmin@ceph-deploy:~/ceph-cluster$ scp ceph.conf ceph.client.lxh.keyring root@192.168.100.80:/etc/ceph/

 

  客户端验证

 

  客户端验证权限

   默认情况下,客户端只有普通用户的认证文件,使用ceph客户端就会出现无client.admin的管理员认证文件的错误提示

 

  因此,使用ceph客户端需要指定普通用户来运行,具体参数为--user

[root@ansible ~]# ceph --user lxh -s

 

 

  映射 rbd

  1、使用普通用户权限映射data-img1镜像

[root@ansible ~]# rbd --user lxh -p rbd-data map data-img1
/dev/rbd0

  

   验证块设备

[root@ansible ~]# lsblk

 

   2、使用普通用户权限映射data-img2镜像

[root@ansible ~]# rbd --user lxh -p rbd-data map data-img2
/dev/rbd1

 

   验证块设备

 

  格式化并使用 rbd 镜像

  1、格式化rbd0

[root@ansible ~]# mkfs.xfs /dev/rbd0
Discarding blocks...Done.
meta-data=/dev/rbd0              isize=512    agcount=8, agsize=98304 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=786432, imaxpct=25
         =                       sunit=1024   swidth=1024 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

 

  2、挂载并使用rbd0

[root@ansible ~]# mkdir /data

[root@ansible ~]# mount /dev/rbd0 /data

[root@ansible ~]# tar -zcf etc.tar.gz /etc

[root@ansible ~]# mv etc.tar.gz /data

[root@ansible ~]# df -h /data
Filesystem      Size  Used Avail Use% Mounted on
/dev/rbd0       3.0G   44M  3.0G   2% /data

[root@ansible ~]# ll /data
total 11272
-rw-r--r-- 1 root root 11540042 Dec  4 15:15 etc.tar.gz

 

  3、格式化rbd1

[root@ansible ~]# mkfs.xfs /dev/rbd1
Discarding blocks...Done.
meta-data=/dev/rbd1              isize=512    agcount=8, agsize=163840 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=1024   swidth=1024 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

 

   4、挂载并使用rbd1

[root@ansible ~]# mkdir /data1

[root@ansible ~]# mount /dev/rbd1 /data1

[root@ansible ~]# tar -zcf etc.tar.gz /etc


[root@ansible ~]# mv etc.tar.gz /data1

[root@ansible ~]# df -h /data1
Filesystem      Size  Used Avail Use% Mounted on
/dev/rbd1       5.0G   44M  5.0G   1% /data1

[root@ansible ~]# ll /data1
total 11272
-rw-r--r-- 1 root root 11540042 Dec  4 15:46 etc.tar.gz

 

  管理端验证

cephadmin@ceph-deploy:~/ceph-cluster$ rbd ls -p rbd-data -l
NAME       SIZE   PARENT  FMT  PROT  LOCK
data-img1  3 GiB            2            
data-img2  5 GiB            2        excl
data-img3  5 GiB            2  

 

   data-img2 LOCK选项处为excl表示,该镜像启用了exclusive-lock特性,只允许一个客户端挂载

 

  验证 ceph 内核模块

   挂载 rbd 之后系统内核会自动加载 libceph.ko 模块

[root@ansible ~]# lsmod|grep ceph

[root@ansible ~]# modinfo libceph

 

  Ubuntu:

 

   Centos:

 

  开机自动挂载

  添加自动挂载的命令

[root@ansible ~]# vim /etc/rc.d/rc.local 
rbd --user lxh -p rbd-data map data-img1
rbd --user lxh -p rbd-data map data-img2
mount /dev/rbd0 /data
mount /dev/rbd1 /data1

 

  添加rc.local执行权限

[root@ansible ~]# chmod +x /etc/rc.d/rc.local 

[root@ansible ~]# cat /etc/rc.d/rc.local
#load rbd ceph modules
modprobe rbd
modprobe libceph
#config rbd map
rbd --user lxh -p rbd-data map data-img1 
sleep 1s
mount /dev/rbd0 /data
sleep 2s
rbd --user lxh -p rbd-data map data-img2 
sleep 1s
mount /dev/rbd1 /data1
exit 0

 

  重启客户端服务器

[root@ansible ~]# reboot

 

  客户端查看rbd镜像的映射关系

[root@ansible ~]# rbd showmapped
id  pool      namespace  image      snap  device   
0   rbd-data             data-img1  -     /dev/rbd0
1   rbd-data             data-img2  -     /dev/rbd1

 

  卸载 rbd 镜像

  客户端首先取消挂载

[root@ansible ~]# umount /data

 

  客户端再执行rbd的取消映射

[root@ansible ~]# rbd --user lxh -p rbd-data unmap data-img1
[root@ansible ~]# rbd --user lxh -p rbd-data unmap data-img2

 

  rbd 镜像空间拉伸:

  可以扩展RBD空间,不建议缩小空间

  当前 rbd 镜像空间大小

cephadmin@ceph-deploy:~/ceph-cluster$ rbd ls -p rbd-data -l
NAME       SIZE   PARENT  FMT  PROT  LOCK
data-img1  3 GiB            2            
data-img2  5 GiB            2        excl
data-img3  5 GiB            2 

 

  rbd 镜像空间拉伸命令

cephadmin@ceph-deploy:~/ceph-cluster$ rbd help resize
usage: rbd resize [--pool <pool>] [--namespace <namespace>] 
                  [--image <image>] --size <size> [--allow-shrink] 
                  [--no-progress] 
                  <image-spec> 

Resize (expand or shrink) image.

Positional arguments
  <image-spec>         image specification
                       (example: [<pool-name>/[<namespace>/]]<image-name>)

Optional arguments
  -p [ --pool ] arg    pool name
  --namespace arg      namespace name
  --image arg          image name
  -s [ --size ] arg    image size (in M/G/T) [default: M]
  --allow-shrink       permit shrinking
  --no-progress        disable progress output

 

  拉伸 rbd 镜像空间

  将data-img1镜像空间拉伸为5G

cephadmin@ceph-deploy:~/ceph-cluster$ rbd resize --pool rbd-data --image data-img1 --size 5G
Resizing image: 100% complete...done.

cephadmin@ceph-deploy:~/ceph-cluster$ rbd ls -p rbd-data -l
NAME       SIZE   PARENT  FMT  PROT  LOCK
data-img1  5 GiB            2            
data-img2  5 GiB            2        excl
data-img3  5 GiB            2 

 

  客户端验证空间

  虽然磁盘的大小在客户端已经为5G,但是分区还没有刷新

[root@ansible ~]# fdisk -l /dev/rbd0

Disk /dev/rbd0: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4194304 bytes / 4194304 bytes

[root@ansible ~]# df -h /dev/rbd0
Filesystem      Size  Used Avail Use% Mounted on
/dev/rbd0       3.0G   44M  3.0G   2% /data

 

  刷新分区大小

  磁盘分区系统是xfs使用xfs_growfs工具,ext4的使用resize2fs工具。

  利用工具直接对挂载的目的分区目录使用

#xfs文件系统
[root@ansible ~]# xfs_growfs /data/

#ext4文件系统
[root@ansible ~]# resize2fs /dev/rbd0

 

posted @ 2023-01-19 17:04  PunchLinux  阅读(225)  评论(0编辑  收藏  举报