NFS即网络文件服务器,可以挂载管理远程主机上的文件如本地一般,特殊场合应用很方便。
CentOS下安装:
1 | yum -y install nfs-utils |
ubuntu安装:
1 | apt install nfs-kernel-server |
配置共享目录:
1 2 3 4 5 6 7 | vim /etc/exports /tmp 192.168.1.0 /24 (rw, sync ,fsid=0,no_root_squash,no_subtree_check) #定义目录tmp,主机192.168.1.0/24可连接,有读写权限。 #fsid=0,此目录为虚拟根目录,挂载时路径填写/即可。 #默认root连接会压缩成匿名用户,如需保持root权限请添加no_root_squash参数。 #no_subtree_check,不检查父目录权限 #如/tmp 192.168.1.0/24(rw,no_root_squash) |
启动NFS,NFS4不需要rpcbind。
1 2 3 4 | systemctl enable rpcbind systemctl start rpcbind systemctl enable nfs-server systemctl start nfs-server |
查看当前共享参数:
1 2 3 | showmount -e localhost Export list for localhost: /tmp 192.168.1.0 /24 * |
或者:
1 | exportfs |
修改exports配置文件后重新生效:
1 | exportfs -a |
远端主机挂载共享目录:
1 2 3 | mount -t nfs 192.168.1.1: /tmp /mnt #默认当nfs服务器不在线时客户端会一直尝试连接,可设置重试次数。 #-o soft,retry=30 |
查看nfs状态:
1 2 3 4 | #服务器端 nfsstat -s #客户端 nfsstat -m |
开启nfs调试日志,保存在/var/log/message,ubuntu在/var/log/syslog
1 2 3 4 | #服务器端 rpcdebug -m nfsd -s all #客户端 rpcdebug -m nfs -s all |
关闭:
1 2 | rpcdebug -m nfs -s all rpcdebug -m nfsd -s all |
NFS服务器Iptables防火墙配置:https://www.haiyun.me/archives/centos-nfs-port.html
标签:centos, linux, nfs, centos开启nfs共享