https://www.cnblogs.com/merely/p/10793877.html
https://help.aliyun.com/document_detail/90529.html
https://support.huaweicloud.com/intl/zh-cn/qs-sfs/zh-cn_topic_0034428728.html
https://blog.csdn.net/kevinhg/article/details/5967432
#######################################################################################################################################
1. 安装:
apt-get install -y nfs-kernel-server
2. 创建共享目录,并添加配置:
mkdir -p /nfs/share
在/etc/exports的末尾追加一行:/nfs/share *(rw,sync,no_subtree_check,no_root_squash)
3. nfs是一个RPC程序,第1步安装成功后,使用它时需要映射提前映射好端口,映射端口,通过rpcbind设定
systemctl status rpcbind
4. 重启nfs-server:
systemctl restart nfs-server && systemctl enable nfs-server
systemctl status nfs-server
5. 挂载上面的共享
在/etc/fstab添加
192.168.22.22:/nfs/share /nfsfile nfs rw,tcp,soft 0 0
如挂载到本机,添加共享文件:
echo 1111 > /nfs/share/1.txt
echo 2222 > /nfs/share/2.txt
挂载mount -a
ll /nfsfile
total 16
-rw-r--r-- 1 root root 5 Sep 15 08:49 1.txt
-rw-r--r-- 1 root root 5 Sep 15 08:49 2.txt
查看挂载状态
nfsstat -m
/nfsfile from 192.168.151.4:/nfs/share
Flags: rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,soft,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.151.4,local_lock=none,addr=192.168.151.4
取消挂载 umount /nfsfile
注:redhat系linux中,低版本启动nfs方式为
/etc/rc.d/init.d/portmap start (在REDHAT中PORTMAP是默认启动的)
/etc/rc.d/init.d/nfs start
#######################################################################################################################################
https://blog.51cto.com/foolishfish/1372770 nfs服务器的配置以及fstab参数描述
nfs服务器的配置,配置文件/etc/exports:
例子:
表示共享服务器上的根目录(/)只有zhang和wang两台主机可以访问,且有读写权限;
zhang主机用root用户身份访问时,将客户机的root用户映射成服务器上的匿名用户(root_squash,该参数为缺省参数),相当于在服务器使用nobody用户访问目录;
wang主机用root用户身份访问该共享目录时,不映射root用户(no_root_squash),即相当于在服务器上用root身份访问该目录;
/root/share/ 192.168.1.20 (rw,insecure,sync,all_squash) # 可以指定模糊匹配,如 192.168.0.*(rw) *(ro)
表示共享服务器上的/root/share/目录只有192.168.1.20主机可以访问,且有读写权限;
此主机用任何身份访问时,将客户机的用户都映射成服务器上的匿名用户(all_squash),相当于在服务器上用nobody用户访问该目录(若客户机要在该共享目录上保存文件(即写操作),则服务器上的nobody用户对该目录必须有写的权限)
表示共享/home/ljm/目录,*.gdfs.edu.cn域中所有的主机都可以访问该目录,且有读写权限
表示共享目录/home/share/,*.gdfs.edu.cn域中的所有主机都可以访问,但只有只读的权限,所有用户都映射成服务器上的uid为student、gid为math的用户
启动nfs后又修改了/etc/exports,不用重启该服务,使用exports命令即可:
例:
[root@localhost ~]# /usr/sbin/exportfs -rv # 全部重新export一次
nfs客户端的配置:
若是临时使用可直接执行mount命令:mount servername(or IP):共享目录 本地挂载目录
若客户机启动就自动挂载服务器的共享目录,则需修改客户机上的/etc/fstab文件
[root@localhost ~]#vi /etc/hosts.allow
Portmap:192.168.5.123:allow
[root@localhost ~]#vi /etc/hosts.deny
Portmap:ALL:deny
安全提醒:确保网络安全,使用nfs时结合tcp_wrappers来限制使用范围(如只想192.168.5.123主机可挂载nfs服务器上的共享目录),另外还可结合iptables来加强
关机时若nfs server上有client联机时,先关掉portmap与nfs两个系统服务。若无法正确将此2项服务关掉,用netstat –utlp找出PID,然后用kill杀掉进程才关机
nfsstat 查看NFS的运行状态,调整NFS运行大有帮助
rpcinfo 查看rpc执行信息,用于检测rpc运行情况
挂载nfs目录格式(语法):
卸载:
showmout命令对于NFS的操作和查错有很大的帮助,参数:
-a :这个参数是一般在NFS SERVER上使用,是用来显示已经mount上本机nfs目录的client机器。
-e :显示指定的NFS SERVER上export出来的目录。
showmount -a IP(用于nfs server上,显示已经mount上本机NFS服务器的client(客户机))
#######################################################################################################################################
以下转载:在路上 » 【整理】Linux中fstab的语法和参数含义和mount NFS时相关参数含义
【背景】
【已解决】在远程Ubuntu服务器中开通NFS服务供别人访问服务器上的文件
期间,对于参考文档,写了下面的配置:
需要搞懂fstab的格式,语法。
【折腾过程】
fstab 语法
man fstab
man fstab bg
man fstab nolock
参考:
linux fstab 语法 – rajaruan – 51CTO技术博客
nfs(5) – nfs, nfs – nfs fstab format and options – man 5 nfs
NFS Client Configuration Files
fstab的格式:
|
file_system |
Is the remote server directory to be mounted. |
|
directory |
Is the mount point on the client where the directory is attached. |
|
type |
Is the file system type. This can be nfs2 for NFS2 mounting, nfs3 for the NFS3 protocol, and nfs and nfs3pref for mounts that attempt the NFS3 protocol, but fall back to nfs2 if the attempt fails. |
|
options |
Is mount options (see Section 4.6.2.1 in this section). |
|
frequency |
Is always set to zero (0) for NFS and CacheFS entries. |
|
pass |
Is always set to zero (0) for NFS and CacheFS entries. |
其中那些参数的含义是:
|
defaults use default options: rw, suid, dev, exec, auto, nouser, and async.
acregmin=n The minimum time (in seconds) that the NFS client caches attributes of a regular file before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 3-second minimum. acregmax=n The maximum time (in seconds) that the NFS client caches attributes of a regular file before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 60-second maximum. acdirmin=n The minimum time (in seconds) that the NFS client caches attributes of a directory before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 30-second minimum. acdirmax=n The maximum time (in seconds) that the NFS client caches attributes of a directory before it requests fresh attribute information from a server. If this option is not specified, the NFS client uses a 60-second maximum. actimeo=n Using actimeo sets all of acregmin, acregmax, acdirmin, and acdirmax to the same value. If this option is not specified, the NFS client uses the defaults for each of these options listed above.
在Unix中,每个文件都有记录上次访问文件时间(atime的),修改时间(mtime),和changed time(ctime)。atime是指每个文件被读取的时间,这个功能经常受到批评,因为这样会造成性能下降,并增加磨损。然而,一些应用程序和用户会使用到atime,因此需要指定选项,atime?noatime?(in Linux) relatime (update atime if older than mtime)?Linux内核版本是2.6.29,默认是atime;2.6.30则默认是relatime。 bg (background) Mounting is performed as a background task if the first attempt fails. The default setting is off. nfsvers=n Use an alternate RPC version number to contact the NFS daemon on the remote host. This option is useful for hosts that can run multiple NFS servers. The default value is version 2. intr If an NFS file operation has a major timeout and it is hard mounted, then allow signals to interupt the file operation and cause it to return EINTR to the calling program. The default is to not allow file operations to be interrupted. tcp Mount the NFS filesystem using the TCP protocol instead of the default UDP protocol. Many NFS servers only support UDP. actimeo=n Using actimeo sets all of acregmin, acregmax, acdirmin, and acdirmax to the same value. There is no default value.
|
【总结】
上述的fstab中的配置:
的含义是:
- 121.41.120.185:/home/share/image
- 是目标NFS服务器的IP(或域名)和NFS共享的路径
- /root/nfs_client_root/
- 是NFS客户端要mount挂载的路径(自定义挂载点,一般挂载到/mnt下面某个路径,比如光驱常挂载到/mnt/cdrom。这里仅为测试方便)
- nfs
- 表示挂载的文件系统类型时NFS
- 各个参数的含义:
- auto:自动挂载;
- noatime:不要添加access time==上次访问文件时间;
- nolock:禁止文件加锁。有时候访问旧的NFS服务器需要此参数。
- bg:挂载作为后台服务去运行,如果第一次挂载失败了。默认是off的。
- nfsvers=4:指定NFS协议的版本。
- intr:允许NFS请求被中断,如果服务器挂了或连不上
- tcp:指定NFS(不适用默认的UDP而改用)TCP
- actimeo=1800:acregmin==acregmax==acdirmin====acdirmax,都设置为1800s=30分钟,即文件缓存时间为30分钟
- 0
- 不需要NFS的CacheFS?
浙公网安备 33010602011771号