1. Prerequisite: The bcache module needs to be configured in the kernel
##1.1 Check
-Whether it exists in the kernel: check whether the /sys/fs/bcache directory exists, it does not mean that there is no bcache in the kernel -Whether it exists as a kernel module: check /lib/modules/<$version> Does the /kernel/drivers/md/bcache directory exist? If it does not exist, it means that there is no bcache kernel module - If there is no bcache after checking the above two steps, it means that the kernel is not configured to compile bcache, and you need to configure and compile a new one yourself. Kernel (you need to pay attention to the version when downloading the kernel, the bcache function is only available in 3.10 and above)1.2 Compile the new kernel
$ wget "" $ 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 //重启,根据菜单选择对应内核版本进入
2. Compile and install
//获取bcache-tools工具(以下两个网址任选其一)$ git clone http://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
3. Deployment method
3.1 Create bcache device
$ -bcache -C <cache-device> -B <backing device>--B -C - -b 结果:有几个backing device就会对应生成几个/dev/
<br>
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
##3.2 Add backing device - 1. Create a back-end device
$ make-bcache -B <backing-device> 结果:生成对应的设备/dev/bcache<n>
$ -la /sys/fs/bcache $ <CSET-UUID> > /sys/block/bcache<n>/bcache/
<br>
3.3 Delete the back-end device - 1 , detach and unbind the backing device
$ -la /sys/fs/bcache/ $ <CSET-UUID> > /sys/block/bcache<n>/bcache/
- 2. Delete the back-end device
$ > /sys/block/bcache<N>/bcache/
3.4 Add caching device
##-1. Create caching device $ make-bcache -C <cache device> 结果:在/sys/fs/bcache目录下生成对应的CACHE SET UUID
注意:有可能设备本身有残余数据,需要使用wipefs清理掉
$ wipefs -a /dev/sda
-2. Attach, associated with bcache device
$ echo <CSET-UUID> > /sys/block/bcache<n>/bcache/attach 解释:通过后端设备attach缓存设备,cache device才能开始缓存,backing device才能被缓存
Prerequisite: Make sure that no backing device is using it (can be viewed through lsblk)Explanation: - The existence of the cache device can be verified through / Understand the cache set uuid corresponding to the sys/fs/bcache directory
- After unregistering the uuid, the cache device is considered deleted$ echo 1 > /sys/fs/bcache/<cache set uuid>/unregister 结果:再看/sys/fs/bcache目录下就没有这个cache设备的uuid了
$ mkfs.xfs /dev/bcache<n> //格式化设备为xfs文件系统$ mount /dev/bcache<n> /mnt //挂载设备到/mnt目录进行访问
4.1 Check the running status
$ cat /sys/block/bcache<n>/bcache/state
$ cat /sys/block/bcache<n>/bcache/dirty_data
// 设置缓存模式(默认writethrough)$ echo <cache mode> > /sys/block/bcache<N>/bcache/cache_mode// 查看缓存模式$ cat /sys/block/bcache<N>/bcache/cache_mode
[writethrough] writeback writearound none
4.5 Configuration information backing device is in the /sys/block/bcache cache device is in the /sys/fs/bcache/ Changes to the configuration information in /sys are temporary Yes, restarting will invalidate it. If you want to set the current configuration at startup, you need to create a conf configuration file in /etc/tmpfile.d/, for example /etc/tmpfile.d/my-bcache.conf: w /sys/block/bcache0/bcache/sequential_cutoff - - - - 1 $ bcache-super-show /dev/sd<n>
w /sys/block/bcache0/bcache/cache_mode - - - - writeback
(To set, in a persistent fashion, the sequential cutoff for bcache0 to 1 MB and write back)
The above is the detailed content of Example tutorial for configuring the bcache module. For more information, please follow other related articles on the PHP Chinese website!