使用rbd-nbd进行rbd挂载
1. 安装软件
apt-get install ceph-common rbd-nbd
- 注意: 请确保ceph-common版本与ceph服务端一致
2.部署nbd模块的配置: /etc/modprobe.d/nbd.conf
写入如下内容:
options nbd max_part=16 nbds_max=99
说明:
- max_part:块设备支持的最大分区数,默认值为0,不修改的话部分情况会无法显示分区
- nbds_max: nbd设备(即/dev/nbd*)的个数, 设备系统默认只有16个,请根据实际情况酌情修改,不能高于255
3.加载nbd模块
[email protected]-test:~# modprobe nbd
## 检查是否成功加载
[email protected]-test:~# ls /dev/nbd*
/dev/nbd0 /dev/nbd1 ......
4.新建rbd并映射到本地块设备
# 新建测试设备
[email protected]-test:~# qemu-img create -f raw rbd:aquarius-sas-img/test-nbd1:id=docker 20G
## 映射
## 格式为:rbd-nbd [pool名]/[rbd名称]
[email protected]-test:~# rbd-nbd map aquarius-sas-img/test-nbd1
## 检查是否出现这个块设备
[email protected]-test:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nbd1 43:0 0 100G 0 disk
sda 8:0 0 278.5G 0 disk
├─sda2 8:2 0 1K 0 part
├─sda9 8:9 0 246.5G 0 part /home
├─sda7 8:7 0 8G 0 part /var
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda1 8:1 0 8G 0 part /
├─sda8 8:8 0 4G 0 part /tmp
└─sda6 8:6 0 8G 0 part /usr
## 新建完成后就可以直接当做块设备来使用,分区、格式化等任何你想做的事
## 列出所有映射的rbd
[email protected]-test:~# rbd-nbd list-mapped
/dev/nbd0
5.简单测试
## 分区,也可以不分区直接格式化后进行读写
[email protected]-test:~# parted -s /dev/nbd1 mktable GPT
[email protected]-test:~# parted -s /dev/nbd1 mkpart primary 1 100%
## 格式化
[email protected]-test:~# mkfs.xfs /dev/nbd1p1
meta-data=/dev/nbd1p1 isize=256 agcount=4, agsize=6553472 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=26213888, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
## 挂载
[email protected]-test:~# mount /dev/nbd1p1 /mnt/
## 简单dd测试
[email protected]-test:~# cd /mnt/
[email protected]-test:~# dd if=/dev/zero of=test-dd-in-nbd bs=2M count=100
100+0 records in
100+0 records out
209715200 bytes (210 MB) copied, 0.145939 s, 1.4 GB/s
[email protected]-test:~# ls -lh
total 200M
-rw-r--r-- 1 root root 200M 5月 14 17:07 test-dd-in-nbd
[email protected]-test:~# df -h|grep nbd
/dev/nbd1p1 100G 233M 100G 1% /mnt
6.解挂载、解除映射
## 解挂载
[email protected]-test:~# umount /mnt/
## 解除映射
[email protected]-test:~# rbd-nbd unmap /dev/nbd1
/dev/nbd1 disconnected
## 检查块设备
[email protected]-test:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 278.5G 0 disk
├─sda2 8:2 0 1K 0 part
├─sda9 8:9 0 246.5G 0 part /home
├─sda7 8:7 0 8G 0 part /var
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda1 8:1 0 8G 0 part /
├─sda8 8:8 0 4G 0 part /tmp
└─sda6 8:6 0 8G 0 part /usr
原文地址:https://www.cnblogs.com/lifei02/p/9892554.html
时间: 2024-10-10 23:12:41