James Bryant

【转】网络文件系统NFS

0
阅读(2258)

什么是NFS?

NFS是Network File System的缩写,即网络文件系统。它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录。NFS客户端(一般为应用服务器,例如web)可以通过挂载(mount)的方式将NFS服务端共享的数据目录挂载到NFS客户端本地系统中(就是某一个挂载点下)。从NFS客户端的机器本地看,NFS服务端共享的目录就好像是客户自己的磁盘分区或者目录一样,而实际上确是远端的NFS服务端的目录。

NFS网络文件系统类似windows系统的网络共享、安全功能、网络驱动器映射,这也和linux系统里的samba服务类似。应用于互联网中小型集群架构后端作为数据共享,如果是大型网站,那么有可能还会用到更复杂的分布式文件系统,例如Moosefs(mfs)、glusterfs、FastDFS。

NFS在企业中的应用场景

在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频、图片、附件等静态资源文件。一般是把网站用户上传的文件都放在NFS共享里,例如,BBS产品的图片、附件、头像,注意网站BBS程序不要放在NFS共享里,然后前端所有的节点访问存储服务之一,特别是中小网站公司应用频率更高。

NFS流程图

NFS原理图

NFS的RPC服务,在CentOS5.x下名称为portmap,在CentOS6.x下名称为rpcbind。

NFS服务端部署环境准备

image

NFS软件列表

部署NFS服务,需要安装下面的软件包:

nfs-utils:这个NFS服务主程序包括rpc.nfsd、rpc.mountd两个daemons和相关文档说明及执行命令文件等。

rpcbind:CentOS 6.x下面RPC的主程序(CentOS 5.x下面的portmap)

NFS可以被视为一个RPC程序,在启动任何一个RPC程序之前,需要做好端口映射工作,这个映射工作就是由rpcbind服务来完成的。因此,必须先启动rpcbind服务。

CentOS 6.6默认没有安装NFS软件包(CentOS 5默认已经安装)。

  1. [root@web-lnmp01 ~]# yum install nfs-utils rpcbind -y

  2. [root@web-lamp01 ~]# rpm -qa nfs-utils rpcbind

  3. [root@web-lnmp01 ~]# rpm -qa nfs-utils rpcbind

  4. nfs-utils-1.2.3-70.el6_8.2.x86_64 #这个包在5.8为portmap

  5. rpcbind-0.2.0-12.el6.x86_64

出现两个软件包,表示NFS服务端软件安装完毕。

