flashcache mysql 安装_Flashcache基本使用及注意事项

1

2

3

rpm--import http://elrepo.org/RPM-GPG-KEY-elrepo.org

rpm-Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm

yum install flashcache-utils kmod-flashcache

2.源码安装

1

2

3

4

5

6

rpm-ivh http://mirrors.ustc.edu.cn/centos/6.5/os/x86_64/Packages/kernel-headers-2.6.32-431.el6.x86_64.rpm

rpm-ivh http://mirrors.ustc.edu.cn/centos/6.5/os/x86_64/Packages/kernel-devel-2.6.32-431.el6.x86_64.rpm

wget https://github.com/facebook/flashcache/archive/3.1.2.tar.gz

tar xf 3.1.2.tar.gz

cd flashcache-3.1.2

make&&make install

自动加载模块

开机自动加载模块配置:

1

2

3

4

5

6

7

8

vim/etc/sysconfig/modules/flashcache.modules

#! /bin/sh

/sbin/modinfo-Ffilename flashcache>/dev/null2>&1

if[$?-eq0];then

/sbin/modprobe flashcache

fi

chmod+x  /etc/sysconfig/modules/flashcache.modules

模块的自动加载最好不要采用写入/etc/rc.local的方式

1

2

3

4

5

6

7

8

9

10

##加载flashcache模块

modprobe flashcache

##查看flashcache模块是否加载

[root@localhost ~]# lsmod |grep flashcache

flashcache920680

dm_mod8420914flashcache,dm_mirror,dm_log

##删除flashcache模块

rmmod flashcache

创建Flashcache

SSD:/dev/sdc

SAS:/dev/sdb2

创建设备名为cachedev的flashcache

1

flashcache_create-pback-b4kcachedev/dev/sdc/dev/sdb2

生成/dev/mapper/cachedev设备

指定flashcache的block大小与Percona的page大小相同,一般默认

flashcache_create相关参数说明:

-p:缓存模式 writeback(数据先写到SSD,随后写到普通硬盘),

writethrough(数据同时写到SSD和普通硬盘),

writearound(数据绕过SSD,直接写到普通硬盘)三种,三种模式的所有读都会被缓存到flashcache可以通过dev.flashcache..cache_all参数调整

-s:缓存大小,可选项,如果未指定则整个SSD设备被用于缓存,默认的计数单位是扇区(sectors),但是可以接受k/m/g单位。

-b:指定块大小,可选项,默认为4KB,必须为2的指数。默认单位为扇区。也可以用K作为单位,一般选4KB。

-f:强制创建,不进行检查

-m:设备元数据块大小,只有writeback需要存储metadata块,默认4K

查看帮助

1

2

3

4

[root@localhost ~]# flashcache_create

Usage:flashcache_create[-v][-pback|thru|around][-bblock size][-mmd block size][-scache size][-aassociativity]cachedev ssd_devname disk_devname

Usage:flashcache_create Cache Mode back|thru|around isrequired argument

Usage:flashcache_create Defaultunits for-b,-m,-sare sectors,orspecify ink/M/G.Defaultassociativity is512

其他帮助参考flashcache源码目录下的man目录

加载缓存设备

1

flashcache_load/dev/sdccachedev(系统重启时使用来加载已经创建过的缓存设备cachedev)

加载已存在的flashcache操作仅用于writeback模式,writethrough和writearound模式重启机器后需要重新使用flashcache_create创建

使用Flashcache

创建好的flashcache设备是块设备,可格式文件系统后挂在使用,也可以继续对其分区等

mount /dev/mapper/cachedev /data

销毁Flashcache

flashcache_destroy /dev/sdc

这种方式删除writeback模式的flashcache时会将SSD上的所有数据删除包括脏数据

建议使用dmsetup命令(device-mapper软件包)删除,会自动将脏数据写入磁盘

dmsetup remove cachedev

Flashcache参数优化

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[root@localhost ]#sysctl dev.flashcache

dev.flashcache.sdc+sdb2.io_latency_hist=0

