NFS笔记

yum -y install rpcbind nfs-utils
需要先启动rpc 在启动nfs  客户源也需要安装nfs-utils
/etc/init.d/nfs reload 平滑重启nfs 相当于 exportfs -rv

exportfs -o rw,sync 172.16.1.0/24:/data 直接使用exportfs配置nfs

showmount -e 172.16.1.31
showmount -e localhost


exports 配置(/etc/exports):
/data 172.16.1.0/24(rw,sync) ro 只读 async异步写入(写入数据先写到缓冲区)


chkconfig netfs on 防止重启的时候未挂载NFS

vim /etc/fstab
172.16.1.31:/data /mnt nfs defaults 0 0

cat /var/lib/nfs/etab 查看服务器端完整配置
cat /proc/mounts 查看挂载报警
chown nfsnobody.nfsnobody /data
客户端挂载命令:mount -t nfs 172.16.1.31:/data /mnt

将挂载开机启动


mount -t nfs -o noexec(不可执行,可以增加安全性) nosuid(不可用使用suid) intr(设置超时时间)

noatime(不记录访问时间,减少磁盘IO) async(异步写入)

default 包括rw,suid,dev,exec,auto,nouser,async


umount -lf /mnt 强制卸载
-f Force unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or later.)
-l Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all refer-ences to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

NFS内核优化建议

优化选项说明

/proc/sys/net/core/rmem_default:该文件指定了接受套接字缓冲区大小的默认值(以字节为单位),默认设置:124928。

/proc/sys/net/core/rmem_max:该文件指定了接受套接字缓冲区大小的最大值(以字节为单位),默认设置:124928。

/proc/sys/net/core/wmem_default:该文件指定了发送套接字缓冲区大小的默认值(以字节为单位),默认设置:124928。

/proc/sys/net/core/wmem_max:该文件指定了发送套接字缓冲区大小的最大值(以字节为单位),默认设置:124928。

具体内核优化命令如下:

cat >>/etc/sysctl.conf<<EOF
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
EOF
sysctl -p


企业NFS共享存储优化
硬件:sas/ssd 硬盘,买多快做raid5或者raid10,网卡吞吐量要大,至少千兆网卡(多块网卡做bond)

NFS服务器端配置 /data 10.0.0.2/24(rw,sync,all_squash,anonuid=65534,anongid=65534)

客户端配置挂载优化命令:
mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,rsize=131072,wsize=131072 10.0.0.7:/data /mnt

内核优化:
cat >>/etc/sysctl.conf<<EOF
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
EOF
sysctl -p

如果NFS有压力 可以使用Moosefs(mfs) GlusterFS(适合大文件) FastDFS

局限性:
1、存在单点故障(可以通过负载均衡和高可用方案弥补)
2、效率不高
3、客户端认证是基于IP的,安全性不高(用于内网问题不大)
4、数据是明文传输的
5、多台客户端挂载一个NFS服务器时,当服务端出现问题的时候,所有客户端都处于挂掉状态(解决方法修复NFS服务或强制卸载)

原文地址:https://www.cnblogs.com/Template/p/9360685.html