启动NFS相关服务

  1. [root@nfs-server ~]# /etc/init.d/rpcbind status #查看rpcbind服务

  2. rpcbind is stopped

  3. [root@nfs-server ~]# /etc/init.d/rpcbind start #启动rpcbind服务

  4. Starting rpcbind: [ OK ]

  5. [root@nfs-server ~]# /etc/init.d/rpcbind status

  6. rpcbind (pid 26101) is running...

  7. [root@nfs-server ~]# lsof -i:111 #rpcbind服务端口111

  8. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

  9. rpcbind 26101 rpc 6u IPv4 28829 0t0 UDP *:sunrpc

  10. rpcbind 26101 rpc 8u IPv4 28832 0t0 TCP *:sunrpc (LISTEN)

  11. rpcbind 26101 rpc 9u IPv6 28834 0t0 UDP *:sunrpc

  12. rpcbind 26101 rpc 11u IPv6 28837 0t0 TCP *:sunrpc (LISTEN)

  13. [root@nfs-server ~]# netstat -lntup|grep rpcbind

  14. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 26101/rpcbind

  15. tcp 0 0 :::111 :::* LISTEN 26101/rpcbind

  16. udp 0 0 0.0.0.0:836 0.0.0.0:* 26101/rpcbind

  17. udp 0 0 0.0.0.0:111 0.0.0.0:* 26101/rpcbind

  18. udp 0 0 :::836 :::* 26101/rpcbind

  19. udp 0 0 :::111 :::* 26101/rpcbind

  20. [root@nfs-server ~]# chkconfig --list|grep rpcbind

  21. rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off

  22. [root@nfs-server ~]# rpcinfo -p localhost

  23.    program vers proto port service

  24.     100000 4 tcp 111 portmapper

  25.     100000 3 tcp 111 portmapper

  26.     100000 2 tcp 111 portmapper

  27.     100000 4 udp 111 portmapper

  28.     100000 3 udp 111 portmapper

  29.     100000 2 udp 111 portmapper

  30. [root@nfs-server ~]# /etc/init.d/nfs status #查看nfs服务

  31. rpc.svcgssd is stopped

  32. rpc.mountd is stopped

  33. nfsd is stopped

  34. rpc.rquotad is stopped

  35. [root@nfs-server ~]# /etc/init.d/nfs start #启动nfs服务

  36. Starting NFS services: [ OK ]

  37. Starting NFS quotas: [ OK ]

  38. Starting NFS mountd: [ OK ]

  39. Starting NFS daemon: [ OK ]

  40. Starting RPC idmapd: [ OK ]

  41. [root@nfs-server ~]# /etc/init.d/nfs status

  42. rpc.svcgssd is stopped

  43. rpc.mountd (pid 26225) is running...

  44. nfsd (pid 26241 26240 26239 26238 26237 26236 26235 26234) is running...

  45. rpc.rquotad (pid 26220) is running...

  46. [root@nfs-server ~]# netstat -lntup|grep 2049 #nfs服务端口2049

  47. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -

  48. tcp 0 0 :::2049 :::* LISTEN -

  49. udp 0 0 0.0.0.0:2049 0.0.0.0:* -

  50. udp 0 0 :::2049 :::* -

  51. [root@nfs-server ~]# rpcinfo -p localhost

  52.    program vers proto port service

  53.     100000 4 tcp 111 portmapper

  54.     100000 3 tcp 111 portmapper

  55.     100000 2 tcp 111 portmapper

  56.     100000 4 udp 111 portmapper

  57.     100000 3 udp 111 portmapper

  58.     100000 2 udp 111 portmapper

  59.     100011 1 udp 875 rquotad

  60.     100011 2 udp 875 rquotad

  61.     100011 1 tcp 875 rquotad

  62.     100011 2 tcp 875 rquotad

  63.     100005 1 udp 56844 mountd

  64.     100005 1 tcp 49326 mountd

  65.     100005 2 udp 47287 mountd

  66.     100005 2 tcp 47817 mountd

  67.     100005 3 udp 56317 mountd

  68.     100005 3 tcp 47741 mountd

  69.     100003 2 tcp 2049 nfs

  70.     100003 3 tcp 2049 nfs

  71.     100003 4 tcp 2049 nfs

  72.     100227 2 tcp 2049 nfs_acl

  73.     100227 3 tcp 2049 nfs_acl

  74.     100003 2 udp 2049 nfs

  75.     100003 3 udp 2049 nfs

  76.     100003 4 udp 2049 nfs

  77.     100227 2 udp 2049 nfs_acl

  78.     100227 3 udp 2049 nfs_acl

  79.     100021 1 udp 45085 nlockmgr

  80.     100021 3 udp 45085 nlockmgr

  81.     100021 4 udp 45085 nlockmgr

  82.     100021 1 tcp 42582 nlockmgr

  83.     100021 3 tcp 42582 nlockmgr

  84.     100021 4 tcp 42582 nlockmgr

  85. [root@nfs-server ~]# chkconfig --list nfs

  86. nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off

  87. [root@nfs-server ~]# chkconfig nfs on #nfs添加开机自启动

  88. [root@nfs-server ~]# chkconfig --list nfs

  89. nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off

  90. [root@nfs-server ~]# less /etc/init.d/rpcbind

  91. #! /bin/sh

  92. #

  93. # rpcbind Start/Stop RPCbind

  94. #

  95. # chkconfig: 2345 13 87 #开机启动顺序

  96. [root@nfs-server ~]# less /etc/init.d/nfs

  97. #!/bin/sh

  98. #

  99. # nfs This shell script takes care of starting and stopping

  100. # the NFS services.

  101. #

  102. # chkconfig: - 30 60 #开机启动顺序

