bcache使用(Bcache usage)

下载与安装

sudo yum install -y gcc libblkid-devel
wget https://github.com/g2p/bcache-tools/archive/refs/heads/master.tar.gz
tar xf master.tar.gz 
cd bcache-tools-master/
sudo make && sudo make install

创建bcache设备

升级内核

需要使用bcache内核参数,该参数需要在4.x内核才支持

需要使用bcache内核参数,该参数需要在4.x内核才支持

wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm
sudo yum install kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm -y
sudo sed -ri 's/(GRUB_DEFAULT)=.*/\1=0/g' /etc/default/grub

# 下列两条命令二选一
## 注意:如果你的系统是用uefi引导的,则命令为
sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
## 否则,使用该命令为
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

可以通过df -hT命令判断你的系统是否由uefi引导,如果输出结果中有/boot/efi(即该目录挂载了一个盘),则为uefi引导;或者通过命令ls /sys/firmware/efi看该目录是否存在

可以通过df -hT命令判断你的系统是否由uefi引导,如果输出结果中有/boot/efi(即该目录挂载了一个盘),则为uefi引导;或者通过命令ls /sys/firmware/efi看该目录是否存在

设置内核参数

lsmod | grep bcache
modprobe bcache
echo 'modprobe bcache' | sudo tee /etc/sysconfig/modules/bcache.modules > /dev/null
sudo chmod 755 /etc/sysconfig/modules/bcache.modules

后端盘与高速盘绑定

一般WAL分区大于10GB就足够使用,Ceph官方文档建议每个DB分区不小于每个数据盘容量的4%,其Cache盘容量推荐占数据盘容量的5%-10%

一般WAL分区大于10GB就足够使用,Ceph官方文档建议每个DB分区不小于每个数据盘容量的4%,其Cache盘容量推荐占数据盘容量的5%-10%

sudo parted -s /dev/nvme0n1  mklabel gpt
sudo parted /dev/nvme0n1 mkpart primary 2048s 10G
sudo parted /dev/nvme0n1 mkpart primary 10G 100%

sudo make-bcache -B /dev/sdb -C /dev/nvme0n1p1
sudo make-bcache -B /dev/sdc -C /dev/nvme0n1p2

验证绑定情况

$ lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:0    0  100G  0 disk 
├─nvme0n1p1 259:5    0  10G   0 part 
│ └─bcache0 253:0    0   50G  0 disk 
├─nvme0n1p2 259:6    0  10G   0 part 
│ └─bcache1 253:128  0   50G  0 disk 
sdb           8:16   0   50G  0 disk 
└─bcache0   253:0    0   50G  0 disk 
sr0          11:0    1  4.3G  0 rom  
sdc           8:32   0   50G  0 disk 
└─bcache1   253:128  0   50G  0 disk 
sda           8:0    0   64G  0 disk 
├─sda2        8:2    0    8G  0 part [SWAP]
├─sda3        8:3    0   32G  0 part /
└─sda1        8:1    0    1G  0 part /boot

卸载bcache设备

————————

Download and install

sudo yum install -y gcc libblkid-devel
wget https://github.com/g2p/bcache-tools/archive/refs/heads/master.tar.gz
tar xf master.tar.gz 
cd bcache-tools-master/
sudo make && sudo make install

创建bcache设备

Upgrade kernel

You need to use the bcache kernel parameter, which needs to be in 4 X kernel

You need to use the bcache kernel parameter, which needs to be in 4 X kernel

wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm
sudo yum install kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm -y
sudo sed -ri 's/(GRUB_DEFAULT)=.*/\1=0/g' /etc/default/grub

# 下列两条命令二选一
## 注意:如果你的系统是用uefi引导的,则命令为
sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
## 否则,使用该命令为
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

You can judge whether your system is booted by UEFI through the DF – HT command. If there is / boot / EFI in the output result (that is, a disk is mounted in the directory), it is UEFI booted; Or check whether the directory exists through the command LS / sys / firmware / EFI

You can judge whether your system is booted by UEFI through the DF – HT command. If there is / boot / EFI in the output result (that is, a disk is mounted in the directory), it is UEFI booted; Or check whether the directory exists through the command LS / sys / firmware / EFI

Set kernel parameters

lsmod | grep bcache
modprobe bcache
echo 'modprobe bcache' | sudo tee /etc/sysconfig/modules/bcache.modules > /dev/null
sudo chmod 755 /etc/sysconfig/modules/bcache.modules

Binding of back-end disk and high-speed disk

Generally, a wal partition larger than 10GB is enough. CEPH’s official documents suggest that each DB partition should not be less than 4% of the capacity of each data disk, and its cache disk capacity is recommended to account for 5% – 10% of the capacity of the data disk

Generally, a wal partition larger than 10GB is enough. CEPH’s official documents suggest that each DB partition should not be less than 4% of the capacity of each data disk, and its cache disk capacity is recommended to account for 5% – 10% of the capacity of the data disk

sudo parted -s /dev/nvme0n1  mklabel gpt
sudo parted /dev/nvme0n1 mkpart primary 2048s 10G
sudo parted /dev/nvme0n1 mkpart primary 10G 100%

sudo make-bcache -B /dev/sdb -C /dev/nvme0n1p1
sudo make-bcache -B /dev/sdc -C /dev/nvme0n1p2

Verify binding

$ lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:0    0  100G  0 disk 
├─nvme0n1p1 259:5    0  10G   0 part 
│ └─bcache0 253:0    0   50G  0 disk 
├─nvme0n1p2 259:6    0  10G   0 part 
│ └─bcache1 253:128  0   50G  0 disk 
sdb           8:16   0   50G  0 disk 
└─bcache0   253:0    0   50G  0 disk 
sr0          11:0    1  4.3G  0 rom  
sdc           8:32   0   50G  0 disk 
└─bcache1   253:128  0   50G  0 disk 
sda           8:0    0   64G  0 disk 
├─sda2        8:2    0    8G  0 part [SWAP]
├─sda3        8:3    0   32G  0 part /
└─sda1        8:1    0    1G  0 part /boot

卸载bcache设备