本文摘自PHP中文网,作者零下一度,侵删。
一、前提:内核中需要配置bcache模块1.1 检查
- 是否存在于内核中:检查/sys/fs/bcache目录是否存在,没有说明内核中没有bcache
- 是否以内核模块方式存在:检查/lib/modules/<$version>/kernel/drivers/md/bcache目录是否存,不存在则说明没有bcache内核模块
- 以上两步检查完如果都没有,则说明内核中没有配置编译bcache,需要自己配置编译新的内核(下载内核时需要注意版本,bcache功能是在3.10及以上版本中才有)
1.2 编译新内核
1 2 3 |
|
二、编译安装
1 |
|
三、部署方式
3.1 创建bcache设备
1 |
|
1 |
|
1 |
|
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 添加后端设备(backing device)
- 1、创建后端设备
1 2 |
|
- 2、attach绑定后端设备
1 |
|
1 |
|
1 |
|
3.3 删除后端设备
- 1、detach解绑backing device设备
1 |
|
- 2、删除后端设备
1 |
|
3.4 添加缓存设备(caching device)
-1、 创建缓存设备
1 2 3 |
|


-2、attach,与bcache设备关联
1 2 |
|
3.5 删除缓存设备
前提:确保没有backing device在使用它(可以通过lsblk查看)
解释: - cache设备的存在,可以通过/sys/fs/bcache目录对应的cache set uuid了解
- unregister该uuid后这个cache设备就被视为删除了
1 2 |
|
3.6 格式化bcache并挂载使用
1 |
|
四、使用操作
4.1 查看运行状态
1 |
|
no cache:该backing device没有attach任何caching device(这意味着所有I / O都直接传递到backing device[pass-through mode])。
clean:everything is ok,缓存是干净的。
dirty:这意味着一切都设置正常,并且您已启用回写,缓存是脏的。
inconsistent:您遇到问题,因为后台设备与缓存设备不同步。
4.2 查看缓存的数据量
1 |
|
4.3 查看/设置缓存模式
1 2 |
|
4.4 打印device信息
1 |
|
4.5 配置信息
backing device 在 /sys/block/bcache<n>/bcache/ 目录下
cache device 在 /sys/fs/bcache/<CSET-UUID>/ 目录下
对/sys中配置信息的改变是暂时的,重启会失效。如果想要在启动时设置当前的配置,需要创建一个conf配置文件在/etc/tmpfile.d/中,例如 /etc/tmpfile.d/my-bcache.conf:
w /sys/block/bcache0/bcache/sequential_cutoff - - - - 1
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)
以上就是配置bcache模块的实例教程的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
更多相关阅读请进入《bcache》频道 >>