工作中推荐使用/etc/rc.local进行服务的启动,不推荐使用chkconfig,目的是为了方便管理。

  1. [root@nfs-server ~]# ps -ef|egrep "rpc|nfs"

  2. rpc 26101 1 0 09:45 ? 00:00:00 rpcbind

  3. root 26211 2 0 09:52 ? 00:00:00 [rpciod/0]

  4. root 26220 1 0 09:52 ? 00:00:00 rpc.rquotad #磁盘配额进程

  5. root 26225 1 0 09:52 ? 00:00:00 rpc.mountd #权限管理验证

  6. root 26232 2 0 09:52 ? 00:00:00 [nfsd4]

  7. root 26233 2 0 09:52 ? 00:00:00 [nfsd4_callbacks]

  8. root 26234 2 0 09:52 ? 00:00:00 [nfsd] #NFS主进程

  9. root 26235 2 0 09:52 ? 00:00:00 [nfsd]

  10. root 26236 2 0 09:52 ? 00:00:00 [nfsd]

  11. root 26237 2 0 09:52 ? 00:00:00 [nfsd]

  12. root 26238 2 0 09:52 ? 00:00:00 [nfsd]

  13. root 26239 2 0 09:52 ? 00:00:00 [nfsd]

  14. root 26240 2 0 09:52 ? 00:00:00 [nfsd]

  15. root 26241 2 0 09:52 ? 00:00:00 [nfsd]

  16. root 26268 1 0 09:52 ? 00:00:00 rpc.idmapd

  17. root 26418 1023 0 10:41 pts/0 00:00:00 egrep rpc|nfs

配置NFS服务端

NFS服务的默认配置文件路径为:/etc/exports,并且默认是空的。

  1. [root@nfs-server ~]# ls -l /etc/exports

  2. -rw-r--r--. 1 root root 0 Jan 12 2010 /etc/exports

exports配置文件格式

/etc/exports文件配置格式

NFS 共享目录    NFS客户端地址1(参数1,参数2,参数3…) 客户端地址1(参数1,参数2,参数3…)

