本帖最后由 TimiZheng 于 2019-10-17 13:50 编辑
参考文档: 官网 下面这个说明文档很重要,可以参考:
有关bcache和flashcache的测试比较 http://www.accelcloud.com/2012/04/18/linux-flashcache-and-bcache-performance-testing/ 这篇文章认为bcache由于flashcache和dmcache http://www.chinacloud.cn/show.aspx?id=24597&cid=12
Bcache介绍中文 https://yq.aliyun.com/articles/60734
测试工具fio下载与安装- wget "http://brick.kernel.dk/snaps/fio-2.1.7.tar.gz"
- tar -xzvf fio-2.1.7.tar.gz
- cd fio-2.1.7
- ./configure
- make
- make install
复制代码
bcache安装
bcache内核安装: 检查是否已存在bcache模块,没有的话需要重新编译内核 ls /lib64/m/modules/3.10.0-514.el7.x86_64/kernel/drivers/md 下是否有bcache模块 直接yum升级内核 1、导入key yum源 直接升级 yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y 这个会直接升级到最新的内核版本
编译内核- #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
- #放到/usr/src/kenernal/目录下
- 使用linux-bcache安装(实际版本为3.12+)
- cd /tmp/linux-bcache
- yum install ncurses-devel
- yum groupinstall Development toos
- yum install binutils*
- make menuconfig
复制代码
选择目录:- Device Drivers
- ->Multiple devices driver support (RAID and LVM) -><*> Block device as cache
复制代码 - make V=1 all
- make modules
- make modules_install
- make install
复制代码
查看启动项awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg 设置新内核 grub2-set-default 0 重启 reboot 无论是编译还是yum升级,升级后都有了bcatch模块,但是都不会自动加载bcache lsmod|grep bcatch
modprob bcache
二、安装bcache-tool- yum -y install pkgconfig libblkid-devel
- cd bcache-tools
- make
- make install
复制代码
三、配置- sdb4 ssd 200G
- sda4 hdd 4T
- 挂载目录 /bcatch
复制代码 - wipefs -a /dev/sda4
- make-bcache -B /dev/sda4 -w4k
复制代码注:这是一个大坑,-B backing device的默认块大小是扇区一样大的,在后面和cache组建关系的时候,会一直不成功,报错内容为bch_cached_dev_attach() Couldn't attach sda4: block size less than set's block size make-bcache -C /dev/sdb4 -w4k -b512k (make-bcache之后就会被创建,如果做错了,使用echo 1 >/sys/block/bcache0/bcache/stop 这样的方式来停用,如果已经注册的还需要解除注册 停用之后,然后每次重新执行一次 卸载重做:- echo /dev/sdb4 > /sys/fs/bcache/ac6fcdd1-c36e-468a-890b-4c044eb20b71/unregister
- echo 1 > /sys/block/bcache0/bcache/stop
- )
复制代码
注册: echo /dev/sda4 > /sys/fs/bcache/register echo /dev/sdb4 > /sys/fs/bcache/register 注册都是提示 -bash: echo: write error: Invalid argument 实际注册的是cache device ,很是怀疑这一步否需要执行hdd的这块盘 注册时候会出现cache device 的id目录- [root@localhost mysqldb]# ls /sys/fs/bcache/
- ac6fcdd1-c36e-468a-890b-4c044eb20b71 register register_quiet
复制代码
设备绑定:将cache绑定到bcache0设备上- echo ac6fcdd1-c36e-468a-890b-4c044eb20b71 > /sys/block/bcache0/bcache/attach
复制代码
查看/var/log/message是否有绑定成功的提示:- Aug 21 19:46:42 localhost kernel: bcache: register_cache() registered cache device sdb4
- Aug 21 19:48:04 localhost kernel: bcache: bch_cached_dev_attach() Caching sda4 as bcache0 on set ac6fcdd1-c36e-468a-890b-4c044eb20b71(id每次做可能不同)
- [root@localhost hddtest]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sdb 8:16 0 744.6G 0 disk
- ├─sdb4 8:20 0 200G 0 part
- │ └─bcache0 253:0 0 4T 0 disk
- ├─sdb2 8:18 0 200G 0 part
- ├─sdb3 8:19 0 200G 0 part /ssddata
- └─sdb1 8:17 0 32G 0 part [SWAP]
- sda 8:0 0 5.5T 0 disk
- ├─sda4 8:4 0 4T 0 part
- │ └─bcache0 253:0 0 4T 0 disk
- ├─sda2 8:2 0 512M 0 part /boot
- ├─sda3 8:3 0 1.5T 0 part /
- └─sda1 8:1 0 1M 0 part
- mount /dev/bcache0 /bcache
复制代码
加载成功之后,查看cache_mode 等- [root@localhost testdb]# cat /sys/block/bcache0/bcache/cache_mode
- writethrough [writeback] writearound none
复制代码
修改模式 echo writethrough > /sys/block/bcache0/bcache/cache_mode
启动后的自动挂载硬盘 原来试过使用uuid,但是有时候会发现这个uuid会发生变化,所以就使用了下面这个方案 - /dev/bcache0 <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>
- <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>/data <wbr>
- <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> xfs <wbr> <wbr>
- defaults <wbr> <wbr> <wbr> <wbr>0 0
复制代码
--关闭bcache: 通过以上bcache之后是很难将hdd盘从ssd盘整分离出来 - <p style="margin: 8px 0px; font-family: Helvetica,;" hiragino="" sans="" yahei=""><span style="line-height: 1.6;">bcache <wbr></span></p>
- <p style="margin: 8px 0px; font-family: Helvetica,;" hiragino="" sans="" yahei="">echo '/dev/sdb4' >
- /sys/fs/bcache/ac6fcdd1-c36e-468a-890b-4c044eb20b71/unregister</p>
- <p style="margin: 8px 0px; font-family: Helvetica,;" hiragino="" sans="" yahei=""><span style="line-height: 25.6px;">echo
- ed3f2062-c9bb-4b2f-9ccb-595e48af9454 >
- /sys/block/bcache0/bcache/detach</span></p>
复制代码
(以上两种方式似乎都可以,具体差异不清楚)
在解除ssd时,会检查是否有脏块,如果有,则会开始刷新数据,此时用iostat 查看,就能看到很高的io读写(从ssd盘中,写入到hdd中) 可以再次注册
- echo '/dev/sdb4' >
- /sys/fs/bcache/<span style="line-height: 25.6px;">register</span>
复制代码
再次检查脏块数据量
- <p style="margin: 8px 0px; font-family: Helvetica,;" hiragino="" sans="" yahei="">[root@localhost <wbr>bcache]# cat
- /sys/block/bcache0/bcache/dirty_data</p>
- <p style="margin: 8px 0px; font-family: Helvetica,;" hiragino="" sans="" yahei="">0</p>
复制代码
|