将映像映射为块设备
将映像映射为块设备的命令
格式
sudo rbd map foo --name client.admin [-m {mon-IP}] [-k /path/to/ceph.client.admin.keyring]
例如
sudo rbd map foo --name client.admin -m ceph1 -k /etc/ceph/ceph.client.admin.keyring
正确输出如下:
[zzq@localhost ceph]$ sudo rbd map foo --name client.admin -m ceph1 -k /etc/ceph/ceph.client.admin.keyring
/dev/rbd0
[zzq@localhost ceph]$
查看块映射map和创建文件系统
rbd showmapped
输出如下:
[zzq@localhost ceph]$ rbd showmapped
id pool image snap device
0 rbd foo - /dev/rbd0
则使用/dev/rbd0创建文件系统
sudo mkfs.ext4 -m0 /dev/rbd0
正确输出如下:
[zzq@localhost ceph]$ sudo mkfs.ext4 -m0 /dev/rbd0
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1024 blocks, Stripe width=1024 blocks
262144 inodes, 1048576 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[zzq@localhost ceph]$
挂载文件系统并写入文件查看
sudo mkdir /cephAll
sudo mount /dev/rbd0 /cephAll
cd /cephAll
sudo vi helloCeph.txt
ls
df -h
这样我们就能在client中直接对ceph集群存储进行读取写入了。
输出如下:
[zzq@localhost ceph]$ sudo mkdir /cephAll
[zzq@localhost ceph]$ sudo mount /dev/rbd0 /cephAll
[zzq@localhost ceph]$ cd /cephAll
[zzq@localhost cephAll]$ sudo vi helloCeph.txt
[zzq@localhost cephAll]$ ls
helloCeph.txt lost+found
[zzq@localhost cephAll]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_localhost-lv_root
18G 2.2G 15G 13% /
tmpfs 482M 0 482M 0% /dev/shm
/dev/sda1 477M 86M 362M 20% /boot
/dev/rbd0 3.9G 8.0M 3.8G 1% /cephAll
[zzq@localhost cephAll]$ |