NFS 共享目录    NFS客户端地址(参数1,参数2…)

  1. [root@nfs-server ~]# cat /etc/exports

  2. /data 192.168.31.*(rw,sync)

  3. [root@nfs-server ~]# /etc/init.d/nfs reload

  4. exportfs: Failed to stat /data: No such file or directory #/data目录不存在

  5. [root@nfs-server ~]# mkdir /data

  6. [root@nfs-server ~]# /etc/init.d/nfs reload #exports -r

  1. [root@nfs-server ~]# showmount -e 127.0.0.1

  2. Export list for 127.0.0.1:

  3. /data 192.168.31.* #共享目录

  1. [root@nfs-server ~]# mount -t nfs 192.168.31.129:/data /mnt #挂载

  2. [root@nfs-server ~]# df -h

  3. Filesystem Size Used Avail Use% Mounted on

  4. /dev/sda3 7.1G 1.5G 5.3G 21% /

  5. tmpfs 497M 0 497M 0% /dev/shm

  6. /dev/sda1 190M 27M 153M 15% /boot

  7. 192.168.31.129:/data 7.1G 1.5G 5.3G 21% /mnt #挂载成功

  1. [root@nfs-server ~]# touch /data/oldboy.txt

  2. [root@nfs-server ~]# ls /mnt

  3. oldboy.txt

  4. [root@nfs-server ~]# touch /mnt/test.txt

  5. touch: cannot touch `/mnt/test.txt': Permission denied #无权限

客户端配置

启动rpcbind

  1. [root@web-lamp01 ~]# /etc/init.d/rpcbind start

  2. Starting rpcbind: [ OK ]

  3. [root@web-lamp01 ~]# /etc/init.d/rpcbind status

  4. rpcbind (pid 26272) is running...

  5. [root@web-lamp01 ~]# cat /etc/rc.local

  6. #启动rpcbind

  7. /etc/init.d/rpcbind start

  1. [root@web-lamp01 ~]# showmount -e 192.168.31.129

  2. Export list for 192.168.31.129:

  3. /data 192.168.31.*

  4. [root@web-lamp01 ~]# mount -t nfs 192.168.31.129:/data /mnt

  5. [root@web-lamp01 ~]# df -h

  6. Filesystem Size Used Avail Use% Mounted on

  7. /dev/sda3 7.1G 1.5G 5.3G 21% /

  8. tmpfs 497M 0 497M 0% /dev/shm

  9. /dev/sda1 190M 27M 153M 16% /boot

  10. 192.168.31.129:/data 7.1G 1.5G 5.3G 21% /mnt

  11. [root@web-lamp01 ~]# ls /mnt

  12. oldboy.txt

在服务端删除/data中的文件/oldboy.txt,然后在客户端进行查看,文件已经不存在。

无法写入是因为权限的问题,解决办法如下。

  1. [root@nfs-server ~]# cat /var/lib/nfs/etab

  2. /data 192.168.31.*(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash) #nfs的由65534进行管理

  3. [root@nfs-server ~]# cat /etc/exports

  4. /data 192.168.31.*(rw,sync)

  5. [root@nfs-server ~]# ls -ld /data

  6. drwxr-xr-x 2 root root 4096 Jan 19 11:36 /data #/data的属主是root

  7. [root@nfs-server ~]# grep 65534 /etc/passwd #查看65534的用户名

  8. nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

  9. [root@nfs-server ~]# chown -R nfsnobody /data #更改/data属主

  10. [root@nfs-server ~]# ls -ld /data

  11. drwxr-xr-x 2 nfsnobody root 4096 Jan 19 11:36 /data

  1. [root@nfs-server ~]# cd /mnt

  2. [root@nfs-server mnt]# pwd

  3. /mnt

  4. [root@nfs-server mnt]# ls

  5. [root@nfs-server mnt]# touch test.txt #服务端创建

  6. [root@nfs-server mnt]# ls

  7. test.txt

  8. [root@web-lamp01 mnt]# touch test2.txt #客户端创建

  9. [root@web-lamp01 mnt]# ls

  10. test2.txt test.txt

客户端设置开机自动挂载

  1. [root@web-lamp01 mnt]# cat /etc/rc.local

  2. #!/bin/sh

  3. #

  4. # This script will be executed *after* all the other init scripts.

  5. # You can put your own initialization stuff in here if you don't

  6. # want to do the full Sys V style init stuff.

  7. touch /var/lock/subsys/local

  8. #启动rpcbind

  9. /etc/init.d/rpcbind start

  10. #挂载nfs /data

  11. /bin/mount -t nfs 192.168.31.129:/data /mnt

同样配置另外一台客户端。

故障排查

1、首先确认NFS服务端配置和服务是否正常。

  1. [root@nfs-server ~]# showmount -e localhost

  2. Export list for localhost:

  3. /data 192.168.31.*

最好服务端自己挂载自己看看是否成功。

  1. [root@nfs-server ~]# mount -t nfs 192.168.31.129:/data /mnt

  2. [root@nfs-server ~]# df -h

  3. Filesystem Size Used Avail Use% Mounted on

  4. /dev/sda3 7.1G 1.4G 5.4G 21% /

  5. tmpfs 497M 0 497M 0% /dev/shm

  6. /dev/sda1 190M 27M 153M 15% /boot

  7. 192.168.31.129:/data 7.1G 1.4G 5.4G 21% /mnt

这一步主要是检查服务端的NFS服务是不是正常的。

2、确认NFS客户端showmount是否正常。

  1. [root@web-lamp01 ~]# showmount -e 192.168.31.129

  2. Export list for 192.168.31.129:

  3. /data 192.168.31.*

如果有问题进行下面排查。

1)ping NFS服务端IP检查

  1. [root@web-lamp01 ~]# ping 192.168.31.129

  2. PING 192.168.31.129 (192.168.31.129) 56(84) bytes of data.

  3. 64 bytes from 192.168.31.129: icmp_seq=1 ttl=64 time=1.40 ms

  4. 64 bytes from 192.168.31.129: icmp_seq=2 ttl=64 time=0.392 ms

2)telnet NFS服务端IP端口检查

  1. [root@web-lamp01 ~]# telnet 192.168.31.129 111

  2. Trying 192.168.31.129...

  3. Connected to 192.168.31.129.

  4. Escape character is '^]'.

如果出现No route to host很有可能是服务端防火墙引起。

此外,还需要注意服务端RPC服务启动顺序问题。

/etc/init.d/rpcbind start

rpcinfo -p localhost

/etc/init.d/nfs start

rpcinfo -p localhost

NFS配置参数权限

image

image

  1. [root@nfs-server ~]# cat /etc/exports

  2. /data 192.168.31.0/24(rw,sync,all_squash)

  3. [root@nfs-server ~]# exportfs -rv

  4. exporting 192.168.31.0/24:/data

NFS服务总结

使得NFS Client端可写的服务端配置条件

当多个NFS客户端以NFS方式写入修改服务器端的文件系统时,需要具有以下权限:

1、NFS服务器/etc/exports设置需要开放可写入的权限,即服务端的共享权限。

2、NFS服务器实际要共享的NFS目录权限具有可写入w的权限,即服务端本地目录的安全权限。

3、每台机器都对应存在和nfs默认配置UID的相同UID65534的nfsnobody用户(确保所有客户端的访问权限统一,否则每个机器需要同时建立相同UID的用户,并覆盖NFS的默认配置)。

当满足三个条件,多个NFS客户端才能具有互相写入,互相修改其他主机写入文件的权限。

NFS服务重要文件说明

/etc/exports

NFS服务主配置文件,配置NFS具体共享服务的地点,默认内容为空,以行为单位。

  1. [root@nfs-server ~]# cat /etc/exports

  2. /data 192.168.31.0/24(rw,sync,all_squash)

/usr/sbin/exportfs

NFS服务的管理命令。例如,可以加载NFS配置生效,还可以直接配置NFS共享目录,即无需配置/etc/exports实现共享。

  1. [root@nfs-server ~]# exportfs –rv #加载配置生效,等价于重启/etc/init.d/nfs reload

  2. exporting 192.168.31.0/24:/data

exportfs不但可以加载配置生效,也可以通过命令直接共享目录。越过/etc/exports,但重启失效。

/usr/sbin/showmount

常用在客户端,查看NFS配置及挂载结果的命令。配置nfsserver,分别在服务端以及客户端查看挂载情况。

/var/lib/nfs/etab

NFS配置文件的完整参数设定的文件(有很多没有配置但是默认就有的NFS参数)。

  1. [root@nfs-server ~]# cat /var/lib/nfs/etab

  2. /data 192.168.31.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,all_squash)

/proc/mounts

客户端挂载参数

  1. [root@web-lamp01 ~]# cat /proc/mounts

  2. rootfs / rootfs rw 0 0

  3. proc /proc proc rw,relatime 0 0

  4. sysfs /sys sysfs rw,relatime 0 0

  5. devtmpfs /dev devtmpfs rw,relatime,size=496952k,nr_inodes=124238,mode=755 0 0

  6. devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0

  7. tmpfs /dev/shm tmpfs rw,relatime 0 0

  8. /dev/sda3 / ext4 rw,relatime,barrier=1,data=ordered 0 0

  9. /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0

  10. /dev/sda1 /boot ext4 rw,relatime,barrier=1,data=ordered 0 0

  11. none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0

  12. sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0

  13. 192.168.31.129:/data/ /mnt nfs4 rw,relatime,vers=4,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.31.130,minorversion=0,local_lock=none,addr=192.168.31.129 0 0

NFS客户端mount挂载命令   

image

执行挂载的过程

  1. [root@web-lamp01 ~]# showmount -e 192.168.31.129 #挂载前先检查有权限需要挂载的信息是否能够挂载

  2. Export list for 192.168.31.129:

  3. /data 192.168.31.0/24 #可以清晰的看到共享了/data目录

  4. [root@web-lamp01 ~]# mount -t nfs 192.168.31.129:/data /mnt #执行挂载命令

  5. [root@web-lamp01 ~]# df –h #查看挂载后的结果

  6. Filesystem Size Used Avail Use% Mounted on

  7. /dev/sda3 7.1G 1.4G 5.4G 21% /

  8. tmpfs 497M 0 497M 0% /dev/shm

  9. /dev/sda1 190M 27M 153M 16% /boot

  10. 192.168.31.129:/data 7.1G 1.4G 5.4G 21% /mnt

  11. [root@web-lamp01 ~]# mount #查看挂载后的结果

  12. /dev/sda3 on / type ext4 (rw)

  13. proc on /proc type proc (rw)

  14. sysfs on /sys type sysfs (rw)

  15. devpts on /dev/pts type devpts (rw,gid=5,mode=620)

  16. tmpfs on /dev/shm type tmpfs (rw)

  17. /dev/sda1 on /boot type ext4 (rw)

  18. none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

  19. sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

  20. 192.168.31.129:/data on /mnt type nfs (rw,vers=4,addr=192.168.31.129,clientaddr=192.168.31.130)

  21. [root@web-lamp01 ~]# grep mnt /proc/mounts #查看挂载后的结果

  22. 192.168.31.129:/data/ /mnt nfs4 rw,relatime,vers=4,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.31.130,minorversion=0,local_lock=none,addr=192.168.31.129 0 0

NFS客户端mount挂载深入

NFS客户端mount挂载参数说明

在NFS服务端可以通过cat /var/lib/nfs/etab查看NFS服务端配置的参数细节。

在NFS客户端可以通过cat /proc/mounts查看mount的挂载参数细节。

NFS Client mount挂载参数列表

image

man nfs查看上述信息。

优化:

  1. [root@web-lamp01 ~]# mount -t nfs -o bg,hard,intr,rsize=131072,wsize=131072 192.168.31.129:/data /mnt

下面是mount -o参数对应的选项列表

image

NFS客户端mount挂载优化

在企业工作场景,一般来说,NFS服务器共享的只是普通静态数据(图片、附件、视频),不需要执行suid、exec等权限,挂载的这类文件系统只能作为数据存取之用,无法执行程序,对于客户端来讲增加了安全性。例如,很多木马篡改站点文件都是由上传入口上传的程序到存储目录,然后执行的。

因此在挂载的时候用下面的命令很有必要。

mount安全挂载参数

mount -t nfs -o nosuid,noexec,nodev,rw 192.168.31.129:/data /mnt

通过mount -o指定挂载参数和在/etc/fstab里指定挂载参数效果是一样的。

mount挂载性能优化参数选项

1、禁止更新目录及文件时间戳挂载

mount -t nfs -o noatime,nodiratime 192.168.31.129:/data /mnt

2、安全加优化的挂载方式

mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 192.168.31.129:/data /mnt

3、默认的挂载方式(推荐)

mount -t nfs 192.168.31.129:/data /mnt

如果是本地文件系统

mount /dev/sdb1 /mnt -o defaults,async,noatime,data=writeback,barrier=0

NFS服务内核优化

优化选项说明:

1、/proc/sys/net/core/rmem_default

该文件指定了接收套接字缓冲区大小的缺失值(以字节为单位),缺省设置:124928。

2、/proc/sys/net/core/rmem_max

该文件指定了接收套接字缓冲区大小的最大值(以字节为单位),缺省设置:124928。

3、/proc/sys/net/core/wmem_default

该文件指定了发送套接字缓冲区大小的缺失值(以字节为单位),缺省设置:124928。

4、/proc/sys/net/core/wmem_max

该文件指定了发送套接字缓冲区大小的最大值(以字节为单位),缺省设置:124928。

上述文件对应的具体内核优化命令:

  1. cat >>/etc/sysctl.conf<<EOF

  2. net.core.wmem_default=8388608

  3. net.core.wmem_max=16777216

  4. net.core.rmem_datault=8388608

  5. net.core.rmem_max=16777216

  6. EOF

  7. sysctl -p

企业场景NFS共享存储优化小结

1、硬件:sas、ssd硬盘,买多块,raid0、raid10。网卡吞吐量要大,至少千兆

2、NFS服务器端配置:/data

192.168.31.0/24(rw,sync,all_squash,anonuid=65534,anongid=65534)

3、NFS客户端挂载:rsize、wsize、noatime、nodirtime、nosuid、noexec、soft(hard、intr)

mount -t nfs -o nosuid,noexec,nodev,noatime,rsize=131072,wsize=131072 192.168.31.129:/data /mnt

mount -t nfs -o noatime,nodiratime,rsize=131072,wsize=131072 192.168.31.129:/data /mnt

mount -t nfs -o noatime,nodiratime 192.168.31.129:/data /mnt

4、有关NFS服务的所有服务器内核优化

  1. cat >>/etc/sysctl.conf<<EOF

  2. net.core.wmem_default=8388608

  3. net.core.wmem_max=16777216

  4. net.core.rmem_datault=8388608

  5. net.core.rmem_max=16777216

  6. EOF

  7. sysctl -p

5、如果卸载的时候提示:umount:/mnt:device is busy,需要退出挂载目录后进行卸载,或是NFS Server宕机了,需要强制卸载mount -lf /mnt。

6、大型网站NFS网络文件系统替代软件,分布式文件系统Moosefs(mfs)、glusterfs、FastDFS。

NFS系统应用优缺点说明

作用:

NFS服务可以让不同的客户端挂载使用同一目录,作为共享存储使用,这样可以保证不同节点客户端数据的一致性,在集群架构环境中经常会用到。如果windows+linux可以用samba。

优点:

1、简单,容易上手,容易掌握。

2、NFS文件系统内数据是在文件系统之上的,即数据能看见。

3、方便,部署快速,维护简单,可控且满足需求。

4、可靠,从软件层面上看,数据可靠性高,经久耐用。数据是在文件系统之上的

5、稳定。

局限:

1、局限性是存在单点故障,如果nfs server宕机了所有客户端都不能访问共享目录

可以通过负载均衡及高可用方案弥补。

2、在大数据高并发的场合,NFS效率、性能有限(一般几千万pv的网站不是瓶颈,除非网站架构太差,2千万pv/日)。

3、客户端认证是基于ip和主机名的,权限是根据ID识别,安全性一般(用于内外则问题不大)。

4、NFS数据是明文的,NFS本身对数据完整性不作验证。

5、多台客户机器挂载一个NFS服务器时,连接管理维护麻烦(耦合度高)。尤其NFS服务出现问题后,所有NFS客户端都挂掉状态(测试环境可以使用autofs自动挂载解决)。

6、大中小型网站(2千万PV以下)线上应用,都有用武之地。

showmount命令说明

image