首先我们查看nfs的版本信息。服务器使用nfsstat -s,客户端使用nfsstat -c

[root@Nfs-138 ~]# nfsstat -s
Server rpc stats:
calls      badcalls   badclnt    badauth    xdrcall
778        0          0          0          0
Server nfs v3:
null         getattr      setattr      lookup       access       readlink
2       100% 0         0% 0         0% 0         0% 0         0% 0         0%
read         write        create       mkdir        symlink      mknod
0         0% 0         0% 0         0% 0         0% 0         0% 0         0%
remove       rmdir        rename       link         readdir      readdirplus
0         0% 0         0% 0         0% 0         0% 0         0% 0         0%
fsstat       fsinfo       pathconf     commit
0         0% 0         0% 0         0% 0         0%
Server nfs v4:
null         compound
19        2% 757      97%

Server nfs v4 operations:
op0-unused   op1-unused   op2-future   access       close        commit
0         0% 0         0% 0         0% 78        4% 20        1% 3         0%
create       delegpurge   delegreturn  getattr      getfh        link
7         0% 0         0% 5         0% 589      33% 105       6% 0         0%
lock         lockt        locku        lookup       lookup_root  nverify
0         0% 0         0% 0         0% 72        4% 0         0% 0         0%
open         openattr     open_conf    open_dgrd    putfh        putpubfh
33        1% 0         0% 4         0% 0         0% 637      36% 0         0%
putrootfh    read         readdir      readlink     remove       rename
24        1% 2         0% 19        1% 0         0% 15        0% 1         0%
renew        restorefh    savefh       secinfo      setattr      setcltid
93        5% 0         0% 1         0% 0         0% 18        1% 4         0%
setcltidconf verify       write        rellockowner bc_ctl       bind_conn
4         0% 0         0% 14        0% 0         0% 0         0% 0         0%
exchange_id  create_ses   destroy_ses  free_stateid getdirdeleg  getdevinfo
0         0% 0         0% 0         0% 0         0% 0         0% 0         0%
getdevlist   layoutcommit layoutget    layoutreturn secinfononam sequence
0         0% 0         0% 0         0% 0         0% 0         0% 0         0%
set_ssv      test_stateid want_deleg   destroy_clid reclaim_comp
0         0% 0         0% 0         0% 0         0% 0         0%


NFS优化:

1.挂载优化

timeo=N   N为正整数,客户端挂载超时时间设置,单位1/10s。

retrans=N  N为正整数,超时重试次数

hard 重复挂载,直至挂载成功

bg 后台挂载,避免影响启动速度

async 异步读写

intr: 可以中断不成功的挂载


wsize=N 写块大小

rsize=N 读块大小

指定了server端和client端的传输的块大小,块大小是根据nfs的版本默认的。可以指定~


安全设置:

nosuid 是否在文件系统中使用上使用特殊权限

noatime 在访问文件时,是否同步访问时间

noexec是否在文件系统中执行二进制文件


2.网络传输优化

可以通过查看

/proc/sys/net/ipv4/ipfrag_high_thresh

/proc/sys/net/ipv4/ipfrag_low_thresh

了解系统可以处理的包的数目,如果网络包到达了ipfrag_high_thresh,那么系统就会开始丢包,直到包的数目到达ipfrag_low_thresh。


3.nfsd 个数

默认启用8个nfsd

[root@Nfs-138 ~]# ps aux | grep nfs|grep -v grep
root      2276  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd4]
root      2277  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd4_callbacks]
root      2278  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2279  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2280  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2281  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2282  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2283  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2284  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]
root      2285  0.0  0.0      0     0 ?        S    13:56   0:00 [nfsd]

可用通过查看nfs的运行情况

[root@Nfs-138 ~]# cat /proc/net/rpc/nfsd
rc 0 63 702
fh 0 0 0 0 0
io 12886 25174
th 8 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000   #8表示运行nfsd个数,后面的是每个nfsd所用的时间,若很大,就需要增加nfsd的个数。
ra 32 0 0 0 0 0 0 0 0 0 0 0
net 765 0 765 28
rpc 765 0 0 0 0
proc2 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
proc3 22 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
proc4 2 19 744
proc4ops 59 0 0 0 78 20 3 7 0 5 589 105 0 0 0 0 72 0 0 33 0 4 0 637 0 24 2 19 0 15 1 80 0 1 0 18 4 4 0 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

可以使用vim /etc/init.d/nfs修改nfsd的个数

image.png



4.若增加了nfsd的进程数,需要增加队列长度(需要有实际经验)

/proc/sys/net/core/rwmem_default

/proc/sys/net/core/wwmem_default

/proc/sys/net/core/rmmem_max

/proc/sys/net/core/wmmem_max

队列的长度最好是每一个nfsd有8k的大小。这样,server端就可以对client的请求作排队处理。如果要永久更改此值

#vim /etc/sysctl.conf增加以下几行

net.core.rmmem_default=数目

net.core.wmmem_default=数目

net.core.rmmem_max=数目

net.core.wmmem_max=数目

#service nfs restart


参考http://blog.chinaunix.net/uid-26000296-id-3970431.html

https://blog.csdn.net/onlyForCloud/article/details/48625737