dev.flashcache.sdc+sdb2.do_sync=0

dev.flashcache.sdc+sdb2.stop_sync=0

dev.flashcache.sdc+sdb2.dirty_thresh_pct=20

dev.flashcache.sdc+sdb2.max_clean_ios_total=4

dev.flashcache.sdc+sdb2.max_clean_ios_set=2

dev.flashcache.sdc+sdb2.do_pid_expiry=0

dev.flashcache.sdc+sdb2.max_pids=100

dev.flashcache.sdc+sdb2.pid_expiry_secs=60

dev.flashcache.sdc+sdb2.reclaim_policy=0

dev.flashcache.sdc+sdb2.zero_stats=0

dev.flashcache.sdc+sdb2.fast_remove=0

dev.flashcache.sdc+sdb2.cache_all=1

dev.flashcache.sdc+sdb2.fallow_clean_speed=2

dev.flashcache.sdc+sdb2.fallow_delay=900

dev.flashcache.sdc+sdb2.skip_seq_thresh_kb=0

dev.flashcache.sdc+sdb2.clean_on_read_miss=0

dev.flashcache.sdc+sdb2.clean_on_write_miss=0

dev.flashcache.sdc+sdb2.lru_promote_thresh=2

dev.flashcache.sdc+sdb2.lru_hot_pct=75

dev.flashcache.sdc+sdb2.new_style_write_merge=0

针对MySQL作此优化

1

2

3

4

5

6

dev.flashcache.sdc+sdb2.cache_all=1默认值1表示缓存所有,0都不缓存,另外通过进程黑白名单控制

dev.flashcache.sdc+sdb2.reclaim_policy=1缓存回收策略,0:FIFO,1:LRU,可动态调整

dev.flashcache.sdbc+sdb2.fast_remove=10表示不同步脏块到磁盘,1表示同步脏块到磁盘

dev.flashcache.sdc+sdb2.dirty_thresh_pct=90每组脏块占有的百分比,过低会减少块覆盖,增加磁盘写操作和读缓存

dev.flashcache.sdc+sdb2.new_style_write_merge=1 打开写入合并,提升写磁盘的性能(旧版本dev.flashcache.sdc+sdb2.write_merge)

dev.flashcache.sdb1+sda6.skip_seq_thresh_kb=256表示不缓存超过256kb的顺序IO(由于SSD的随机读写比SAS好,但顺序读写相差不大,故作此优化)

Flashcache开机启动

flashcache模块自动加载–flashcache设备自动加载flashcache_load /dev/sdc  cachedev

A.模块自动加载请参考安装部分

B.开机自动加载已创建的缓存设备及挂载

1

2

3

4

5

6

7

8

9

10

cd/usr/src/flashcache-3.1.2/utils

cp flashcache/etc/init.d/

chmod+x/etc/init.d/flashcache

修改/etc/init.d/flashcache

SSD_DISK=/dev/sdc

BACKEND_DISK=/dev/sdb2

CACHEDEV_NAME=cachedev

MOUNTPOINT=/data

FLASHCACHE_NAME=sdc+sdb2

chkconfig flashcache on

Flashcache状态监控

1

2

3

4

5

6

7

8

9

10

dmsetup status cachedev

dmsetup tablecachedev

错误日志报告

/proc/flashcache/sdc+sdb2/flashcache_errors

状态报告

/proc/flashcache/sdc+sdb2/flashcache_stats

亦可使用flashstat命令实时查看

到此flashcache的基本使用就是这样,看了网上很多资料都是各种抄袭,不凡错误的,最后还是读了官方的帮助,总结出自己的以便以后使用;

后续要做的就是增加了SSD缓存后,要观察SSD的使用情况及缓存命中率等在逐渐调试优化,下一篇增加MySQL数据库从系统/MySQL方面的一些优化总结和大家分享,请继续关注

推荐IO测试工具

注意事项:

flashcache_create创建了缓存设备之后挂载即可使用,如创建之后使用flashcache_load /dev/sdc  cachedev会提示Invalid Flashcache superblock的错误

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值