Linux Cachefiles 加速NFS

NFS是一種經常使用到的網絡共享文件系統,如何來提高NFS速度
在linux下,有一個filesystem cache系統叫FS-Cache,來加速file server,如NFS SAMBA CIFS。
FS-Cache是linux kernel中一個通用的cache管理者,用於管理網路和其他檔案系統的cache。
FS-Cache是在linux核心版本2.6.30及以上版本才有支援。在RHEL6.x 、CentOS6.x版本可以使用此方法加速。

FS-Cache Cachefiles 是安裝在client端,server端不需要安裝

安裝

yum install cachefilesd.x86_64

配置 check cachefilesd.conf

vim /etc/cachefilesd.conf 
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

說明:
dir: cache目錄。預設路徑是 /var/cache/fscache。
tag: 指定一個FS-Cache標籤,用來區分多個cache。預設是"CacheFiles"。
secctx system_u:system_r:cachefiles_kernel_t:s0 : 開啟SELinux的話,需要更改安全內容。
brun 10%, bcull 7%, bstop 3%, frun 10%, fcull 7%, fstop 3% : cache策略。

cachefiles模塊將在dir 目錄下自動創建兩個子目錄:cache和graveyard。
主動cache存儲於cache目錄下。process檢測graveyard目錄,並將刪除任何出現在該目錄中的cache。

啟用cachefilesd

start cachefilesd
/etc/init.d/cachefilesd  start

確認 check cachefilesd status

/etc/init.d/cachefilesd  status
cachefilesd (pid  12941) is running...
dir /var/fscache
cat /proc/fs/nfsfs/servers

注意FSC列的值,如果是yes 表示已經啟用cachefilesd,否則就沒有啟用

NFS 掛載啟用fsc選項 (kernel 2.6.30以後才有支援)
如果你的kernel 2.6.30 在之前,需要編譯核心才能使用cachefile
編譯核心kernel module 將CONFIG_NFS_FSCACHE=y 才能讓nfs支援cachefilesd。

因為cachefiles使用xattr存儲額外信息來維護ccahe,需要本機filesystem支援xattr擴展文件屬性。
ext4 filesystem預設已經啟用xattr。
如果是使用ext3 filesystem,需要加上user_xattr選項。按照如下步驟操作:

gedit /etc/fstab
/dev/sdb1 /data ext3 defaults,user_xattr 0 0

設定 /data 支援xattr擴展文件屬性

當要mount nfs時,必須-o fsc告訴kernel這個nfs要使用cache機制

mount -t nfs4 rb30s01:/ /data  -o fsc

查看cachefiles統計信息

cat /proc/fs/fscache/stats

補充:
nfs-utils 需要要使用1.1.5以後的版本,建議使用 nfs-utils-1.2.3-54
nfs-utils-1.2.3-54.el6.x86_64.rpm

如果cachefile沒有啟用的話

modprobe cachefiles

lsmod |grep cachefiles

cachefiles             36906  1
fscache                53874  2 cachefiles,nfs

/etc/init.d/cachefilesd  restart

ERIC3534

上一篇 Cadence IC6 cdb2oa 轉換方法
下一篇 Linux 掛載NTFS 硬碟格式