因为在工作中使用到Bcache技术,所以了解了一些。做一下记录:
1 检查:
a 是否存在于内核中 /sys/fs/bcache目录是否存在
b:是否有bcache模块 /lib/modules/<$version>/kernel/drivers/md/bcache
2 内核升级
BCache的功能是在3.10以上的版本上添加的。
$ wget "http://vault.centos.org/7.3.1611/os/Source/SPackages/kernel-3.10.0-514.el7.src.rpm"
$ rpm2cpio ./kernel-3.10.0-514.el7.src.rpm | cpio -idmv //提取rpm包内容,获取内核:linux-3.10.0-514.el7.tar.xz$ make menuconfig //内核配置 Device Drivers ->Multiple devices driver support (RAID and LVM) -><*> Block device as cache$ make bzImage (V=1) //编译内核
$ make modules //编译内核模块
$ make modules_install //拷贝内核模块的.ko文件到/lib/modules下
$ make install //拷贝initrd和bzImage到boot目录下,并修改开机启动配置文件
$ reboot //重启,根据菜单选择对应内核版本进入
3 编译安装Bcache-Tools
//获取bcache-tools工具(以下两个网址任选其一)
$ git clonehttp://evilpiepirate.org/git/bcache-tools.git
$ git clone https://github.com/g2p/bcache-tools.git//安装前需要两个依赖包pkg-config和libblkid-dev
$yum -y install pkg-config libblkid-dev//编译安装bcache-tools$make$ make install
4 创建bcache设备
make-bcache -C <cache-device> -B <backing device>
make-bcache设备提供了同时初始化多个设备的功能,并自动绑定缓存设备和后端设备参数。
-B 格式化后端设备
-C 格式化caching device
example: the default block and bucket sizes of 512B and 128kB are used. The block size should match the backing devices sector size which will usually be either 512 or 4k. The bucket size should match the erase block size of the caching device with the intent of reducing write amplification. For example, using a HDD with 4k sectors and an SSD with an erase block size of 2MB this command would look like
# make-bcache --block 4k --bucket 2m -C /dev/sdy
5 创建后端设备
make-bcache -B <backing-device> 结果:生成对应的设备/dev/bcache<n>
6 attach绑定后端设备
ls -la /sys/fs/bcache //查看cache set uuid
echo <CSET-UUID> /sys/block/bcache<n>/bcache/attach //attache之后,缓存设备就能够对新加的后端设备缓存数据了。
lsblk查看对应关系