创建Ceph块设备
[root@node2 ~]# rbd create block-device4 --size 5G --image-format 1
rbd: image format 1 is deprecated
查看块设备信息
[root@node2 ~]# rbd --image block-device4 info
rbd image 'block-device4':
size 5120 MB in 1280 objects
order 22 (4096 kB objects)
block_name_prefix: rb.0.1435a.238e1f29
format: 1
映射块设备到block-device4
[root@node2 ~]# rbd map --image block-device4
/dev/rbd2
查看系统中块设备映射信息
[root@node2 ~]# rbd showmapped
id pool image snap device
0 rbd block-device1 - /dev/rbd0
1 rbd block-device3 - /dev/rbd1
2 rbd block-device4 - /dev/rbd2
要使用这个块设备,需要创建并挂载一个文件系统
[root@node2 ~]# mkfs.xfs /dev/rbd2
meta-data=/dev/rbd2 isize=256 agcount=9, agsize=162816 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=1024 swidth=1024 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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
创建挂载点并挂载
[root@node2 ~]# mkdir /mnt/block-device4
[root@node2 ~]# mount /dev/rbd2 /mnt/block-device4
[root@node2 ~]# df -h /mnt/block-device4
Filesystem Size Used Avail Use% Mounted on
/dev/rbd2 5.0G 33M 5.0G 1% /mnt/block-device4
查看挂载情况
[root@node2 ~]# mount | grep rbd
/dev/rbd0 on /mnt/ceph-block-device1 type xfs (rw,relatime,attr2,inode64,sunit=8192,swidth=8192,noquota)
创建测试文件测试块设备
[root@node2 ~]# touch /mnt/block-device4/test
[root@node2 ~]# dd if=/dev/zero of=/mnt/block-device4/file bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.18182 s, 577 MB/s
[root@node2 ~]#
查看文件写入信息
[root@node2 ~]# ls /mnt/block-device4
file test
[root@node2 ~]# ll /mnt/block-device4
total 102400
-rw-r--r-- 1 root root 104857600 Sep 25 22:37 file
-rw-r--r-- 1 root root 0 Sep 25 22:36 test
[root@node2 ~]# df -h /mnt/block-device4
Filesystem Size Used Avail Use% Mounted on
/dev/rbd2 5.0G 133M 4.9G 3% /mnt/block-device4
设备开机自动挂载
[root@node2 ~]# echo "/dev/rbd2 /mnt/block-device4 xfs defaults,_netdev0 0" >> /etc/fstab
查看系统中rbd
[root@node2 ~]# rbd ls
block-device4
block-device2
[root@node2 ~]# rbd list
block-device4
block-device2
将刚创建的RBD块设备扩容到10G
[root@node2 ~]# rbd resize --image block-device4 --size 10G
Resizing image: 100% complete...done.
[root@node2 ~]# rbd --image block-device4 info
rbd image 'block-device4':
size 10240 MB in 2560 objects
order 22 (4096 kB objects)
block_name_prefix: rb.0.1435a.238e1f29
format: 1
扩展文件系统空间
[root@node2 ~]# df -h /mnt/block-device4
Filesystem Size Used Avail Use% Mounted on
/dev/rbd2 5.0G 133M 4.9G 3% /mnt/block-device4
使用xfs_growfs命令对文件系统进行扩充
[root@node2 ~]# xfs_growfs -d /mnt/block-device4
meta-data=/dev/rbd2 isize=256 agcount=9, agsize=162816 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=1024 swidth=1024 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1310720 to 2621440
[root@node2 ~]# df -h /mnt/block-device4
Filesystem Size Used Avail Use% Mounted on
/dev/rbd2 10G 133M 9.9G 2% /mnt/block-device4
[root@node2 ~]#
本文转自 OpenStack2015 51CTO博客,原文链接:http://blog.51cto.com/andyliu/1856538,如需转载请自行联系原作者