• Welcome to LiuJason's Blog!

Linux使用fscache给NFS(客户端)添加本地SSD缓存|CentOS7为例

Linux笔记 Jason 3 years ago (2021-01-30) 610 Views 0 Comments QR code of this page

安装FScache模块

yum -y install cachefilesd
systemctl enable cachefilesd
systemctl start cachefilesd

配置参数

默认配置文件在/etc/cachefilesd.conf,其中第一行是SSD缓存的位置,我因为系统盘是SSD所以没有做任何修改,有兴趣可以研究一下。

# cat /etc/cachefilesd.conf
###############################################################################
#
# Copyright (C) 2006,2010 Red Hat, Inc. All Rights Reserved.
# Written by David Howells ([email protected])
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
###############################################################################

dir /var/cache/fscache
tag mycache
brun 10%
bcull 7%
bstop 3%
frun 10%
fcull 7%
fstop 3%

# Assuming you're using SELinux with the default security policy included in
# this package
secctx system_u:system_r:cachefiles_kernel_t:s0

挂载nfs

在fstab里写入挂载信息,添加fsc参数,参考:

# vi /etc/fstab
【NFS服务器】:【路径】 【挂载点】 nfs _netdev,fsc,async 0 0

然后mount -a挂载,并验证是否挂载成功:

# cat /proc/fs/nfsfs/servers
NV SERVER   PORT USE HOSTNAME
v4 0a020203  801   1 【NFS服务器】

验证缓存

查看FScache状态:

# service cachefilesd  status
Redirecting to /bin/systemctl status cachefilesd.service
● cachefilesd.service - Local network file caching management daemon
   Loaded: loaded (/usr/lib/systemd/system/cachefilesd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-01-30 10:22:15 CET; 30s ago
 Main PID: 15546 (cachefilesd)
   CGroup: /system.slice/cachefilesd.service
           └─15546 /usr/sbin/cachefilesd -n -f /etc/cachefilesd.conf

Jan 30 10:22:15 KVM-FSN1-M103 systemd[1]: Starting Local network file caching management daemon...
Jan 30 10:22:15 KVM-FSN1-M103 systemd[1]: Started Local network file caching management daemon.
Jan 30 10:22:27 KVM-FSN1-M103 cachefilesd[15546]: About to bind cache
Jan 30 10:22:27 KVM-FSN1-M103 cachefilesd[15546]: Bound cache
Jan 30 10:22:27 KVM-FSN1-M103 cachefilesd[15546]: Daemon Started

查看是否FSC参数为yes,是的话就说明开启成功了:

# cat /proc/fs/nfsfs/volumes
NV SERVER   PORT DEV          FSID                              FSC
v4 0a020203  801 0:40         93708ab500102402:0                yes
v4 0a026465  801 0:39         923cd7b2141449fc:8fbb6fecf6743ef1 yes

过一段时间查看统计情况,如果不全都是0就说明已经在正常缓存了:

# cat /proc/fs/fscache/stats
FS-Cache statistics
Cookies: idx=19 dat=322 spc=0
Objects: alc=0 nal=0 avl=0 ded=0
ChkAux : non=0 ok=0 upd=0 obs=0
Pages  : mrk=0 unc=0
Acquire: n=341 nul=0 noc=0 ok=341 nbf=0 oom=0
Lookups: n=0 neg=0 pos=0 crt=0 tmo=0
Invals : n=108 run=0
Updates: n=0 nul=0 run=0
Relinqs: n=239 nul=0 wcr=0 rtr=0
AttrChg: n=0 ok=0 nbf=0 oom=0 run=0
Allocs : n=0 ok=0 wt=0 nbf=0 int=0
Allocs : ops=0 owt=0 abt=0
Retrvls: n=423310 ok=0 wt=0 nod=0 nbf=423310 int=0 oom=0
Retrvls: ops=0 owt=0 abt=0
Stores : n=0 ok=0 agn=0 nbf=0 oom=0
Stores : ops=0 run=0 pgs=0 rxd=0 olm=0
VmScan : nos=0 gon=0 bsy=0 can=0 wt=0
Ops    : pend=0 run=0 enq=0 can=0 rej=0
Ops    : ini=0 dfr=0 rel=0 gc=0
CacheOp: alo=0 luo=0 luc=0 gro=0
CacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0
CacheEv: nsp=0 stl=0 rtr=0 cul=0


# du -sh /var/cache/fscache
12K	/var/cache/fscache

This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/1162.html
Like (1)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址